Creates pre-downsampling rules that control how LindormTSDB aggregates time series data at a reduced resolution for storage and query efficiency.
Applicable engines and versions
Applies to LindormTSDB only. All versions are supported.
Syntax
create_predownsample_statement ::= CREATE PREDOWNSAMPLE time_interval
AGGREGATORS ('function_identifier' [, 'function_identifier'] ...)
[ TTL time_interval ] ON table_identifier
time_interval ::= interval unitsParameters
| Parameter | Description |
|---|---|
interval | The interval at which time series data is aggregated. Must be a positive integer. |
units | The unit of the interval. Valid values: s (seconds), m (minutes), h (hours), d (days). |
AGGREGATORS | The aggregation functions to apply during pre-downsampling. Valid values: count, first, last, min, max, sum. |
function_identifier | The name of the aggregation function. A single statement can specify multiple functions with the same interval. Alternatively, define functions with the same interval across multiple statements. |
TTL | The time to live (TTL) of the pre-downsampled data. |
table_identifier | The name of the table for which pre-downsampling rules are configured. |
Theavgfunction is not supported. To calculate an average over pre-downsampled data, divide thesumresult by thecountresult. If data is repeatedly added and overwritten, the computed average may be inaccurate.
If multiple pre-downsampling rules specify different TTL values, the largest TTL applies to all rules.
Query pre-downsampled data
By default, querying a table returns the original data, not the pre-downsampled data. To query only pre-downsampled data, add the /*+ PREDOWNSAMPLE */ hint to your query statement.
For more information, see Pre-downsampling.
Examples
Example 1: Create a pre-downsampling rule with a 90-day TTL
The following statement aggregates data in the sensor table hourly using sum and max, and retains the pre-downsampled data for 90 days.
CREATE PREDOWNSAMPLE `1h` AGGREGATORS (`sum`, `max`) TTL `90d` ON sensor;Example 2: Query pre-downsampled data
The following statement queries hourly pre-downsampled data from the sensor table within a specified time range.
SELECT /*+ PREDOWNSAMPLE */ SUM(temperature) FROM sensor
WHERE time >= 1619076780000 AND time <= 1619076800000
SAMPLE BY 1h;