Enable range statistics for a specific column in a compressed hypertable. This tracks a range of values for that column per chunk. Used for chunk pruning during query optimization.

Best practice is to enable range tracking on columns that are correlated to the partitioning column. In other words, enable tracking on secondary columns which are referenced in the WHERE clauses in your queries.

TimescaleDB supports min/max range tracking for the smallint, int, bigint, serial, bigserial, date, timestamp, and timestamptz data types. The min/max ranges are calculated when a chunk belonging to this hypertable is compressed using the compress_chunk function. The range is stored in start (inclusive) and end (exclusive) form in the chunk_column_stats catalog table.

This way you store the min/max values for such columns in this catalog table at the per-chunk level. These min/max range values do not participate in partitioning of the data. These ranges are used for chunk pruning when the WHERE clause of an SQL query specifies ranges on the column.

A DROP COLUMN on a column with statistics tracking enabled on it ends up removing all relevant entries from the catalog table.

A decompress_chunk invocation on a compressed chunk resets its entries from the chunk_column_stats catalog table since now it's available for DML and the min/max range values can change on any further data manipulation in the chunk.

By default, this feature is disabled. To enable chunk skipping, set timescale.enable_chunk_skipping = on in postgresql.conf. When you upgrade from a database instance that uses compression but does not support chunk skipping, you need to recompress the previously compressed chunks for chunk skipping to work.

In this sample, you convert the conditions table to a hypertable with partitioning on the time column. You then specify and enable additional columns to track ranges for.

SELECT create_hypertable('conditions', 'time');
SELECT enable_chunk_skipping('conditions', 'device_id');
NameTypeDefaultRequiredDescription
column_nameTEXT-Column to track range statistics for
hypertableREGCLASS-Hypertable that the column belongs to
if_not_existsBOOLEANfalseSet to true so that a notice is sent when ranges are not being tracked for a column. By default, an error is thrown
ColumnTypeDescription
column_stats_idINTEGERID of the entry in the TimescaleDB internal catalog
enabledBOOLEANReturns true when tracking is enabled, if_not_exists is true, and when a new entry is not
added

Keywords

Found an issue on this page?Report an issue or Edit this page in GitHub.