Skip to content

Partitioning, Indexing & Optimization

Master hypertable performance tuning

Tiger Data 101 → TimescaleDB | Section: Hypertables | ⏱ Time: ~3 min

TimescaleDB automatically partitions by time. This is the core optimization: queries with time filters skip irrelevant chunks entirely.

For high-cardinality data (thousands of unique devices, sensors, or users), add a second dimension:

SELECT create_hypertable(
'sensor_readings',
by_range('time', INTERVAL '1 day'),
by_hash('device_id', 4) -- 4 sub-partitions per time chunk
);

This creates a 2D grid: time chunks are further split by device ID, keeping each sub-chunk smaller and more queryable.


Effective indexes dramatically speed up queries. Best practices:

  1. Time + tag index (most common):

    CREATE INDEX ON sensor_readings (device_id, time DESC);
  2. Measure column (for range queries on values):

    CREATE INDEX ON sensor_readings (temperature) WHERE temperature > 30;

  • Chunk exclusion: Queries automatically skip chunks outside the filter range
  • Compression: Older chunks can be compressed to 10–40x smaller
  • Retention policies: Automatically drop chunks older than your retention window
  • Continuous Aggregates: Pre-compute expensive aggregations

Knowledge Check

Question 1 of 3

A. When you query a hypertable with a time filter (e.g., `WHERE time > NOW() - INTERVAL '7 days'`), what optimization does TimescaleDB apply automatically?