forked from timescale/timescaledb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolumnar_index_scan-17.out
More file actions
3573 lines (3315 loc) · 161 KB
/
Copy pathcolumnar_index_scan-17.out
File metadata and controls
3573 lines (3315 loc) · 161 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
SET max_parallel_workers_per_gather = 0;
-- disable vectorized aggregation to prevent plan switches when running on 32-bit
SET timescaledb.enable_vectorized_aggregation = off;
\set TEST_BASE_NAME columnar_index_scan
SELECT format('include/%s_query.sql', :'TEST_BASE_NAME') as "TEST_QUERY_NAME",
format('%s/results/%s_results_optimized.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_OPTIMIZED",
format('%s/results/%s_results_unoptimized.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNOPTIMIZED"
\gset
SELECT format('\! diff -u --label "Unoptimized results" --label "Optimized results" %s %s', :'TEST_RESULTS_UNOPTIMIZED', :'TEST_RESULTS_OPTIMIZED') as "DIFF_CMD"
\gset
CREATE TABLE metrics(
time timestamptz NOT NULL,
device text,
sensor text,
value float,
value2 float
) WITH (tsdb.hypertable,tsdb.orderby='time desc',tsdb.segmentby='device,sensor',tsdb.index='minmax(value)');
NOTICE: using column "time" as partitioning column
INSERT INTO metrics VALUES
('2025-01-01 00:00:00 PST', 'd1', 'A', 10.0, 10.1),
('2025-01-01 01:00:00 PST', 'd1', 'A', 20.0, 20.1),
('2025-01-01 02:00:00 PST', 'd1', 'A', 15.0, 15.1),
('2025-01-01 00:30:00 PST', 'd1', 'B', 4.0, 4.1),
('2025-01-01 01:30:00 PST', 'd1', 'B', 25.0, 25.1),
('2025-01-01 02:30:00 PST', 'd1', 'B', 29.0, 29.1),
('2025-01-01 00:00:00 PST', 'd2', 'A', 10.0, 10.1),
('2025-01-01 01:00:00 PST', 'd2', 'A', 20.0, 20.1),
('2025-01-01 02:00:00 PST', 'd2', 'A', 15.0, 15.1),
('2025-01-01 00:30:00 PST', 'd2', 'C', 6.0, 6.1),
('2025-01-01 01:30:00 PST', 'd2', 'C', 25.0, 25.1),
('2025-01-01 02:30:00 PST', 'd2', 'C', 31.0, 31.1);
-- Compress all chunks
SELECT compress_chunk(c) FROM show_chunks('metrics') c;
compress_chunk
----------------------------------------
_timescaledb_internal._hyper_1_1_chunk
-- first run with hypertable with 1 fully compressed chunk
-- get query plans
\set PREFIX 'EXPLAIN (costs off)'
\set ECHO all
SET timescaledb.enable_columnarindexscan = on;
\ir :TEST_QUERY_NAME
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
-- canary for test diff
SHOW timescaledb.enable_columnarindexscan;
timescaledb.enable_columnarindexscan
--------------------------------------
on
-- simple query with count without grouping
:PREFIX SELECT device, count(*) FROM metrics GROUP BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- simple query with count with grouping
:PREFIX SELECT device, count(*) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- simple query with multiple count with grouping
:PREFIX SELECT device, count(*), count(*) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- simple query with 1 max aggregate that can use optimization
:PREFIX SELECT device, max(time) FROM metrics GROUP BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- simple query with 1 min aggregate that can use optimization
:PREFIX SELECT sensor, min(time) FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---
GroupAggregate
Group Key: sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Sort
Sort Key: compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
-- simple query with 1 first aggregate that can use optimization
:PREFIX SELECT device, first(time, time) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- simple query with 1 last aggregate that can use optimization
:PREFIX SELECT device, last(time, time) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- explicit index columns dont prevent optimization
:PREFIX SELECT sensor, min(value) FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---
GroupAggregate
Group Key: sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Sort
Sort Key: compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
:PREFIX SELECT sensor, min(value), max(value) FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---
GroupAggregate
Group Key: sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Sort
Sort Key: compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
-- multiple aggregates on same column
:PREFIX SELECT sensor, min(time), max(time), first(time,time), last(time,time) FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---
GroupAggregate
Group Key: sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Sort
Sort Key: compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
-- same aggregate on multiple columns
:PREFIX SELECT sensor, min(time), min(value) FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---
GroupAggregate
Group Key: sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Sort
Sort Key: compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
-- same aggregate on multiple columns but different order
:PREFIX SELECT sensor, min(value), min(time), sensor FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---
GroupAggregate
Group Key: sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Sort
Sort Key: compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
-- multiple aggregates on multiple columns
:PREFIX SELECT sensor, first(time,time), last(time,time), first(value, value), last(value, value) FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---
GroupAggregate
Group Key: sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Sort
Sort Key: compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
-- test multiple group by columns
:PREFIX SELECT device, sensor, max(time) FROM metrics GROUP BY device,sensor ORDER BY device,sensor;
--- QUERY PLAN ---
GroupAggregate
Group Key: device, sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- filter on segmentby allows optimization
:PREFIX SELECT device, min(time) FROM metrics WHERE device IN ('d1','d2') GROUP BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
Index Cond: (device = ANY ('{d1,d2}'::text[]))
:PREFIX SELECT device, min(time) FROM metrics WHERE device =ANY(ARRAY['d1','d2']) AND sensor='B' GROUP BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
Index Cond: ((device = ANY ('{d1,d2}'::text[])) AND (sensor = 'B'::text))
-- HAVING on segmentby (pushed down to lower scan)
:PREFIX SELECT device, min(time) FROM metrics GROUP BY device HAVING device IN ('d1','d2');
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
Index Cond: (device = ANY ('{d1,d2}'::text[]))
:PREFIX SELECT device, min(time) FROM metrics GROUP BY device,sensor HAVING device =ANY(ARRAY['d1','d2']) AND sensor='B';
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
Index Cond: ((device = ANY ('{d1,d2}'::text[])) AND (sensor = 'B'::text))
-- HAVING with aggregate function
:PREFIX SELECT device, min(value) FROM metrics GROUP BY device HAVING min(value) > 20;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
Filter: (min(value) > '20'::double precision)
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
:PREFIX SELECT device, max(value) FROM metrics GROUP BY device HAVING min(value) < 25;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
Filter: (min(value) < '25'::double precision)
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- HAVING
:PREFIX SELECT device, min(time) FROM metrics GROUP BY device HAVING min(time) > '2025-01-01 00:30:00 PST';
--- QUERY PLAN ---
GroupAggregate
Group Key: device
Filter: (min("time") > 'Wed Jan 01 00:30:00 2025 PST'::timestamp with time zone)
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- tableoid doesnt prevent optimization
:PREFIX SELECT tableoid, device, max(time) FROM metrics GROUP BY device, tableoid;
--- QUERY PLAN ---
HashAggregate
Group Key: device, tableoid
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Seq Scan on compress_hyper_2_2_chunk
:PREFIX SELECT device, max(time), min(tableoid) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- multiple aggregates on same column use optimization
:PREFIX SELECT device, min(time), max(time) FROM metrics GROUP BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- multiple aggregates on same column with first/last
:PREFIX SELECT device, min(time), first(time, time), last(time, time), max(time) FROM metrics GROUP BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- segmentby column at end of targetlist
:PREFIX SELECT first(time, time), last(time, time), device FROM metrics GROUP BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- multiple aggregates on different columns use optimization
:PREFIX SELECT device, min(time), max(value) FROM metrics GROUP BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- multiple aggregates on same non-time column use optimization
:PREFIX SELECT device, min(value), max(value) FROM metrics GROUP BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- multiple aggregates on multiple columns
:PREFIX SELECT device, min(time), max(time), min(value), max(value) FROM metrics GROUP BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- expression on aggregates
:PREFIX SELECT device, max(time), min(time), max(time) - min(time) FROM metrics GROUP BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- test with sort
:PREFIX SELECT device, sensor, first(time,time), last(time,time) from metrics group by device, sensor order by 1,2;
--- QUERY PLAN ---
GroupAggregate
Group Key: device, sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- test with subquery (SubqueryScan)
:PREFIX SELECT * FROM (SELECT device, min(time), max(time) FROM metrics GROUP BY device) sub ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
:PREFIX SELECT mx, mn, device FROM (SELECT device, min(time) mn, max(time) mx FROM metrics GROUP BY device) sub ORDER BY device;
--- QUERY PLAN ---
Subquery Scan on sub
-> GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- test with CTE (also uses SubqueryScan)
:PREFIX WITH agg_data AS (
SELECT device, min(time) as min_time, max(time) as max_time FROM metrics GROUP BY device
)
SELECT * FROM agg_data ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- test parallel queries (not supported with ColumnarIndexScan)
SELECT set_config(CASE WHEN current_setting('server_version_num')::int < 160000 THEN 'force_parallel_mode' ELSE 'debug_parallel_query' END,'on', false);
set_config
------------
on
:PREFIX SELECT device, min(time), max(time) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
SELECT set_config(CASE WHEN current_setting('server_version_num')::int < 160000 THEN 'force_parallel_mode' ELSE 'debug_parallel_query' END,'off', false);
set_config
------------
off
-- test with UNION ALL (Append node)
:PREFIX SELECT device, min(time) FROM metrics WHERE device = 'd1' GROUP BY device
UNION ALL
SELECT device, min(time) FROM metrics WHERE device = 'd2' GROUP BY device
ORDER BY device;
--- QUERY PLAN ---
Sort
Sort Key: device
-> Append
-> GroupAggregate
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
Index Cond: (device = 'd1'::text)
-> GroupAggregate
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk compress_hyper_2_2_chunk_1
Index Cond: (device = 'd2'::text)
:PREFIX SELECT device, min(time), max(time) FROM metrics GROUP BY device
UNION ALL
SELECT device, max(time), min(time) FROM metrics GROUP BY device ORDER BY 1,2,3;
--- QUERY PLAN ---
Incremental Sort
Sort Key: device, (min("time")), (max("time"))
Presorted Key: device
-> Merge Append
Sort Key: device
-> GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-> GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk compress_hyper_2_2_chunk_1
-- test WINDOW functions
:PREFIX SELECT device, max(time), lead(device) OVER (PARTITION BY max(time)) from metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
Sort
Sort Key: device
-> WindowAgg
-> Sort
Sort Key: (max("time"))
-> GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
:PREFIX SELECT device, max(time), lead(device) OVER (PARTITION BY device) from metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
WindowAgg
-> GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- currently unoptimized queries
-- count on dimension column (could be optimized but currently is not)
:PREFIX SELECT count(time) FROM metrics;
--- QUERY PLAN ---
Aggregate
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
-- count with segmentby column
:PREFIX SELECT count(device) FROM metrics;
--- QUERY PLAN ---
Aggregate
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
-- count with other columns
:PREFIX SELECT count(value) FROM metrics;
--- QUERY PLAN ---
Aggregate
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
-- group by on non-segmentby prevents optimization
:PREFIX SELECT max(time) FROM metrics GROUP BY value;
--- QUERY PLAN ---
HashAggregate
Group Key: _hyper_1_1_chunk.value
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
:PREFIX SELECT device, max(time) FROM metrics GROUP BY device,value;
--- QUERY PLAN ---
HashAggregate
Group Key: _hyper_1_1_chunk.device, _hyper_1_1_chunk.value
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
-- unsupported aggregates on any column
:PREFIX SELECT avg(value) FROM metrics;
--- QUERY PLAN ---
Aggregate
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
:PREFIX SELECT string_agg(device, ',') FROM metrics;
--- QUERY PLAN ---
Aggregate
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
-- aggregate on segmentby column does not use optimization
:PREFIX SELECT device, min(sensor) FROM metrics GROUP BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- aggregate on column without metadata
:PREFIX SELECT min(value2) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- aggregates with FILTER clause
:PREFIX SELECT count(*) FILTER(WHERE device='dev 1') FROM metrics;
--- QUERY PLAN ---
Aggregate
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
:PREFIX SELECT min(value) FILTER(WHERE device='dev 1') FROM metrics;
--- QUERY PLAN ---
Aggregate
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
-- aggregates with DISTINCT
:PREFIX SELECT count(DISTINCT device) FROM metrics;
--- QUERY PLAN ---
Aggregate
-> Custom Scan (SkipScan) on _hyper_1_1_chunk
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- aggregates with ORDER
:PREFIX SELECT min(value ORDER BY time) FROM metrics;
--- QUERY PLAN ---
Aggregate
-> Sort
Sort Key: _hyper_1_1_chunk."time"
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
-- WHERE clause on non-segmentby column
:PREFIX SELECT count(*) FROM metrics WHERE value > 10;
--- QUERY PLAN ---
Aggregate
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
Vectorized Filter: (value > '10'::double precision)
-> Seq Scan on compress_hyper_2_2_chunk
Filter: (_ts_meta_v2_max_value > '10'::double precision)
-- first/last with different arg1 and arg2
:PREFIX SELECT first(value, time) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
:PREFIX SELECT last(value, time) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- GROUPING SETS / ROLLUP / CUBE are not supported by ColumnarIndexScan
:PREFIX SELECT device, sensor, count(*) FROM metrics GROUP BY ROLLUP(device, sensor) ORDER BY device, sensor;
--- QUERY PLAN ---
GroupAggregate
Group Key: _hyper_1_1_chunk.device, _hyper_1_1_chunk.sensor
Group Key: _hyper_1_1_chunk.device
Group Key: ()
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
:PREFIX SELECT device, sensor, count(*) FROM metrics GROUP BY CUBE(device, sensor) ORDER BY device, sensor;
--- QUERY PLAN ---
Sort
Sort Key: _hyper_1_1_chunk.device, _hyper_1_1_chunk.sensor
-> MixedAggregate
Hash Key: _hyper_1_1_chunk.sensor
Group Key: _hyper_1_1_chunk.device, _hyper_1_1_chunk.sensor
Group Key: _hyper_1_1_chunk.device
Group Key: ()
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
:PREFIX SELECT device, sensor, count(*) FROM metrics GROUP BY GROUPING SETS ((device), (sensor), ()) ORDER BY device, sensor;
--- QUERY PLAN ---
Sort
Sort Key: _hyper_1_1_chunk.device, _hyper_1_1_chunk.sensor
-> MixedAggregate
Hash Key: _hyper_1_1_chunk.sensor
Group Key: _hyper_1_1_chunk.device
Group Key: ()
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- DISTINCT on a segmentby column (Agg with no Aggrefs)
:PREFIX SELECT DISTINCT device FROM metrics ORDER BY device;
--- QUERY PLAN ---
Unique
-> Custom Scan (SkipScan) on _hyper_1_1_chunk
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- count(*) without GROUP BY
:PREFIX SELECT count(*) FROM metrics;
--- QUERY PLAN ---
Aggregate
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Seq Scan on compress_hyper_2_2_chunk
-- aggregate only in HAVING (not in SELECT)
:PREFIX SELECT device FROM metrics GROUP BY device HAVING min(value) > 10 ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
Filter: (min(value) > '10'::double precision)
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- GROUP BY ordinal position
:PREFIX SELECT device, min(time) FROM metrics GROUP BY 1 ORDER BY 1;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- GROUP BY () empty grouping
:PREFIX SELECT count(*) FROM metrics GROUP BY ();
--- QUERY PLAN ---
Aggregate
Group Key: ()
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
-- aggregate wrapped in COALESCE
:PREFIX SELECT device, COALESCE(min(time), '2000-01-01'::timestamptz) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- aggregate above a JOIN (Agg not directly above ColumnarScan)
:PREFIX SELECT m.device, min(m.time) FROM metrics m JOIN (VALUES ('d1'), ('d2')) AS d(device) ON m.device = d.device GROUP BY m.device ORDER BY m.device;
--- QUERY PLAN ---
Sort
Sort Key: m.device
-> HashAggregate
Group Key: m.device
-> Nested Loop
-> Values Scan on "*VALUES*"
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk m
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
Index Cond: (device = "*VALUES*".column1)
-- ordered-set aggregate (not supported)
:PREFIX SELECT device, percentile_cont(0.5) WITHIN GROUP (ORDER BY value) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- bool_and / bool_or (not supported)
:PREFIX SELECT device, bool_and(value > 0), bool_or(value > 0) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- partition-wise aggregate
SET enable_partitionwise_aggregate = on;
:PREFIX SELECT device, min(time), max(time) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
SET enable_partitionwise_aggregate = off;
-- Aggref inside a SubLink in the outer tlist (inner aggregate belongs to a separate Agg)
:PREFIX SELECT device, count(*), (SELECT count(*) FROM (VALUES (1),(2),(3)) v(x) WHERE x::text < device) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
SubPlan 1
-> Aggregate
-> Values Scan on "*VALUES*"
Filter: ((column1)::text < device)
-- HAVING with non-pushable expression on grouping columns
:PREFIX SELECT device, sensor, min(time) FROM metrics GROUP BY device, sensor HAVING (device || sensor) LIKE 'd1%' ORDER BY device, sensor;
--- QUERY PLAN ---
GroupAggregate
Group Key: device, sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Sort
Sort Key: compress_hyper_2_2_chunk.device, compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
Filter: ((device || sensor) ~~ 'd1%'::text)
-- same Aggref referenced multiple times in tlist
:PREFIX SELECT device, min(time), date_trunc('day', min(time)) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- GROUP BY column not in SELECT (appears only as resjunk in Agg tlist)
:PREFIX SELECT count(*) FROM metrics GROUP BY device ORDER BY count(*);
--- QUERY PLAN ---
Sort
Sort Key: (COALESCE(sum(compress_hyper_2_2_chunk._ts_meta_count), '0'::bigint))
-> GroupAggregate
Group Key: device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- WHERE mixes segmentby and non-segmentby column
:PREFIX SELECT device, count(*) FROM metrics WHERE device = 'd1' AND value > 10 GROUP BY device ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
Vectorized Filter: (value > '10'::double precision)
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
Index Cond: (device = 'd1'::text)
Filter: (_ts_meta_v2_max_value > '10'::double precision)
-- WHERE with a SubPlan on a segmentby column (not pushable, must not be dropped)
:PREFIX SELECT count(*) FROM metrics WHERE device NOT IN (SELECT 'd' || g FROM generate_series(1,1) g);
--- QUERY PLAN ---
Aggregate
-> Custom Scan (ChunkAppend) on metrics
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
Filter: (NOT (ANY (device = (hashed SubPlan 1).col1)))
-> Seq Scan on compress_hyper_2_2_chunk
SubPlan 1
-> Function Scan on generate_series g
:PREFIX SELECT count(*) FROM metrics WHERE device IN (SELECT 'd' || g FROM generate_series(1,2) g);
--- QUERY PLAN ---
Aggregate
-> Nested Loop
-> Unique
-> Sort
Sort Key: (('d'::text || (g.g)::text))
-> Function Scan on generate_series g
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
Index Cond: (device = ('d'::text || (g.g)::text))
-- HAVING with NOT around Aggref
:PREFIX SELECT device, min(value) FROM metrics GROUP BY device HAVING NOT (min(value) > 10) ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
Filter: (min(value) <= '10'::double precision)
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- HAVING with Aggref IS NULL
:PREFIX SELECT device, min(value) FROM metrics GROUP BY device HAVING min(value) IS NULL ORDER BY device;
--- QUERY PLAN ---
GroupAggregate
Group Key: device
Filter: (min(value) IS NULL)
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-- GROUP BY with explicit collation (not a bare Var)
:PREFIX SELECT device COLLATE "C", count(*) FROM metrics GROUP BY device COLLATE "C" ORDER BY 1;
--- QUERY PLAN ---
GroupAggregate
Group Key: (_hyper_1_1_chunk.device)::text
-> Result
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
-> Sort
Sort Key: compress_hyper_2_2_chunk.device COLLATE "C"
-> Seq Scan on compress_hyper_2_2_chunk
-- self-join on the same hypertable
:PREFIX SELECT m1.device, min(m1.time) FROM metrics m1 JOIN metrics m2 ON m1.device = m2.device GROUP BY m1.device ORDER BY m1.device;
--- QUERY PLAN ---
GroupAggregate
Group Key: m1.device
-> Merge Join
Merge Cond: (m1.device = m2.device)
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk
-> Materialize
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk m2
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_v2_last_tim_idx on compress_hyper_2_2_chunk compress_hyper_2_2_chunk_1
\set PREFIX ''
\set ECHO errors
--- Unoptimized results
+++ Optimized results
@@ -1,6 +1,6 @@
timescaledb.enable_columnarindexscan
--------------------------------------
- off
+ on
device | count
SET timescaledb.enable_columnarindexscan = on;
\ir :TEST_QUERY_NAME
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
-- canary for test diff
SHOW timescaledb.enable_columnarindexscan;
timescaledb.enable_columnarindexscan
--------------------------------------
on
-- simple query with count without grouping
:PREFIX SELECT device, count(*) FROM metrics GROUP BY device;
--- QUERY PLAN ---
Finalize HashAggregate
Group Key: metrics.device
-> Append
-> Partial HashAggregate
Group Key: _hyper_1_1_chunk.device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
-> Partial HashAggregate
Group Key: _hyper_1_1_chunk.device
-> Seq Scan on _hyper_1_1_chunk
-- simple query with count with grouping
:PREFIX SELECT device, count(*) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
Finalize GroupAggregate
Group Key: metrics.device
-> Merge Append
Sort Key: metrics.device
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
-> Sort
Sort Key: compress_hyper_2_2_chunk.device
-> Seq Scan on compress_hyper_2_2_chunk
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Sort
Sort Key: _hyper_1_1_chunk.device
-> Seq Scan on _hyper_1_1_chunk
-- simple query with multiple count with grouping
:PREFIX SELECT device, count(*), count(*) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
Finalize GroupAggregate
Group Key: metrics.device
-> Merge Append
Sort Key: metrics.device
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
-> Sort
Sort Key: compress_hyper_2_2_chunk.device
-> Seq Scan on compress_hyper_2_2_chunk
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Sort
Sort Key: _hyper_1_1_chunk.device
-> Seq Scan on _hyper_1_1_chunk
-- simple query with 1 max aggregate that can use optimization
:PREFIX SELECT device, max(time) FROM metrics GROUP BY device;
--- QUERY PLAN ---
Finalize HashAggregate
Group Key: metrics.device
-> Append
-> Partial HashAggregate
Group Key: _hyper_1_1_chunk.device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
-> Seq Scan on compress_hyper_2_2_chunk
-> Partial HashAggregate
Group Key: _hyper_1_1_chunk.device
-> Seq Scan on _hyper_1_1_chunk
-- simple query with 1 min aggregate that can use optimization
:PREFIX SELECT sensor, min(time) FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---
Finalize GroupAggregate
Group Key: metrics.sensor
-> Merge Append
Sort Key: metrics.sensor
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
-> Sort
Sort Key: compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.sensor
-> Sort
Sort Key: _hyper_1_1_chunk.sensor
-> Seq Scan on _hyper_1_1_chunk
-- simple query with 1 first aggregate that can use optimization
:PREFIX SELECT device, first(time, time) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
Finalize GroupAggregate
Group Key: metrics.device
-> Merge Append
Sort Key: metrics.device
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
-> Sort
Sort Key: compress_hyper_2_2_chunk.device
-> Seq Scan on compress_hyper_2_2_chunk
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Sort
Sort Key: _hyper_1_1_chunk.device
-> Seq Scan on _hyper_1_1_chunk
-- simple query with 1 last aggregate that can use optimization
:PREFIX SELECT device, last(time, time) FROM metrics GROUP BY device ORDER BY device;
--- QUERY PLAN ---
Finalize GroupAggregate
Group Key: metrics.device
-> Merge Append
Sort Key: metrics.device
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
-> Sort
Sort Key: compress_hyper_2_2_chunk.device
-> Seq Scan on compress_hyper_2_2_chunk
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.device
-> Sort
Sort Key: _hyper_1_1_chunk.device
-> Seq Scan on _hyper_1_1_chunk
-- explicit index columns dont prevent optimization
:PREFIX SELECT sensor, min(value) FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---
Finalize GroupAggregate
Group Key: metrics.sensor
-> Merge Append
Sort Key: metrics.sensor
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
-> Sort
Sort Key: compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.sensor
-> Sort
Sort Key: _hyper_1_1_chunk.sensor
-> Seq Scan on _hyper_1_1_chunk
:PREFIX SELECT sensor, min(value), max(value) FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---
Finalize GroupAggregate
Group Key: metrics.sensor
-> Merge Append
Sort Key: metrics.sensor
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
-> Sort
Sort Key: compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.sensor
-> Sort
Sort Key: _hyper_1_1_chunk.sensor
-> Seq Scan on _hyper_1_1_chunk
-- multiple aggregates on same column
:PREFIX SELECT sensor, min(time), max(time), first(time,time), last(time,time) FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---
Finalize GroupAggregate
Group Key: metrics.sensor
-> Merge Append
Sort Key: metrics.sensor
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
-> Sort
Sort Key: compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.sensor
-> Sort
Sort Key: _hyper_1_1_chunk.sensor
-> Seq Scan on _hyper_1_1_chunk
-- same aggregate on multiple columns
:PREFIX SELECT sensor, min(time), min(value) FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---
Finalize GroupAggregate
Group Key: metrics.sensor
-> Merge Append
Sort Key: metrics.sensor
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.sensor
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
-> Sort
Sort Key: compress_hyper_2_2_chunk.sensor
-> Seq Scan on compress_hyper_2_2_chunk
-> Partial GroupAggregate
Group Key: _hyper_1_1_chunk.sensor
-> Sort
Sort Key: _hyper_1_1_chunk.sensor
-> Seq Scan on _hyper_1_1_chunk
-- same aggregate on multiple columns but different order
:PREFIX SELECT sensor, min(value), min(time), sensor FROM metrics GROUP BY sensor ORDER BY sensor;
--- QUERY PLAN ---