Partitioning, Indexing & Optimization
Master hypertable performance tuning
Tiger Data 101 → TimescaleDB | Section: Hypertables | ⏱ Time: ~3 min
Partitioning strategies
Section titled “Partitioning strategies”Time-based partitioning (default)
Section titled “Time-based partitioning (default)”TimescaleDB automatically partitions by time. This is the core optimization: queries with time filters skip irrelevant chunks entirely.
Space-based partitioning (optional)
Section titled “Space-based partitioning (optional)”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.
Indexing hypertables
Section titled “Indexing hypertables”Effective indexes dramatically speed up queries. Best practices:
-
Time + tag index (most common):
CREATE INDEX ON sensor_readings (device_id, time DESC); -
Measure column (for range queries on values):
CREATE INDEX ON sensor_readings (temperature) WHERE temperature > 30;
Optimization techniques
Section titled “Optimization techniques”- 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
Section titled “Knowledge check”Knowledge Check
Question 1 of 3