Thank you for your suggestions, @jonatasdp.
select * from timescaledb_information.compressed_chunk_stats;
Returns 0 rows, so I guess the chunks are not compressed?
The time ranges are very long indeed. The test data covers several hundred of parameters with a resolution of 1 minute over two years. The query aggregates over 1 year. To be very performant, you probably would want to use some sort of pre aggregation, but I wanted to understand how flexible you are with your queries in TimescaleDB.
I tried the ANALYZE EXPLAIN, but to me the output looks very similar. The most obvious to me is that for the first query it states:
Workers Planned: 6
Workers Launched: 5
while it states for the following queries
Workers Planned: 6
Workers Launched: 0
Essentially the out looks like this, with a lot more Parallel Bitmap Heap Scans:
First query:
Finalize GroupAggregate (cost=574270.40..574315.59 rows=55 width=40) (actual time=526.233..556.650 rows=365 loops=1)
Group Key: (time_bucket('1 day'::interval, _hyper_1_87_chunk.generation_time))
-> Gather Merge (cost=574270.40..574310.64 rows=330 width=64) (actual time=526.221..556.478 rows=395 loops=1)
Workers Planned: 6
Workers Launched: 5
-> Sort (cost=573270.30..573270.43 rows=55 width=64) (actual time=504.171..504.203 rows=66 loops=6)
Sort Key: (time_bucket('1 day'::interval, _hyper_1_87_chunk.generation_time))
Sort Method: quicksort Memory: 34kB
Worker 0: Sort Method: quicksort Memory: 34kB
Worker 1: Sort Method: quicksort Memory: 34kB
Worker 2: Sort Method: quicksort Memory: 34kB
Worker 3: Sort Method: quicksort Memory: 34kB
Worker 4: Sort Method: quicksort Memory: 33kB
-> Partial HashAggregate (cost=573268.02..573268.71 rows=55 width=64) (actual time=504.090..504.138 rows=66 loops=6)
Group Key: time_bucket('1 day'::interval, _hyper_1_87_chunk.generation_time)
-> Result (cost=369.38..572160.71 rows=88585 width=16) (actual time=7.267..484.004 rows=87600 loops=6)
-> Parallel Append (cost=369.38..571053.39 rows=88585 width=16) (actual time=7.261..473.124 rows=87600 loops=6)
-> Parallel Bitmap Heap Scan on _hyper_1_87_chunk (cost=369.51..11050.84 rows=3323 width=16) (actual time=7.904..66.623 rows=10080 loops=1)
Recheck Cond: ((id = 'test1'::text) AND (generation_time >= '2022-01-01 00:00:00+00'::timestamp with time zone) AND (generation_time < '2023-01-01 00:00:00+00'::timestamp with time zone))
-> Bitmap Index Scan on "87_87_parameters_pkey" (cost=0.00..366.93 rows=10302 width=0) (actual time=6.483..6.483 rows=10080 loops=1)
Index Cond: ((id = 'test1'::text) AND (generation_time >= '2022-01-01 00:00:00+00'::timestamp with time zone) AND (generation_time < '2023-01-01 00:00:00+00'::timestamp with time zone))
Second Query:
Finalize GroupAggregate (cost=585315.80..585361.00 rows=55 width=40) (actual time=2649.451..2657.856 rows=365 loops=1)
Group Key: (time_bucket('1 day'::interval, _hyper_1_82_chunk.generation_time))
-> Gather Merge (cost=585315.80..585356.05 rows=330 width=64) (actual time=2649.433..2657.709 rows=365 loops=1)
Workers Planned: 6
Workers Launched: 0
-> Sort (cost=584315.70..584315.84 rows=55 width=64) (actual time=2643.755..2643.827 rows=365 loops=1)
Sort Key: (time_bucket('1 day'::interval, _hyper_1_82_chunk.generation_time))
Sort Method: quicksort Memory: 76kB
-> Partial HashAggregate (cost=584313.43..584314.11 rows=55 width=64) (actual time=2643.519..2643.688 rows=365 loops=1)
Group Key: time_bucket('1 day'::interval, _hyper_1_82_chunk.generation_time)
-> Result (cost=369.42..583183.34 rows=90407 width=16) (actual time=3.884..2526.014 rows=525602 loops=1)
-> Parallel Append (cost=369.42..582053.25 rows=90407 width=16) (actual time=3.878..2462.689 rows=525602 loops=1)
-> Parallel Bitmap Heap Scan on _hyper_1_82_chunk (cost=506.02..14868.58 rows=4551 width=16) (actual time=6.262..50.874 rows=10080 loops=1)
Recheck Cond: ((id = 'test5'::text) AND (generation_time >= '2022-01-01 00:00:00+00'::timestamp with time zone) AND (generation_time < '2023-01-01 00:00:00+00'::timestamp with time zone))
Heap Blocks: exact=10080
-> Bitmap Index Scan on "82_82_parameters_pkey" (cost=0.00..502.50 rows=14107 width=0) (actual time=4.495..4.495 rows=10080 loops=1)
Index Cond: ((id = 'test5'::text) AND (generation_time >= '2022-01-01 00:00:00+00'::timestamp with time zone) AND (generation_time < '2023-01-01 00:00:00+00'::timestamp with time zone))
Other things I noticed is, that the first gather merge has 395 rows while the second has 365 (as it should be I guess). And the second query state ‘Heap Blocks: exact=’ after each Parallel Bitmap, which the first does not do.
Can you spot something? Could this be storage related?
Cheers