EXPLAIN SELECT DISTINCT ON (ts) ts, ts - lag(ts) OVER (ORDER BY ts) AS interval FROM metrics_30m WHERE ts >= '2024-04-08 14:00:00+00'::timestamptz ORDER BY ts ASC; Unique (cost=28383357.04..74804673.43 rows=6 width=24) -> WindowAgg (cost=28383357.04..73530789.10 rows=509553731 width=24) -> Subquery Scan on metrics_30m (cost=28383357.04..64613598.81 rows=509553731 width=8) -> Result (cost=28383357.04..59518061.50 rows=509553731 width=63) -> Custom Scan (ChunkAppend) on _materialized_hypertable_5 (cost=28383357.04..54422524.19 rows=509553731 width=55) Order: _materialized_hypertable_5.ts, _materialized_hypertable_5.dev_id, _materialized_hypertable_5.loc_id, _materialized_hypertable_5.ctxt_id, _materialized_hypertable_5.ev_class, _materialized_hypertable_5.num DESC, _materialized_hypertable_5.size DESC, _materialized_hypertable_5.success DESC, _materialized_hypertable_5.random DESC -> Sort (cost=28383357.04..28834699.54 rows=180537000 width=55) Sort Key: _hyper_5_60_chunk.ts, _hyper_5_60_chunk.dev_id, _hyper_5_60_chunk.loc_id, _hyper_5_60_chunk.ctxt_id, _hyper_5_60_chunk.ev_class, _hyper_5_60_chunk.num DESC, _hyper_5_60_chunk.size DESC, _hyper_5_60_chunk.success DESC, _hyper_5_60_chunk.random DESC -> Custom Scan (DecompressChunk) on _hyper_5_60_chunk (cost=0.06..10499.40 rows=180537000 width=55) Vectorized Filter: (ts >= '2024-04-08 14:00:00+00'::timestamp with time zone) -> Seq Scan on compress_hyper_6_77_chunk (cost=0.00..10499.40 rows=180537 width=325) Filter: (_ts_meta_max_1 >= '2024-04-08 14:00:00+00'::timestamp with time zone) -> Sort (cost=20348307.50..20676685.00 rows=131351000 width=55) Sort Key: _hyper_5_68_chunk.ts, _hyper_5_68_chunk.dev_id, _hyper_5_68_chunk.loc_id, _hyper_5_68_chunk.ctxt_id, _hyper_5_68_chunk.ev_class, _hyper_5_68_chunk.num DESC, _hyper_5_68_chunk.size DESC, _hyper_5_68_chunk.success DESC, _hyper_5_68_chunk.random DESC -> Custom Scan (DecompressChunk) on _hyper_5_68_chunk (cost=0.05..6792.89 rows=131351000 width=55) Vectorized Filter: (ts >= '2024-04-08 14:00:00+00'::timestamp with time zone) -> Seq Scan on compress_hyper_6_87_chunk (cost=0.00..6792.89 rows=131351 width=325) Filter: (_ts_meta_max_1 >= '2024-04-08 14:00:00+00'::timestamp with time zone) -> Sort (cost=0.00..0.00 rows=0 width=0) Sort Key: _hyper_5_79_chunk.ts, _hyper_5_79_chunk.dev_id, _hyper_5_79_chunk.loc_id, _hyper_5_79_chunk.ctxt_id, _hyper_5_79_chunk.ev_class, _hyper_5_79_chunk.num DESC, _hyper_5_79_chunk.size DESC, _hyper_5_79_chunk.success DESC, _hyper_5_79_chunk.random DESC -> Seq Scan on _hyper_5_79_chunk (cost=0.00..3481232.60 rows=140114207 width=55) Filter: (ts >= '2024-04-08 14:00:00+00'::timestamp with time zone) -> Sort (cost=0.00..0.00 rows=0 width=0) Sort Key: _hyper_5_89_chunk.ts, _hyper_5_89_chunk.dev_id, _hyper_5_89_chunk.loc_id, _hyper_5_89_chunk.ctxt_id, _hyper_5_89_chunk.ev_class, _hyper_5_89_chunk.num DESC, _hyper_5_89_chunk.size DESC, _hyper_5_89_chunk.success DESC, _hyper_5_89_chunk.random DESC -> Seq Scan on _hyper_5_89_chunk (cost=0.00..1429907.05 rows=57551524 width=55) Filter: (ts >= '2024-04-08 14:00:00+00'::timestamp with time zone) (26 rows)