You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add more aggregate test cases for ColumnarIndexScan
Cover query shapes that were missing from the test suite:
- DISTINCT on a segmentby column (Agg without Aggrefs)
- count(*) without GROUP BY
- aggregate only in HAVING (not in SELECT)
- GROUP BY ordinal position
- GROUP BY () empty grouping
- aggregate wrapped in COALESCE
- aggregate above a JOIN
- ordered-set aggregate (percentile_cont)
- bool_and / bool_or
- partition-wise aggregate
Copy file name to clipboardExpand all lines: tsl/test/expected/columnar_index_scan-15.out
+379Lines changed: 379 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -571,6 +571,93 @@ SELECT device, max(time), min(time) FROM metrics GROUP BY device ORDER BY 1,2,3;
571
571
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
572
572
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
573
573
574
+
-- DISTINCT on a segmentby column (Agg with no Aggrefs)
575
+
:PREFIX SELECT DISTINCT device FROM metrics ORDER BY device;
576
+
--- QUERY PLAN ---
577
+
Unique
578
+
-> Custom Scan (SkipScan) on _hyper_1_1_chunk
579
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
580
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
581
+
582
+
-- count(*) without GROUP BY
583
+
:PREFIX SELECT count(*) FROM metrics;
584
+
--- QUERY PLAN ---
585
+
Aggregate
586
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
587
+
-> Seq Scan on compress_hyper_2_2_chunk
588
+
589
+
-- aggregate only in HAVING (not in SELECT)
590
+
:PREFIX SELECT device FROM metrics GROUP BY device HAVING min(value) > 10 ORDER BY device;
591
+
--- QUERY PLAN ---
592
+
GroupAggregate
593
+
Group Key: device
594
+
Filter: (min(value) > '10'::double precision)
595
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
596
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
597
+
598
+
-- GROUP BY ordinal position
599
+
:PREFIX SELECT device, min(time) FROM metrics GROUP BY 1 ORDER BY 1;
600
+
--- QUERY PLAN ---
601
+
GroupAggregate
602
+
Group Key: device
603
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
604
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
605
+
606
+
-- GROUP BY () empty grouping
607
+
:PREFIX SELECT count(*) FROM metrics GROUP BY ();
608
+
--- QUERY PLAN ---
609
+
Aggregate
610
+
Group Key: ()
611
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
612
+
-> Seq Scan on compress_hyper_2_2_chunk
613
+
614
+
-- aggregate wrapped in COALESCE
615
+
:PREFIX SELECT device, COALESCE(min(time), '2000-01-01'::timestamptz) FROM metrics GROUP BY device ORDER BY device;
616
+
--- QUERY PLAN ---
617
+
GroupAggregate
618
+
Group Key: device
619
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
620
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
621
+
622
+
-- aggregate above a JOIN (Agg not directly above ColumnarScan)
623
+
: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;
624
+
--- QUERY PLAN ---
625
+
Sort
626
+
Sort Key: m.device
627
+
-> HashAggregate
628
+
Group Key: m.device
629
+
-> Nested Loop
630
+
-> Values Scan on "*VALUES*"
631
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk m
632
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
633
+
Index Cond: (device = "*VALUES*".column1)
634
+
635
+
-- ordered-set aggregate (not supported)
636
+
:PREFIX SELECT device, percentile_cont(0.5) WITHIN GROUP (ORDER BY value) FROM metrics GROUP BY device ORDER BY device;
637
+
--- QUERY PLAN ---
638
+
GroupAggregate
639
+
Group Key: _hyper_1_1_chunk.device
640
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
641
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
642
+
643
+
-- bool_and / bool_or (not supported)
644
+
:PREFIX SELECT device, bool_and(value > 0), bool_or(value > 0) FROM metrics GROUP BY device ORDER BY device;
645
+
--- QUERY PLAN ---
646
+
GroupAggregate
647
+
Group Key: _hyper_1_1_chunk.device
648
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
649
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
650
+
651
+
-- partition-wise aggregate
652
+
SET enable_partitionwise_aggregate = on;
653
+
:PREFIX SELECT device, min(time), max(time) FROM metrics GROUP BY device ORDER BY device;
654
+
--- QUERY PLAN ---
655
+
GroupAggregate
656
+
Group Key: device
657
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
658
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
659
+
660
+
SET enable_partitionwise_aggregate = off;
574
661
\set PREFIX ''
575
662
\set ECHO errors
576
663
--- Unoptimized results
@@ -1486,6 +1573,150 @@ SELECT device, max(time), min(time) FROM metrics GROUP BY device ORDER BY 1,2,3;
1486
1573
-> Seq Scan on compress_hyper_2_2_chunk
1487
1574
-> Seq Scan on _hyper_1_1_chunk
1488
1575
1576
+
-- DISTINCT on a segmentby column (Agg with no Aggrefs)
1577
+
:PREFIX SELECT DISTINCT device FROM metrics ORDER BY device;
1578
+
--- QUERY PLAN ---
1579
+
Sort
1580
+
Sort Key: metrics.device
1581
+
-> HashAggregate
1582
+
Group Key: metrics.device
1583
+
-> Append
1584
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
1585
+
-> Seq Scan on compress_hyper_2_2_chunk
1586
+
-> Seq Scan on _hyper_1_1_chunk
1587
+
1588
+
-- count(*) without GROUP BY
1589
+
:PREFIX SELECT count(*) FROM metrics;
1590
+
--- QUERY PLAN ---
1591
+
Finalize Aggregate
1592
+
-> Append
1593
+
-> Partial Aggregate
1594
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
1595
+
-> Seq Scan on compress_hyper_2_2_chunk
1596
+
-> Partial Aggregate
1597
+
-> Seq Scan on _hyper_1_1_chunk
1598
+
1599
+
-- aggregate only in HAVING (not in SELECT)
1600
+
:PREFIX SELECT device FROM metrics GROUP BY device HAVING min(value) > 10 ORDER BY device;
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
1611
+
-> Seq Scan on compress_hyper_2_2_chunk
1612
+
-> Partial HashAggregate
1613
+
Group Key: _hyper_1_1_chunk.device
1614
+
-> Seq Scan on _hyper_1_1_chunk
1615
+
1616
+
-- GROUP BY ordinal position
1617
+
:PREFIX SELECT device, min(time) FROM metrics GROUP BY 1 ORDER BY 1;
1618
+
--- QUERY PLAN ---
1619
+
Sort
1620
+
Sort Key: metrics.device
1621
+
-> Finalize HashAggregate
1622
+
Group Key: metrics.device
1623
+
-> Append
1624
+
-> Partial HashAggregate
1625
+
Group Key: _hyper_1_1_chunk.device
1626
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
1627
+
-> Seq Scan on compress_hyper_2_2_chunk
1628
+
-> Partial HashAggregate
1629
+
Group Key: _hyper_1_1_chunk.device
1630
+
-> Seq Scan on _hyper_1_1_chunk
1631
+
1632
+
-- GROUP BY () empty grouping
1633
+
:PREFIX SELECT count(*) FROM metrics GROUP BY ();
1634
+
--- QUERY PLAN ---
1635
+
Aggregate
1636
+
Group Key: ()
1637
+
-> Append
1638
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
1639
+
-> Seq Scan on compress_hyper_2_2_chunk
1640
+
-> Seq Scan on _hyper_1_1_chunk
1641
+
1642
+
-- aggregate wrapped in COALESCE
1643
+
:PREFIX SELECT device, COALESCE(min(time), '2000-01-01'::timestamptz) FROM metrics GROUP BY device ORDER BY device;
1644
+
--- QUERY PLAN ---
1645
+
Sort
1646
+
Sort Key: metrics.device
1647
+
-> Finalize HashAggregate
1648
+
Group Key: metrics.device
1649
+
-> Append
1650
+
-> Partial HashAggregate
1651
+
Group Key: _hyper_1_1_chunk.device
1652
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
1653
+
-> Seq Scan on compress_hyper_2_2_chunk
1654
+
-> Partial HashAggregate
1655
+
Group Key: _hyper_1_1_chunk.device
1656
+
-> Seq Scan on _hyper_1_1_chunk
1657
+
1658
+
-- aggregate above a JOIN (Agg not directly above ColumnarScan)
1659
+
: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;
1660
+
--- QUERY PLAN ---
1661
+
Sort
1662
+
Sort Key: m.device
1663
+
-> HashAggregate
1664
+
Group Key: m.device
1665
+
-> Hash Join
1666
+
Hash Cond: (m.device = "*VALUES*".column1)
1667
+
-> Append
1668
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk m_1
1669
+
-> Seq Scan on compress_hyper_2_2_chunk
1670
+
-> Seq Scan on _hyper_1_1_chunk m_1
1671
+
-> Hash
1672
+
-> Values Scan on "*VALUES*"
1673
+
1674
+
-- ordered-set aggregate (not supported)
1675
+
:PREFIX SELECT device, percentile_cont(0.5) WITHIN GROUP (ORDER BY value) FROM metrics GROUP BY device ORDER BY device;
1676
+
--- QUERY PLAN ---
1677
+
GroupAggregate
1678
+
Group Key: metrics.device
1679
+
-> Sort
1680
+
Sort Key: metrics.device
1681
+
-> Append
1682
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
1683
+
-> Seq Scan on compress_hyper_2_2_chunk
1684
+
-> Seq Scan on _hyper_1_1_chunk
1685
+
1686
+
-- bool_and / bool_or (not supported)
1687
+
:PREFIX SELECT device, bool_and(value > 0), bool_or(value > 0) FROM metrics GROUP BY device ORDER BY device;
1688
+
--- QUERY PLAN ---
1689
+
Sort
1690
+
Sort Key: metrics.device
1691
+
-> Finalize HashAggregate
1692
+
Group Key: metrics.device
1693
+
-> Append
1694
+
-> Partial HashAggregate
1695
+
Group Key: _hyper_1_1_chunk.device
1696
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
1697
+
-> Seq Scan on compress_hyper_2_2_chunk
1698
+
-> Partial HashAggregate
1699
+
Group Key: _hyper_1_1_chunk.device
1700
+
-> Seq Scan on _hyper_1_1_chunk
1701
+
1702
+
-- partition-wise aggregate
1703
+
SET enable_partitionwise_aggregate = on;
1704
+
:PREFIX SELECT device, min(time), max(time) FROM metrics GROUP BY device ORDER BY device;
1705
+
--- QUERY PLAN ---
1706
+
Sort
1707
+
Sort Key: metrics.device
1708
+
-> Finalize HashAggregate
1709
+
Group Key: metrics.device
1710
+
-> Append
1711
+
-> Partial HashAggregate
1712
+
Group Key: _hyper_1_1_chunk.device
1713
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk
1714
+
-> Seq Scan on compress_hyper_2_2_chunk
1715
+
-> Partial HashAggregate
1716
+
Group Key: _hyper_1_1_chunk.device
1717
+
-> Seq Scan on _hyper_1_1_chunk
1718
+
1719
+
SET enable_partitionwise_aggregate = off;
1489
1720
\set PREFIX ''
1490
1721
\set ECHO errors
1491
1722
--- Unoptimized results
@@ -2478,6 +2709,154 @@ SELECT device, max(time), min(time) FROM metrics GROUP BY device ORDER BY 1,2,3;
2478
2709
-> Custom Scan (ColumnarScan) on _hyper_1_3_chunk
2479
2710
-> Seq Scan on compress_hyper_2_4_chunk
2480
2711
2712
+
-- DISTINCT on a segmentby column (Agg with no Aggrefs)
2713
+
:PREFIX SELECT DISTINCT device FROM metrics ORDER BY device;
2714
+
--- QUERY PLAN ---
2715
+
Unique
2716
+
-> Merge Append
2717
+
Sort Key: metrics.device
2718
+
-> Custom Scan (SkipScan) on _hyper_1_1_chunk
2719
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
2720
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
2721
+
-> Custom Scan (SkipScan) on _hyper_1_3_chunk
2722
+
-> Custom Scan (ColumnarScan) on _hyper_1_3_chunk
2723
+
-> Index Scan using compress_hyper_2_4_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_4_chunk
2724
+
2725
+
-- count(*) without GROUP BY
2726
+
:PREFIX SELECT count(*) FROM metrics;
2727
+
--- QUERY PLAN ---
2728
+
Finalize Aggregate
2729
+
-> Append
2730
+
-> Partial Aggregate
2731
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
2732
+
-> Seq Scan on compress_hyper_2_2_chunk
2733
+
-> Partial Aggregate
2734
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_3_chunk metrics
2735
+
-> Seq Scan on compress_hyper_2_4_chunk
2736
+
2737
+
-- aggregate only in HAVING (not in SELECT)
2738
+
:PREFIX SELECT device FROM metrics GROUP BY device HAVING min(value) > 10 ORDER BY device;
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
2748
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
2749
+
-> Partial GroupAggregate
2750
+
Group Key: device
2751
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_3_chunk metrics
2752
+
-> Index Scan using compress_hyper_2_4_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_4_chunk
2753
+
2754
+
-- GROUP BY ordinal position
2755
+
:PREFIX SELECT device, min(time) FROM metrics GROUP BY 1 ORDER BY 1;
2756
+
--- QUERY PLAN ---
2757
+
Finalize GroupAggregate
2758
+
Group Key: metrics.device
2759
+
-> Merge Append
2760
+
Sort Key: metrics.device
2761
+
-> Partial GroupAggregate
2762
+
Group Key: device
2763
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
2764
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
2765
+
-> Partial GroupAggregate
2766
+
Group Key: device
2767
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_3_chunk metrics
2768
+
-> Index Scan using compress_hyper_2_4_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_4_chunk
2769
+
2770
+
-- GROUP BY () empty grouping
2771
+
:PREFIX SELECT count(*) FROM metrics GROUP BY ();
2772
+
--- QUERY PLAN ---
2773
+
Aggregate
2774
+
Group Key: ()
2775
+
-> Append
2776
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
2777
+
-> Seq Scan on compress_hyper_2_2_chunk
2778
+
-> Custom Scan (ColumnarScan) on _hyper_1_3_chunk
2779
+
-> Seq Scan on compress_hyper_2_4_chunk
2780
+
2781
+
-- aggregate wrapped in COALESCE
2782
+
:PREFIX SELECT device, COALESCE(min(time), '2000-01-01'::timestamptz) FROM metrics GROUP BY device ORDER BY device;
2783
+
--- QUERY PLAN ---
2784
+
Finalize GroupAggregate
2785
+
Group Key: metrics.device
2786
+
-> Merge Append
2787
+
Sort Key: metrics.device
2788
+
-> Partial GroupAggregate
2789
+
Group Key: device
2790
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
2791
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
2792
+
-> Partial GroupAggregate
2793
+
Group Key: device
2794
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_3_chunk metrics
2795
+
-> Index Scan using compress_hyper_2_4_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_4_chunk
2796
+
2797
+
-- aggregate above a JOIN (Agg not directly above ColumnarScan)
2798
+
: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;
2799
+
--- QUERY PLAN ---
2800
+
Sort
2801
+
Sort Key: m.device
2802
+
-> HashAggregate
2803
+
Group Key: m.device
2804
+
-> Nested Loop
2805
+
-> Values Scan on "*VALUES*"
2806
+
-> Append
2807
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk m_1
2808
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
2809
+
Index Cond: (device = "*VALUES*".column1)
2810
+
-> Custom Scan (ColumnarScan) on _hyper_1_3_chunk m_2
2811
+
-> Index Scan using compress_hyper_2_4_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_4_chunk
2812
+
Index Cond: (device = "*VALUES*".column1)
2813
+
2814
+
-- ordered-set aggregate (not supported)
2815
+
:PREFIX SELECT device, percentile_cont(0.5) WITHIN GROUP (ORDER BY value) FROM metrics GROUP BY device ORDER BY device;
2816
+
--- QUERY PLAN ---
2817
+
GroupAggregate
2818
+
Group Key: metrics.device
2819
+
-> Merge Append
2820
+
Sort Key: metrics.device
2821
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
2822
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
2823
+
-> Custom Scan (ColumnarScan) on _hyper_1_3_chunk
2824
+
-> Index Scan using compress_hyper_2_4_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_4_chunk
2825
+
2826
+
-- bool_and / bool_or (not supported)
2827
+
:PREFIX SELECT device, bool_and(value > 0), bool_or(value > 0) FROM metrics GROUP BY device ORDER BY device;
2828
+
--- QUERY PLAN ---
2829
+
Finalize GroupAggregate
2830
+
Group Key: metrics.device
2831
+
-> Merge Append
2832
+
Sort Key: metrics.device
2833
+
-> Partial GroupAggregate
2834
+
Group Key: _hyper_1_1_chunk.device
2835
+
-> Custom Scan (ColumnarScan) on _hyper_1_1_chunk
2836
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
2837
+
-> Partial GroupAggregate
2838
+
Group Key: _hyper_1_3_chunk.device
2839
+
-> Custom Scan (ColumnarScan) on _hyper_1_3_chunk
2840
+
-> Index Scan using compress_hyper_2_4_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_4_chunk
2841
+
2842
+
-- partition-wise aggregate
2843
+
SET enable_partitionwise_aggregate = on;
2844
+
:PREFIX SELECT device, min(time), max(time) FROM metrics GROUP BY device ORDER BY device;
2845
+
--- QUERY PLAN ---
2846
+
Finalize GroupAggregate
2847
+
Group Key: metrics.device
2848
+
-> Merge Append
2849
+
Sort Key: metrics.device
2850
+
-> Partial GroupAggregate
2851
+
Group Key: device
2852
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_1_chunk metrics
2853
+
-> Index Scan using compress_hyper_2_2_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_2_chunk
2854
+
-> Partial GroupAggregate
2855
+
Group Key: device
2856
+
-> Custom Scan (ColumnarIndexScan) on _hyper_1_3_chunk metrics
2857
+
-> Index Scan using compress_hyper_2_4_chunk_device_sensor__ts_meta_min_1__ts_m_idx on compress_hyper_2_4_chunk
0 commit comments