Reduce scanned data points to improve query efficiency
Query speed in TSDB scales directly with the number of data points scanned: the fewer points a query must read, the faster it returns results. Because queries cannot be cancelled once started, the only way to control query duration is to reduce the scan count before submitting the query.
The strategies below target two independent stages — data collection and query construction — so you can act at whichever stage applies to your situation.
Reduce points at collection time
Use a coarser collection interval
The collection interval determines how many data points are stored per unit of time. Millisecond-precision collection generates far more points than second- or minute-level collection for the same time window.
Choose the coarsest interval that still satisfies your monitoring or analysis requirements. For most use cases, second- or minute-level intervals provide sufficient resolution while keeping query scan counts manageable.
Reduce points at query time
Align the time range to the top of the hour
Align both the start time and the end time to the top of the hour to avoid additional data queries.
Use exact tag filter conditions
Use precise tag filter conditions to narrow the matched series. Broad or missing tag filters cause the database to scan more series in the time range, increasing the total scan count.
Select a time range appropriate to the data volume
Aggregation response time depends on the total volume of data being aggregated. A wider time range or a finer collection interval both increase the amount of data the aggregation must process.
Size the time range to match what you actually need.
Constraints
Queries cannot be cancelled. Once a query starts, it runs to completion. If a query is taking too long, the only option is to wait for it to finish. To avoid this situation:
Set a time range no larger than your actual data needs.
Use exact tag filter conditions to narrow matched series.
Prefer coarser collection intervals to limit the data volume from the start.