diff --git a/pkg/sql/opt/memo/testdata/stats_quality/tpch/q20 b/pkg/sql/opt/memo/testdata/stats_quality/tpch/q20 index 71053947aae6..a0ea53090221 100644 --- a/pkg/sql/opt/memo/testdata/stats_quality/tpch/q20 +++ b/pkg/sql/opt/memo/testdata/stats_quality/tpch/q20 @@ -101,91 +101,78 @@ sort │ │ ├── immutable │ │ ├── stats: [rows=2e-05, distinct(17)=2e-05, null(17)=0] │ │ ├── key: (17) - │ │ └── project - │ │ ├── save-table-name: q20_project_7 - │ │ ├── columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) + │ │ └── inner-join (lookup part) + │ │ ├── save-table-name: q20_lookup_join_7 + │ │ ├── columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) ps_availqty:18(int!null) p_partkey:23(int!null) p_name:24(varchar!null) sum:52(float!null) + │ │ ├── key columns: [16] = [23] + │ │ ├── lookup columns are key │ │ ├── immutable - │ │ ├── stats: [rows=2e-05, distinct(16)=2e-05, null(16)=0, distinct(17)=2e-05, null(17)=0] - │ │ ├── key: (16,17) - │ │ └── project - │ │ ├── save-table-name: q20_project_8 - │ │ ├── columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) p_partkey:23(int!null) - │ │ ├── immutable - │ │ ├── stats: [rows=0.00249835317, distinct(16)=2e-05, null(16)=0, distinct(17)=0.00249835317, null(17)=0, distinct(23)=2e-05, null(23)=0] - │ │ ├── key: (17,23) - │ │ ├── fd: (16)==(23), (23)==(16) - │ │ └── inner-join (lookup part) - │ │ ├── save-table-name: q20_lookup_join_9 - │ │ ├── columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) ps_availqty:18(int!null) p_partkey:23(int!null) p_name:24(varchar!null) sum:52(float!null) - │ │ ├── key columns: [16] = [23] - │ │ ├── lookup columns are key - │ │ ├── immutable - │ │ ├── stats: [rows=0.00249835317, distinct(16)=2e-05, null(16)=0, distinct(17)=0.00249835317, null(17)=0, distinct(18)=0.00249835317, null(18)=0, distinct(23)=2e-05, null(23)=0, distinct(24)=7.51678871e-09, null(24)=0, distinct(52)=0.00249835317, null(52)=0] - │ │ ├── key: (17,23) - │ │ ├── fd: (16,17)-->(18,52), (23)-->(24), (16)==(23), (23)==(16) - │ │ ├── select - │ │ │ ├── save-table-name: q20_select_10 - │ │ │ ├── columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) ps_availqty:18(int!null) sum:52(float!null) - │ │ │ ├── immutable - │ │ │ ├── stats: [rows=124.917659, distinct(16)=124.917659, null(16)=0, distinct(17)=124.917659, null(17)=0, distinct(18)=124.917659, null(18)=0, distinct(52)=124.917659, null(52)=0] - │ │ │ ├── key: (16,17) - │ │ │ ├── fd: (16,17)-->(18,52) - │ │ │ ├── group-by - │ │ │ │ ├── save-table-name: q20_group_by_11 - │ │ │ │ ├── columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) ps_availqty:18(int!null) sum:52(float!null) - │ │ │ │ ├── grouping columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) - │ │ │ │ ├── stats: [rows=374.752976, distinct(16)=374.752976, null(16)=0, distinct(17)=374.752976, null(17)=0, distinct(18)=374.752976, null(18)=0, distinct(52)=374.752976, null(52)=0, distinct(16,17)=374.752976, null(16,17)=0] - │ │ │ │ ├── key: (16,17) - │ │ │ │ ├── fd: (16,17)-->(18,52) - │ │ │ │ ├── inner-join (hash) - │ │ │ │ │ ├── save-table-name: q20_inner_join_12 - │ │ │ │ │ ├── columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) ps_availqty:18(int!null) l_partkey:35(int!null) l_suppkey:36(int!null) l_quantity:38(float!null) l_shipdate:44(date!null) - │ │ │ │ │ ├── multiplicity: left-rows(exactly-one), right-rows(zero-or-more) - │ │ │ │ │ ├── stats: [rows=374.752976, distinct(16)=374.752976, null(16)=0, distinct(17)=374.752976, null(17)=0, distinct(18)=367.762691, null(18)=0, distinct(35)=374.752976, null(35)=0, distinct(36)=374.752976, null(36)=0, distinct(38)=49.9722088, null(38)=0, distinct(44)=234.264424, null(44)=0, distinct(16,17)=374.752976, null(16,17)=0] - │ │ │ │ │ ├── fd: (16,17)-->(18), (16)==(35), (35)==(16), (17)==(36), (36)==(17) - │ │ │ │ │ ├── index-join lineitem - │ │ │ │ │ │ ├── save-table-name: q20_index_join_13 - │ │ │ │ │ │ ├── columns: l_partkey:35(int!null) l_suppkey:36(int!null) l_quantity:38(float!null) l_shipdate:44(date!null) - │ │ │ │ │ │ ├── stats: [rows=925860.354, distinct(35)=197960.338, null(35)=0, distinct(36)=9920, null(36)=0, distinct(38)=50, null(38)=0, distinct(44)=365, null(44)=0] - │ │ │ │ │ │ │ histogram(44)= 0 0 24928 2400 27605 1800 27605 2400 28205 4800 28205 3000 28205 1800 25205 4200 28805 1800 28205 4200 27005 3600 28205 1800 26405 3600 27605 2400 28805 1200 24004 5401 27005 5401 28205 3600 28205 1200 28805 1800 27005 3600 27605 1800 27005 2400 27605 4200 26405 5401 28205 4200 27605 2400 28205 1800 26405 3000 27005 4200 28805 3000 6901.2 3450.6 - │ │ │ │ │ │ │ <--- '1993-12-31' ------- '1994-01-13' ------- '1994-01-27' ------- '1994-02-06' ------- '1994-02-19' ------- '1994-03-04' ------- '1994-03-17' ------- '1994-03-29' ------- '1994-04-10' ------- '1994-04-22' ------- '1994-05-02' ------- '1994-05-17' ------- '1994-05-27' ------- '1994-06-08' ------- '1994-06-21' ------- '1994-07-04' ------- '1994-07-15' ------- '1994-07-25' ------- '1994-08-09' ------- '1994-08-18' ------- '1994-08-30' ------- '1994-09-14' ------- '1994-09-26' ------- '1994-10-07' ------- '1994-10-20' ------- '1994-10-31' ------- '1994-11-10' ------- '1994-11-22' ------- '1994-12-05' ------- '1994-12-16' ------- '1994-12-28' -------- '1994-12-31' - │ │ │ │ │ │ └── scan lineitem@l_sd - │ │ │ │ │ │ ├── save-table-name: q20_scan_14 - │ │ │ │ │ │ ├── columns: l_orderkey:34(int!null) l_linenumber:37(int!null) l_shipdate:44(date!null) - │ │ │ │ │ │ ├── constraint: /44/34/37: [/'1994-01-01' - /'1994-12-31'] - │ │ │ │ │ │ ├── stats: [rows=925860.354, distinct(34)=736656.352, null(34)=0, distinct(37)=7, null(37)=0, distinct(44)=365, null(44)=0] - │ │ │ │ │ │ │ histogram(34)= 0 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4444 185.13 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4444 185.13 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 - │ │ │ │ │ │ │ <---- 32 --------- 27780 -------- 60677 -------- 87430 -------- 111814 -------- 139648 -------- 166148 -------- 198051 -------- 232580 -------- 259104 -------- 283460 -------- 311460 -------- 344230 -------- 376102 -------- 408963 -------- 436743 -------- 470368 -------- 503942 -------- 531236 -------- 559395 -------- 589314 -------- 620839 -------- 649670 -------- 672483 -------- 698693 -------- 726629 -------- 756997 -------- 796164 -------- 824327 -------- 855873 -------- 882247 -------- 916418 -------- 951748 -------- 978498 -------- 1005765 -------- 1036864 -------- 1061351 -------- 1093638 -------- 1122308 -------- 1155844 -------- 1191239 -------- 1225540 -------- 1254915 -------- 1281670 -------- 1306721 -------- 1337410 -------- 1368419 -------- 1405382 -------- 1438210 -------- 1465477 -------- 1490627 -------- 1517251 -------- 1544289 -------- 1573729 -------- 1607168 -------- 1635648 -------- 1658848 -------- 1691623 -------- 1718631 -------- 1753345 -------- 1782470 -------- 1812742 -------- 1837702 -------- 1873349 -------- 1905733 -------- 1941024 -------- 1977287 -------- 2005826 -------- 2035300 -------- 2067878 -------- 2093927 -------- 2127906 -------- 2154055 -------- 2181095 -------- 2212035 -------- 2242374 -------- 2263458 -------- 2288481 -------- 2315300 -------- 2340997 -------- 2371200 -------- 2399616 -------- 2429154 -------- 2455393 -------- 2488384 -------- 2521088 -------- 2550885 -------- 2581058 -------- 2610496 -------- 2644197 -------- 2675648 -------- 2698821 -------- 2726246 -------- 2757444 -------- 2792612 -------- 2827174 -------- 2846849 -------- 2881250 -------- 2900739 -------- 2930660 -------- 2962240 -------- 2999235 -------- 3031974 -------- 3060197 -------- 3087586 -------- 3120390 -------- 3147524 -------- 3170721 -------- 3199173 ------ 3230049 -------- 3255008 -------- 3284965 -------- 3315744 -------- 3345376 -------- 3379776 -------- 3405445 -------- 3436711 -------- 3467557 -------- 3489541 -------- 3518179 -------- 3546276 -------- 3568964 ------ 3596039 -------- 3621926 -------- 3644805 -------- 3675361 -------- 3706592 -------- 3735589 -------- 3761220 -------- 3789607 -------- 3820866 -------- 3862274 -------- 3898051 -------- 3925188 -------- 3957157 -------- 3983873 -------- 4013092 -------- 4039202 -------- 4070918 -------- 4105696 -------- 4136867 -------- 4169475 -------- 4205249 -------- 4239013 -------- 4264423 -------- 4292135 -------- 4324453 -------- 4356356 -------- 4392386 -------- 4423074 -------- 4447335 -------- 4469345 -------- 4496513 -------- 4530848 -------- 4565159 -------- 4596965 -------- 4627011 -------- 4662598 -------- 4690818 -------- 4718691 -------- 4749349 -------- 4782722 -------- 4824485 -------- 4856323 -------- 4885795 -------- 4911142 -------- 4945794 -------- 4972801 -------- 5000583 -------- 5033735 -------- 5072421 -------- 5112929 -------- 5145956 -------- 5181923 -------- 5217478 -------- 5247620 -------- 5273605 -------- 5304100 -------- 5343362 -------- 5375842 -------- 5408391 -------- 5439046 -------- 5464610 -------- 5497857 -------- 5528295 -------- 5557956 -------- 5593474 -------- 5626209 -------- 5660931 -------- 5703463 -------- 5733440 -------- 5762565 -------- 5788034 -------- 5813505 -------- 5848227 -------- 5870727 -------- 5908998 -------- 5938311 -------- 5968930 -------- 5999751 - │ │ │ │ │ │ │ histogram(37)= 0 2.3017e+05 0 1.9693e+05 0 1.6119e+05 0 1.3036e+05 0 1.0268e+05 0 69069 0 35460 - │ │ │ │ │ │ │ <------ 1 ---------- 2 ---------- 3 ---------- 4 ---------- 5 -------- 6 ----- 7 - - │ │ │ │ │ │ │ histogram(44)= 0 0 24928 2400 27605 1800 27605 2400 28205 4800 28205 3000 28205 1800 25205 4200 28805 1800 28205 4200 27005 3600 28205 1800 26405 3600 27605 2400 28805 1200 24004 5401 27005 5401 28205 3600 28205 1200 28805 1800 27005 3600 27605 1800 27005 2400 27605 4200 26405 5401 28205 4200 27605 2400 28205 1800 26405 3000 27005 4200 28805 3000 6901.2 3450.6 - │ │ │ │ │ │ │ <--- '1993-12-31' ------- '1994-01-13' ------- '1994-01-27' ------- '1994-02-06' ------- '1994-02-19' ------- '1994-03-04' ------- '1994-03-17' ------- '1994-03-29' ------- '1994-04-10' ------- '1994-04-22' ------- '1994-05-02' ------- '1994-05-17' ------- '1994-05-27' ------- '1994-06-08' ------- '1994-06-21' ------- '1994-07-04' ------- '1994-07-15' ------- '1994-07-25' ------- '1994-08-09' ------- '1994-08-18' ------- '1994-08-30' ------- '1994-09-14' ------- '1994-09-26' ------- '1994-10-07' ------- '1994-10-20' ------- '1994-10-31' ------- '1994-11-10' ------- '1994-11-22' ------- '1994-12-05' ------- '1994-12-16' ------- '1994-12-28' -------- '1994-12-31' - │ │ │ │ │ │ ├── key: (34,37) - │ │ │ │ │ │ └── fd: (34,37)-->(44) - │ │ │ │ │ ├── scan partsupp - │ │ │ │ │ │ ├── save-table-name: q20_scan_15 - │ │ │ │ │ │ ├── columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) ps_availqty:18(int!null) - │ │ │ │ │ │ ├── stats: [rows=800000, distinct(16)=199241, null(16)=0, distinct(17)=9920, null(17)=0, distinct(18)=9920, null(18)=0, distinct(16,17)=798302, null(16,17)=0] - │ │ │ │ │ │ │ histogram(16)= 0 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3840 160 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3840 160 3920 80 3920 80 3920 160 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 160 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 160 3920 80 3920 80 3920 80 3920 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 - │ │ │ │ │ │ │ <--- 11 ------ 765 ------ 1954 ------ 3094 ------ 4311 ------ 5377 ------ 6431 ------ 7396 ------ 8288 ------ 9272 ------ 10101 ------ 11159 ------ 12287 ------ 13216 ------ 14316 ------ 15503 ------ 16605 ------ 17726 ------ 18717 ------ 19542 ------ 20537 ------ 21666 ------ 22752 ------ 23971 ------ 24995 ------ 25994 ------ 26842 ------ 27390 ------ 28440 ------ 29526 ------ 30460 ------ 31515 ------ 32312 ------ 33159 ------ 33972 ------ 34884 ------ 35855 ------ 36884 ------ 38010 ------ 39033 ------ 39975 ------ 41212 ------ 42073 ------ 42782 ------ 43708 ------ 44715 ------ 45878 ------ 47111 ------ 48039 ------ 49002 ------ 50120 ------ 51213 ------ 52110 ------ 53025 ------ 53839 ------ 54936 ------ 55856 ------ 56820 ------ 58014 ------ 59079 ------ 59981 ------ 60972 ------ 62028 ------ 63090 ------ 64027 ------ 64909 ------ 65916 ------ 66861 ------ 67912 ------ 68977 ------ 70169 ------ 71156 ------ 72183 ------ 73210 ------ 74218 ------ 75126 ------ 76182 ------ 77201 ------ 78004 ------ 78975 ------ 79993 ------ 80986 ------ 81978 ------ 82761 ------ 83782 ------ 84946 ------ 85946 ------ 86808 ------ 87656 ------ 88587 ------ 89454 ------ 90799 ------ 91730 ------ 92853 ------ 93711 ------ 94565 ------ 95544 ------ 96591 ------ 97578 ------ 98568 ------ 99475 ------ 100626 ------ 101679 ------ 102802 ------ 103800 ------ 104901 ------ 105678 ------ 106420 ------ 107335 ------ 108666 ------ 109855 ------ 110808 ------ 111732 ------ 112497 ------ 113432 ------ 114405 ------ 115440 ------ 116504 ------ 117316 ------ 118321 ------ 119068 ------ 119846 ------ 120926 ------ 122077 ------ 122949 ------ 123943 ------ 124937 ------ 126233 ------ 127250 ------ 128140 ------ 129049 ------ 129887 ------ 130876 ------ 131726 ------ 132511 ------ 133477 ------ 134247 ------ 135281 ------ 136204 ------ 137302 ------ 138754 ------ 140003 ------ 140831 ------ 141666 ------ 142617 ------ 143565 ------ 144737 ------ 145910 ------ 146952 ------ 147912 ------ 148781 ------ 149766 ------ 150631 ------ 151819 ------ 152865 ------ 153895 ------ 154813 ------ 155710 ------ 156815 ------ 157926 ------ 159092 ------ 160005 ------ 161023 ------ 162111 ------ 163183 ------ 164159 ------ 165338 ------ 166253 ------ 167290 ------ 168099 ------ 169524 ------ 170467 ------ 171236 ------ 172225 ------ 173089 ------ 174101 ------ 175241 ------ 176102 ------ 176969 ------ 178074 ------ 178858 ------ 179838 ------ 181097 ------ 182021 ------ 182950 ------ 184039 ------ 184907 ------ 185995 ------ 187520 ------ 188513 ------ 189558 ------ 190767 ------ 192126 ------ 193405 ------ 194495 ------ 195462 ------ 196564 ------ 197793 ------ 198874 ------ 199967 - │ │ │ │ │ │ │ histogram(17)= 0 80 3840 160 3920 80 3840 160 3920 160 3920 80 3840 160 3920 240 3920 80 3920 80 3920 80 3920 240 3920 80 3760 240 3920 80 3920 80 3920 80 3920 80 3920 320 3920 80 3680 320 3920 160 3920 80 3920 80 3840 160 3920 160 3840 160 3920 80 3920 80 3920 80 3920 160 3920 240 3920 80 3840 160 3920 80 3840 240 3920 160 3920 160 3840 160 3920 240 3840 320 3760 240 3840 160 3840 160 3920 240 3920 80 3840 240 3680 480 3920 80 3920 80 3920 80 3920 160 3920 160 3920 80 3920 80 3920 160 3760 320 3840 320 3920 320 3920 80 3920 160 3920 80 3840 160 3840 160 3920 80 3920 80 3920 240 3760 240 3920 160 3920 160 3920 80 3840 160 3920 160 3840 320 3920 80 3920 80 3920 240 3920 160 3920 160 3920 240 3920 80 3920 240 3680 400 3680 320 3840 80 3840 160 3760 240 3840 80 3840 320 3840 160 3840 80 3840 240 3840 80 3840 160 3840 80 3840 240 3760 240 3760 160 3920 80 3840 240 3840 80 3920 80 3920 160 3840 160 3840 80 3760 320 3840 80 3920 80 3920 80 3920 80 3920 320 3840 80 3840 80 3840 160 3760 240 3840 160 3840 80 3920 80 3840 240 3760 160 3840 160 3840 160 3760 240 3760 240 3840 160 3840 160 3920 80 3840 160 3840 160 3840 160 3760 240 3760 240 3920 240 3840 80 3840 80 3920 80 3920 160 3760 160 3840 160 3920 80 3600 480 3760 160 3920 80 3920 80 3840 240 3840 160 3680 240 3680 320 3920 240 3760 160 3840 80 3920 160 3760 320 3840 160 3840 80 3840 80 3920 80 3920 160 3840 320 3760 160 3840 240 3840 80 3760 160 3680 240 3920 160 3840 80 3840 240 3680 240 3920 160 3840 80 3920 160 3760 160 3920 160 3840 80 3760 240 3920 160 3840 80 3920 80 3920 80 3920 80 3920 80 3680 320 3760 240 3920 80 3920 80 3920 160 3760 160 3840 240 3840 160 3840 80 3760 240 3920 80 3600 400 3920 80 3920 80 3840 160 3920 80 3920 160 3600 320 3920 80 - │ │ │ │ │ │ │ <--- 1 ------ 57 ------ 119 ------ 176 ------ 228 ------ 277 ------ 315 ------ 390 ------ 437 ------ 479 ------ 517 ------ 568 ------ 626 ------ 678 ------ 728 ------ 785 ------ 850 ------ 900 ------ 965 ------ 1015 ------ 1056 ------ 1101 ------ 1152 ------ 1194 ------ 1236 ------ 1282 ------ 1331 ------ 1389 ------ 1456 ------ 1505 ------ 1555 ------ 1605 ------ 1650 ------ 1710 ------ 1762 ------ 1806 ------ 1855 ------ 1911 ------ 1959 ------ 2021 ------ 2076 ------ 2120 ------ 2169 ------ 2218 ------ 2284 ------ 2324 ------ 2365 ------ 2412 ------ 2474 ------ 2524 ------ 2568 ------ 2620 ------ 2665 ------ 2719 ------ 2781 ------ 2831 ------ 2884 ------ 2926 ------ 2973 ------ 3012 ------ 3071 ------ 3112 ------ 3158 ------ 3209 ------ 3250 ------ 3313 ------ 3366 ------ 3414 ------ 3463 ------ 3514 ------ 3557 ------ 3608 ------ 3668 ------ 3713 ------ 3777 ------ 3827 ------ 3882 ------ 3938 ------ 3989 ------ 4036 ------ 4084 ------ 4134 ------ 4182 ------ 4231 ------ 4292 ------ 4337 ------ 4382 ------ 4426 ------ 4474 ------ 4521 ------ 4568 ------ 4614 ------ 4651 ------ 4695 ------ 4742 ------ 4800 ------ 4853 ------ 4905 ------ 4954 ------ 4997 ------ 5050 ------ 5115 ------ 5167 ------ 5231 ------ 5276 ------ 5325 ------ 5371 ------ 5419 ------ 5484 ------ 5547 ------ 5586 ------ 5636 ------ 5685 ------ 5744 ------ 5799 ------ 5855 ------ 5894 ------ 5938 ------ 5984 ------ 6038 ------ 6085 ------ 6143 ------ 6196 ------ 6257 ------ 6306 ------ 6350 ------ 6395 ------ 6445 ------ 6497 ------ 6556 ------ 6596 ------ 6636 ------ 6684 ------ 6744 ------ 6799 ------ 6844 ------ 6894 ------ 6947 ------ 6994 ------ 7048 ------ 7104 ------ 7149 ------ 7199 ------ 7248 ------ 7288 ------ 7343 ------ 7391 ------ 7446 ------ 7492 ------ 7538 ------ 7598 ------ 7650 ------ 7702 ------ 7767 ------ 7799 ------ 7849 ------ 7898 ------ 7941 ------ 7989 ------ 8041 ------ 8086 ------ 8127 ------ 8169 ------ 8216 ------ 8263 ------ 8326 ------ 8374 ------ 8413 ------ 8465 ------ 8521 ------ 8579 ------ 8631 ------ 8680 ------ 8732 ------ 8783 ------ 8832 ------ 8888 ------ 8945 ------ 8997 ------ 9052 ------ 9106 ------ 9136 ------ 9193 ------ 9234 ------ 9279 ------ 9326 ------ 9381 ------ 9426 ------ 9471 ------ 9519 ------ 9552 ------ 9609 ------ 9660 ------ 9716 ------ 9762 ------ 9815 ------ 9863 ------ 9910 ------ 9948 ------ 10000 - │ │ │ │ │ │ │ histogram(18)= 0 240 7.9968e+05 80 - │ │ │ │ │ │ │ <--- 2 ------------ 9999 - │ │ │ │ │ │ ├── key: (16,17) - │ │ │ │ │ │ └── fd: (16,17)-->(18) - │ │ │ │ │ └── filters - │ │ │ │ │ ├── l_partkey:35 = ps_partkey:16 [type=bool, outer=(16,35), constraints=(/16: (/NULL - ]; /35: (/NULL - ]), fd=(16)==(35), (35)==(16)] - │ │ │ │ │ └── l_suppkey:36 = ps_suppkey:17 [type=bool, outer=(17,36), constraints=(/17: (/NULL - ]; /36: (/NULL - ]), fd=(17)==(36), (36)==(17)] - │ │ │ │ └── aggregations - │ │ │ │ ├── sum [as=sum:52, type=float, outer=(38)] - │ │ │ │ │ └── l_quantity:38 [type=float] - │ │ │ │ └── const-agg [as=ps_availqty:18, type=int, outer=(18)] - │ │ │ │ └── ps_availqty:18 [type=int] - │ │ │ └── filters - │ │ │ └── ps_availqty:18 > (sum:52 * 0.5) [type=bool, outer=(18,52), immutable, constraints=(/18: (/NULL - ])] - │ │ └── filters - │ │ └── p_name:24 LIKE 'forest%' [type=bool, outer=(24), constraints=(/24: [/'forest' - /'foresu'); tight)] + │ │ ├── stats: [rows=0.00249835317, distinct(16)=2e-05, null(16)=0, distinct(17)=0.00249835317, null(17)=0, distinct(18)=0.00249835317, null(18)=0, distinct(23)=2e-05, null(23)=0, distinct(24)=7.51678871e-09, null(24)=0, distinct(52)=0.00249835317, null(52)=0] + │ │ ├── key: (17,23) + │ │ ├── fd: (16,17)-->(18,52), (23)-->(24), (16)==(23), (23)==(16) + │ │ ├── select + │ │ │ ├── save-table-name: q20_select_8 + │ │ │ ├── columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) ps_availqty:18(int!null) sum:52(float!null) + │ │ │ ├── immutable + │ │ │ ├── stats: [rows=124.917659, distinct(16)=124.917659, null(16)=0, distinct(17)=124.917659, null(17)=0, distinct(18)=124.917659, null(18)=0, distinct(52)=124.917659, null(52)=0] + │ │ │ ├── key: (16,17) + │ │ │ ├── fd: (16,17)-->(18,52) + │ │ │ ├── group-by + │ │ │ │ ├── save-table-name: q20_group_by_9 + │ │ │ │ ├── columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) ps_availqty:18(int!null) sum:52(float!null) + │ │ │ │ ├── grouping columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) + │ │ │ │ ├── stats: [rows=374.752976, distinct(16)=374.752976, null(16)=0, distinct(17)=374.752976, null(17)=0, distinct(18)=374.752976, null(18)=0, distinct(52)=374.752976, null(52)=0, distinct(16,17)=374.752976, null(16,17)=0] + │ │ │ │ ├── key: (16,17) + │ │ │ │ ├── fd: (16,17)-->(18,52) + │ │ │ │ ├── inner-join (hash) + │ │ │ │ │ ├── save-table-name: q20_inner_join_10 + │ │ │ │ │ ├── columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) ps_availqty:18(int!null) l_partkey:35(int!null) l_suppkey:36(int!null) l_quantity:38(float!null) l_shipdate:44(date!null) + │ │ │ │ │ ├── multiplicity: left-rows(exactly-one), right-rows(zero-or-more) + │ │ │ │ │ ├── stats: [rows=374.752976, distinct(16)=374.752976, null(16)=0, distinct(17)=374.752976, null(17)=0, distinct(18)=367.762691, null(18)=0, distinct(35)=374.752976, null(35)=0, distinct(36)=374.752976, null(36)=0, distinct(38)=49.9722088, null(38)=0, distinct(44)=234.264424, null(44)=0, distinct(16,17)=374.752976, null(16,17)=0] + │ │ │ │ │ ├── fd: (16,17)-->(18), (16)==(35), (35)==(16), (17)==(36), (36)==(17) + │ │ │ │ │ ├── index-join lineitem + │ │ │ │ │ │ ├── save-table-name: q20_index_join_11 + │ │ │ │ │ │ ├── columns: l_partkey:35(int!null) l_suppkey:36(int!null) l_quantity:38(float!null) l_shipdate:44(date!null) + │ │ │ │ │ │ ├── stats: [rows=925860.354, distinct(35)=197960.338, null(35)=0, distinct(36)=9920, null(36)=0, distinct(38)=50, null(38)=0, distinct(44)=365, null(44)=0] + │ │ │ │ │ │ │ histogram(44)= 0 0 24928 2400 27605 1800 27605 2400 28205 4800 28205 3000 28205 1800 25205 4200 28805 1800 28205 4200 27005 3600 28205 1800 26405 3600 27605 2400 28805 1200 24004 5401 27005 5401 28205 3600 28205 1200 28805 1800 27005 3600 27605 1800 27005 2400 27605 4200 26405 5401 28205 4200 27605 2400 28205 1800 26405 3000 27005 4200 28805 3000 6901.2 3450.6 + │ │ │ │ │ │ │ <--- '1993-12-31' ------- '1994-01-13' ------- '1994-01-27' ------- '1994-02-06' ------- '1994-02-19' ------- '1994-03-04' ------- '1994-03-17' ------- '1994-03-29' ------- '1994-04-10' ------- '1994-04-22' ------- '1994-05-02' ------- '1994-05-17' ------- '1994-05-27' ------- '1994-06-08' ------- '1994-06-21' ------- '1994-07-04' ------- '1994-07-15' ------- '1994-07-25' ------- '1994-08-09' ------- '1994-08-18' ------- '1994-08-30' ------- '1994-09-14' ------- '1994-09-26' ------- '1994-10-07' ------- '1994-10-20' ------- '1994-10-31' ------- '1994-11-10' ------- '1994-11-22' ------- '1994-12-05' ------- '1994-12-16' ------- '1994-12-28' -------- '1994-12-31' + │ │ │ │ │ │ └── scan lineitem@l_sd + │ │ │ │ │ │ ├── save-table-name: q20_scan_12 + │ │ │ │ │ │ ├── columns: l_orderkey:34(int!null) l_linenumber:37(int!null) l_shipdate:44(date!null) + │ │ │ │ │ │ ├── constraint: /44/34/37: [/'1994-01-01' - /'1994-12-31'] + │ │ │ │ │ │ ├── stats: [rows=925860.354, distinct(34)=736656.352, null(34)=0, distinct(37)=7, null(37)=0, distinct(44)=365, null(44)=0] + │ │ │ │ │ │ │ histogram(34)= 0 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4444 185.13 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4444 185.13 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4536.6 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 4629.3 92.567 + │ │ │ │ │ │ │ <---- 32 --------- 27780 -------- 60677 -------- 87430 -------- 111814 -------- 139648 -------- 166148 -------- 198051 -------- 232580 -------- 259104 -------- 283460 -------- 311460 -------- 344230 -------- 376102 -------- 408963 -------- 436743 -------- 470368 -------- 503942 -------- 531236 -------- 559395 -------- 589314 -------- 620839 -------- 649670 -------- 672483 -------- 698693 -------- 726629 -------- 756997 -------- 796164 -------- 824327 -------- 855873 -------- 882247 -------- 916418 -------- 951748 -------- 978498 -------- 1005765 -------- 1036864 -------- 1061351 -------- 1093638 -------- 1122308 -------- 1155844 -------- 1191239 -------- 1225540 -------- 1254915 -------- 1281670 -------- 1306721 -------- 1337410 -------- 1368419 -------- 1405382 -------- 1438210 -------- 1465477 -------- 1490627 -------- 1517251 -------- 1544289 -------- 1573729 -------- 1607168 -------- 1635648 -------- 1658848 -------- 1691623 -------- 1718631 -------- 1753345 -------- 1782470 -------- 1812742 -------- 1837702 -------- 1873349 -------- 1905733 -------- 1941024 -------- 1977287 -------- 2005826 -------- 2035300 -------- 2067878 -------- 2093927 -------- 2127906 -------- 2154055 -------- 2181095 -------- 2212035 -------- 2242374 -------- 2263458 -------- 2288481 -------- 2315300 -------- 2340997 -------- 2371200 -------- 2399616 -------- 2429154 -------- 2455393 -------- 2488384 -------- 2521088 -------- 2550885 -------- 2581058 -------- 2610496 -------- 2644197 -------- 2675648 -------- 2698821 -------- 2726246 -------- 2757444 -------- 2792612 -------- 2827174 -------- 2846849 -------- 2881250 -------- 2900739 -------- 2930660 -------- 2962240 -------- 2999235 -------- 3031974 -------- 3060197 -------- 3087586 -------- 3120390 -------- 3147524 -------- 3170721 -------- 3199173 ------ 3230049 -------- 3255008 -------- 3284965 -------- 3315744 -------- 3345376 -------- 3379776 -------- 3405445 -------- 3436711 -------- 3467557 -------- 3489541 -------- 3518179 -------- 3546276 -------- 3568964 ------ 3596039 -------- 3621926 -------- 3644805 -------- 3675361 -------- 3706592 -------- 3735589 -------- 3761220 -------- 3789607 -------- 3820866 -------- 3862274 -------- 3898051 -------- 3925188 -------- 3957157 -------- 3983873 -------- 4013092 -------- 4039202 -------- 4070918 -------- 4105696 -------- 4136867 -------- 4169475 -------- 4205249 -------- 4239013 -------- 4264423 -------- 4292135 -------- 4324453 -------- 4356356 -------- 4392386 -------- 4423074 -------- 4447335 -------- 4469345 -------- 4496513 -------- 4530848 -------- 4565159 -------- 4596965 -------- 4627011 -------- 4662598 -------- 4690818 -------- 4718691 -------- 4749349 -------- 4782722 -------- 4824485 -------- 4856323 -------- 4885795 -------- 4911142 -------- 4945794 -------- 4972801 -------- 5000583 -------- 5033735 -------- 5072421 -------- 5112929 -------- 5145956 -------- 5181923 -------- 5217478 -------- 5247620 -------- 5273605 -------- 5304100 -------- 5343362 -------- 5375842 -------- 5408391 -------- 5439046 -------- 5464610 -------- 5497857 -------- 5528295 -------- 5557956 -------- 5593474 -------- 5626209 -------- 5660931 -------- 5703463 -------- 5733440 -------- 5762565 -------- 5788034 -------- 5813505 -------- 5848227 -------- 5870727 -------- 5908998 -------- 5938311 -------- 5968930 -------- 5999751 + │ │ │ │ │ │ │ histogram(37)= 0 2.3017e+05 0 1.9693e+05 0 1.6119e+05 0 1.3036e+05 0 1.0268e+05 0 69069 0 35460 + │ │ │ │ │ │ │ <------ 1 ---------- 2 ---------- 3 ---------- 4 ---------- 5 -------- 6 ----- 7 - + │ │ │ │ │ │ │ histogram(44)= 0 0 24928 2400 27605 1800 27605 2400 28205 4800 28205 3000 28205 1800 25205 4200 28805 1800 28205 4200 27005 3600 28205 1800 26405 3600 27605 2400 28805 1200 24004 5401 27005 5401 28205 3600 28205 1200 28805 1800 27005 3600 27605 1800 27005 2400 27605 4200 26405 5401 28205 4200 27605 2400 28205 1800 26405 3000 27005 4200 28805 3000 6901.2 3450.6 + │ │ │ │ │ │ │ <--- '1993-12-31' ------- '1994-01-13' ------- '1994-01-27' ------- '1994-02-06' ------- '1994-02-19' ------- '1994-03-04' ------- '1994-03-17' ------- '1994-03-29' ------- '1994-04-10' ------- '1994-04-22' ------- '1994-05-02' ------- '1994-05-17' ------- '1994-05-27' ------- '1994-06-08' ------- '1994-06-21' ------- '1994-07-04' ------- '1994-07-15' ------- '1994-07-25' ------- '1994-08-09' ------- '1994-08-18' ------- '1994-08-30' ------- '1994-09-14' ------- '1994-09-26' ------- '1994-10-07' ------- '1994-10-20' ------- '1994-10-31' ------- '1994-11-10' ------- '1994-11-22' ------- '1994-12-05' ------- '1994-12-16' ------- '1994-12-28' -------- '1994-12-31' + │ │ │ │ │ │ ├── key: (34,37) + │ │ │ │ │ │ └── fd: (34,37)-->(44) + │ │ │ │ │ ├── scan partsupp + │ │ │ │ │ │ ├── save-table-name: q20_scan_13 + │ │ │ │ │ │ ├── columns: ps_partkey:16(int!null) ps_suppkey:17(int!null) ps_availqty:18(int!null) + │ │ │ │ │ │ ├── stats: [rows=800000, distinct(16)=199241, null(16)=0, distinct(17)=9920, null(17)=0, distinct(18)=9920, null(18)=0, distinct(16,17)=798302, null(16,17)=0] + │ │ │ │ │ │ │ histogram(16)= 0 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3840 160 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3840 160 3920 80 3920 80 3920 160 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 160 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 80 3920 160 3920 80 3920 80 3920 80 3920 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 4000 80 + │ │ │ │ │ │ │ <--- 11 ------ 765 ------ 1954 ------ 3094 ------ 4311 ------ 5377 ------ 6431 ------ 7396 ------ 8288 ------ 9272 ------ 10101 ------ 11159 ------ 12287 ------ 13216 ------ 14316 ------ 15503 ------ 16605 ------ 17726 ------ 18717 ------ 19542 ------ 20537 ------ 21666 ------ 22752 ------ 23971 ------ 24995 ------ 25994 ------ 26842 ------ 27390 ------ 28440 ------ 29526 ------ 30460 ------ 31515 ------ 32312 ------ 33159 ------ 33972 ------ 34884 ------ 35855 ------ 36884 ------ 38010 ------ 39033 ------ 39975 ------ 41212 ------ 42073 ------ 42782 ------ 43708 ------ 44715 ------ 45878 ------ 47111 ------ 48039 ------ 49002 ------ 50120 ------ 51213 ------ 52110 ------ 53025 ------ 53839 ------ 54936 ------ 55856 ------ 56820 ------ 58014 ------ 59079 ------ 59981 ------ 60972 ------ 62028 ------ 63090 ------ 64027 ------ 64909 ------ 65916 ------ 66861 ------ 67912 ------ 68977 ------ 70169 ------ 71156 ------ 72183 ------ 73210 ------ 74218 ------ 75126 ------ 76182 ------ 77201 ------ 78004 ------ 78975 ------ 79993 ------ 80986 ------ 81978 ------ 82761 ------ 83782 ------ 84946 ------ 85946 ------ 86808 ------ 87656 ------ 88587 ------ 89454 ------ 90799 ------ 91730 ------ 92853 ------ 93711 ------ 94565 ------ 95544 ------ 96591 ------ 97578 ------ 98568 ------ 99475 ------ 100626 ------ 101679 ------ 102802 ------ 103800 ------ 104901 ------ 105678 ------ 106420 ------ 107335 ------ 108666 ------ 109855 ------ 110808 ------ 111732 ------ 112497 ------ 113432 ------ 114405 ------ 115440 ------ 116504 ------ 117316 ------ 118321 ------ 119068 ------ 119846 ------ 120926 ------ 122077 ------ 122949 ------ 123943 ------ 124937 ------ 126233 ------ 127250 ------ 128140 ------ 129049 ------ 129887 ------ 130876 ------ 131726 ------ 132511 ------ 133477 ------ 134247 ------ 135281 ------ 136204 ------ 137302 ------ 138754 ------ 140003 ------ 140831 ------ 141666 ------ 142617 ------ 143565 ------ 144737 ------ 145910 ------ 146952 ------ 147912 ------ 148781 ------ 149766 ------ 150631 ------ 151819 ------ 152865 ------ 153895 ------ 154813 ------ 155710 ------ 156815 ------ 157926 ------ 159092 ------ 160005 ------ 161023 ------ 162111 ------ 163183 ------ 164159 ------ 165338 ------ 166253 ------ 167290 ------ 168099 ------ 169524 ------ 170467 ------ 171236 ------ 172225 ------ 173089 ------ 174101 ------ 175241 ------ 176102 ------ 176969 ------ 178074 ------ 178858 ------ 179838 ------ 181097 ------ 182021 ------ 182950 ------ 184039 ------ 184907 ------ 185995 ------ 187520 ------ 188513 ------ 189558 ------ 190767 ------ 192126 ------ 193405 ------ 194495 ------ 195462 ------ 196564 ------ 197793 ------ 198874 ------ 199967 + │ │ │ │ │ │ │ histogram(17)= 0 80 3840 160 3920 80 3840 160 3920 160 3920 80 3840 160 3920 240 3920 80 3920 80 3920 80 3920 240 3920 80 3760 240 3920 80 3920 80 3920 80 3920 80 3920 320 3920 80 3680 320 3920 160 3920 80 3920 80 3840 160 3920 160 3840 160 3920 80 3920 80 3920 80 3920 160 3920 240 3920 80 3840 160 3920 80 3840 240 3920 160 3920 160 3840 160 3920 240 3840 320 3760 240 3840 160 3840 160 3920 240 3920 80 3840 240 3680 480 3920 80 3920 80 3920 80 3920 160 3920 160 3920 80 3920 80 3920 160 3760 320 3840 320 3920 320 3920 80 3920 160 3920 80 3840 160 3840 160 3920 80 3920 80 3920 240 3760 240 3920 160 3920 160 3920 80 3840 160 3920 160 3840 320 3920 80 3920 80 3920 240 3920 160 3920 160 3920 240 3920 80 3920 240 3680 400 3680 320 3840 80 3840 160 3760 240 3840 80 3840 320 3840 160 3840 80 3840 240 3840 80 3840 160 3840 80 3840 240 3760 240 3760 160 3920 80 3840 240 3840 80 3920 80 3920 160 3840 160 3840 80 3760 320 3840 80 3920 80 3920 80 3920 80 3920 320 3840 80 3840 80 3840 160 3760 240 3840 160 3840 80 3920 80 3840 240 3760 160 3840 160 3840 160 3760 240 3760 240 3840 160 3840 160 3920 80 3840 160 3840 160 3840 160 3760 240 3760 240 3920 240 3840 80 3840 80 3920 80 3920 160 3760 160 3840 160 3920 80 3600 480 3760 160 3920 80 3920 80 3840 240 3840 160 3680 240 3680 320 3920 240 3760 160 3840 80 3920 160 3760 320 3840 160 3840 80 3840 80 3920 80 3920 160 3840 320 3760 160 3840 240 3840 80 3760 160 3680 240 3920 160 3840 80 3840 240 3680 240 3920 160 3840 80 3920 160 3760 160 3920 160 3840 80 3760 240 3920 160 3840 80 3920 80 3920 80 3920 80 3920 80 3680 320 3760 240 3920 80 3920 80 3920 160 3760 160 3840 240 3840 160 3840 80 3760 240 3920 80 3600 400 3920 80 3920 80 3840 160 3920 80 3920 160 3600 320 3920 80 + │ │ │ │ │ │ │ <--- 1 ------ 57 ------ 119 ------ 176 ------ 228 ------ 277 ------ 315 ------ 390 ------ 437 ------ 479 ------ 517 ------ 568 ------ 626 ------ 678 ------ 728 ------ 785 ------ 850 ------ 900 ------ 965 ------ 1015 ------ 1056 ------ 1101 ------ 1152 ------ 1194 ------ 1236 ------ 1282 ------ 1331 ------ 1389 ------ 1456 ------ 1505 ------ 1555 ------ 1605 ------ 1650 ------ 1710 ------ 1762 ------ 1806 ------ 1855 ------ 1911 ------ 1959 ------ 2021 ------ 2076 ------ 2120 ------ 2169 ------ 2218 ------ 2284 ------ 2324 ------ 2365 ------ 2412 ------ 2474 ------ 2524 ------ 2568 ------ 2620 ------ 2665 ------ 2719 ------ 2781 ------ 2831 ------ 2884 ------ 2926 ------ 2973 ------ 3012 ------ 3071 ------ 3112 ------ 3158 ------ 3209 ------ 3250 ------ 3313 ------ 3366 ------ 3414 ------ 3463 ------ 3514 ------ 3557 ------ 3608 ------ 3668 ------ 3713 ------ 3777 ------ 3827 ------ 3882 ------ 3938 ------ 3989 ------ 4036 ------ 4084 ------ 4134 ------ 4182 ------ 4231 ------ 4292 ------ 4337 ------ 4382 ------ 4426 ------ 4474 ------ 4521 ------ 4568 ------ 4614 ------ 4651 ------ 4695 ------ 4742 ------ 4800 ------ 4853 ------ 4905 ------ 4954 ------ 4997 ------ 5050 ------ 5115 ------ 5167 ------ 5231 ------ 5276 ------ 5325 ------ 5371 ------ 5419 ------ 5484 ------ 5547 ------ 5586 ------ 5636 ------ 5685 ------ 5744 ------ 5799 ------ 5855 ------ 5894 ------ 5938 ------ 5984 ------ 6038 ------ 6085 ------ 6143 ------ 6196 ------ 6257 ------ 6306 ------ 6350 ------ 6395 ------ 6445 ------ 6497 ------ 6556 ------ 6596 ------ 6636 ------ 6684 ------ 6744 ------ 6799 ------ 6844 ------ 6894 ------ 6947 ------ 6994 ------ 7048 ------ 7104 ------ 7149 ------ 7199 ------ 7248 ------ 7288 ------ 7343 ------ 7391 ------ 7446 ------ 7492 ------ 7538 ------ 7598 ------ 7650 ------ 7702 ------ 7767 ------ 7799 ------ 7849 ------ 7898 ------ 7941 ------ 7989 ------ 8041 ------ 8086 ------ 8127 ------ 8169 ------ 8216 ------ 8263 ------ 8326 ------ 8374 ------ 8413 ------ 8465 ------ 8521 ------ 8579 ------ 8631 ------ 8680 ------ 8732 ------ 8783 ------ 8832 ------ 8888 ------ 8945 ------ 8997 ------ 9052 ------ 9106 ------ 9136 ------ 9193 ------ 9234 ------ 9279 ------ 9326 ------ 9381 ------ 9426 ------ 9471 ------ 9519 ------ 9552 ------ 9609 ------ 9660 ------ 9716 ------ 9762 ------ 9815 ------ 9863 ------ 9910 ------ 9948 ------ 10000 + │ │ │ │ │ │ │ histogram(18)= 0 240 7.9968e+05 80 + │ │ │ │ │ │ │ <--- 2 ------------ 9999 + │ │ │ │ │ │ ├── key: (16,17) + │ │ │ │ │ │ └── fd: (16,17)-->(18) + │ │ │ │ │ └── filters + │ │ │ │ │ ├── l_partkey:35 = ps_partkey:16 [type=bool, outer=(16,35), constraints=(/16: (/NULL - ]; /35: (/NULL - ]), fd=(16)==(35), (35)==(16)] + │ │ │ │ │ └── l_suppkey:36 = ps_suppkey:17 [type=bool, outer=(17,36), constraints=(/17: (/NULL - ]; /36: (/NULL - ]), fd=(17)==(36), (36)==(17)] + │ │ │ │ └── aggregations + │ │ │ │ ├── sum [as=sum:52, type=float, outer=(38)] + │ │ │ │ │ └── l_quantity:38 [type=float] + │ │ │ │ └── const-agg [as=ps_availqty:18, type=int, outer=(18)] + │ │ │ │ └── ps_availqty:18 [type=int] + │ │ │ └── filters + │ │ │ └── ps_availqty:18 > (sum:52 * 0.5) [type=bool, outer=(18,52), immutable, constraints=(/18: (/NULL - ])] + │ │ └── filters + │ │ └── p_name:24 LIKE 'forest%' [type=bool, outer=(24), constraints=(/24: [/'forest' - /'foresu'); tight)] │ └── filters (true) └── filters └── n_name:11 = 'CANADA' [type=bool, outer=(11), constraints=(/11: [/'CANADA' - /'CANADA']; tight), fd=()-->(11)] @@ -260,27 +247,7 @@ column_names row_count distinct_count null_count column_names row_count_est row_count_err distinct_count_est distinct_count_err null_count_est null_count_err {ps_suppkey} 0.00 1.00 0.00 1.00 0.00 1.00 -----Stats for q20_project_7---- -column_names row_count distinct_count null_count -{ps_partkey} 0 0 0 -{ps_suppkey} 0 0 0 -~~~~ -column_names row_count_est row_count_err distinct_count_est distinct_count_err null_count_est null_count_err -{ps_partkey} 0.00 1.00 0.00 1.00 0.00 1.00 -{ps_suppkey} 0.00 1.00 0.00 1.00 0.00 1.00 - -----Stats for q20_project_8---- -column_names row_count distinct_count null_count -{p_partkey} 0 0 0 -{ps_partkey} 0 0 0 -{ps_suppkey} 0 0 0 -~~~~ -column_names row_count_est row_count_err distinct_count_est distinct_count_err null_count_est null_count_err -{p_partkey} 0.00 1.00 0.00 1.00 0.00 1.00 -{ps_partkey} 0.00 1.00 0.00 1.00 0.00 1.00 -{ps_suppkey} 0.00 1.00 0.00 1.00 0.00 1.00 - -----Stats for q20_lookup_join_9---- +----Stats for q20_lookup_join_7---- column_names row_count distinct_count null_count {p_name} 0 0 0 {p_partkey} 0 0 0 @@ -297,7 +264,7 @@ column_names row_count_est row_count_err distinct_count_est distinct_count_ {ps_suppkey} 0.00 1.00 0.00 1.00 0.00 1.00 {sum} 0.00 1.00 0.00 1.00 0.00 1.00 -----Stats for q20_select_10---- +----Stats for q20_select_8---- column_names row_count distinct_count null_count {ps_availqty} 541940 9920 0 {ps_partkey} 541940 197367 0 @@ -310,7 +277,7 @@ column_names row_count_est row_count_err distinct_count_est distinct_count_ {ps_suppkey} 125.00 4335.52 <== 125.00 79.36 <== 0.00 1.00 {sum} 125.00 4335.52 <== 125.00 1.96 <== 0.00 1.00 -----Stats for q20_group_by_11---- +----Stats for q20_group_by_9---- column_names row_count distinct_count null_count {ps_availqty} 543101 9920 0 {ps_partkey} 543101 197437 0 @@ -323,7 +290,7 @@ column_names row_count_est row_count_err distinct_count_est distinct_count_ {ps_suppkey} 375.00 1448.27 <== 375.00 26.45 <== 0.00 1.00 {sum} 375.00 1448.27 <== 375.00 1.52 0.00 1.00 -----Stats for q20_inner_join_12---- +----Stats for q20_inner_join_10---- column_names row_count distinct_count null_count {l_partkey} 909665 197437 0 {l_quantity} 909665 50 0 @@ -342,7 +309,7 @@ column_names row_count_est row_count_err distinct_count_est distinct_count_ {ps_partkey} 375.00 2425.77 <== 375.00 526.50 <== 0.00 1.00 {ps_suppkey} 375.00 2425.77 <== 375.00 26.45 <== 0.00 1.00 -----Stats for q20_index_join_13---- +----Stats for q20_index_join_11---- column_names row_count distinct_count null_count {l_partkey} 909665 197437 0 {l_quantity} 909665 50 0 @@ -355,7 +322,7 @@ column_names row_count_est row_count_err distinct_count_est distinct_count_e {l_shipdate} 925860.00 1.02 365.00 1.00 0.00 1.00 {l_suppkey} 925860.00 1.02 9920.00 1.00 0.00 1.00 -----Stats for q20_scan_14---- +----Stats for q20_scan_12---- column_names row_count distinct_count null_count {l_linenumber} 909665 7 0 {l_orderkey} 909665 266316 0 @@ -366,7 +333,7 @@ column_names row_count_est row_count_err distinct_count_est distinct_count {l_orderkey} 925860.00 1.02 736656.00 2.77 <== 0.00 1.00 {l_shipdate} 925860.00 1.02 365.00 1.00 0.00 1.00 -----Stats for q20_scan_15---- +----Stats for q20_scan_13---- column_names row_count distinct_count null_count {ps_availqty} 800000 9920 0 {ps_partkey} 800000 199241 0 diff --git a/pkg/sql/opt/xform/groupby_funcs.go b/pkg/sql/opt/xform/groupby_funcs.go index 1d89d0810f92..3652965d1c78 100644 --- a/pkg/sql/opt/xform/groupby_funcs.go +++ b/pkg/sql/opt/xform/groupby_funcs.go @@ -266,3 +266,16 @@ func (c *CustomFuncs) GroupingColumns(private *memo.GroupingPrivate) opt.ColSet func (c *CustomFuncs) GroupingOrdering(private *memo.GroupingPrivate) props.OrderingChoice { return private.Ordering } + +// MakeGroupingPrivate constructs a new GroupingPrivate using the given +// grouping columns, OrderingChoice, NullsAreDistinct bool, and ErrorOnDup text. +func (c *CustomFuncs) MakeGroupingPrivate( + groupingCols opt.ColSet, ordering props.OrderingChoice, nullsAreDistinct bool, errorText string, +) *memo.GroupingPrivate { + return &memo.GroupingPrivate{ + GroupingCols: groupingCols, + Ordering: ordering, + NullsAreDistinct: nullsAreDistinct, + ErrorOnDup: errorText, + } +} diff --git a/pkg/sql/opt/xform/rules/groupby.opt b/pkg/sql/opt/xform/rules/groupby.opt index 348a46a7e663..48283ade18ac 100644 --- a/pkg/sql/opt/xform/rules/groupby.opt +++ b/pkg/sql/opt/xform/rules/groupby.opt @@ -212,17 +212,17 @@ => ((OpName) (Select $unionScans $filters) $aggs $private) -# EliminateIndexJoinInsideGroupBy removes an IndexJoin operator if it can be -# proven that the removal does not affect the output of the parent grouping -# operator. This is the case if: +# EliminateIndexJoinOrProjectInsideGroupBy removes an IndexJoin or Project +# operator if it can be proven that the removal does not affect the output of +# the parent grouping operator. This is the case if: # -# 1. Only columns from the index join's input are being used by the grouping -# operator. +# 1. Only columns from the index join/project's input are being used by the +# grouping operator. # # 2. The OrderingChoice of the grouping operator can be expressed with only -# columns from the index join's input. Or in other words, at least one column -# in every ordering group is one of the output columns from the index join's -# input. +# columns from the index join/project's input. Or in other words, at least +# one column in every ordering group is one of the output columns from the +# index join/project's input. # # This rule is useful when using partial indexes. When generating partial index # scans, expressions can be removed from filters because they exactly match @@ -270,22 +270,35 @@ # └── scan t@secondary,partial # └── columns: i:1 rowid:4!null # -[EliminateIndexJoinInsideGroupBy, Explore] +# A Project is created in cases where the partial index predicate constrains +# some columns to be constant, and therefore provides those columns as constant +# projections instead of using an IndexJoin. The Project can be eliminated for +# the same reasons as the IndexJoin. +[EliminateIndexJoinOrProjectInsideGroupBy, Explore] (GroupBy | DistinctOn | EnsureUpsertDistinctOn - (IndexJoin $input:*) + (IndexJoin | Project $input:*) $aggs:* $private:* & (OrderingCanProjectCols - (GroupingOrdering $private) + $ordering:(GroupingOrdering $private) $inputCols:(OutputCols $input) ) & (ColsAreSubset (UnionCols - (GroupingColumns $private) + $groupingCols:(GroupingColumns $private) (AggregationOuterCols $aggs) ) $inputCols ) ) => -((OpName) $input $aggs $private) +((OpName) + $input + $aggs + (MakeGroupingPrivate + $groupingCols + (PruneOrdering $ordering $inputCols) + (NullsAreDistinct $private) + (ErrorOnDup $private) + ) +) diff --git a/pkg/sql/opt/xform/testdata/external/tpch b/pkg/sql/opt/xform/testdata/external/tpch index d90495c5160b..a7c351f42f3b 100644 --- a/pkg/sql/opt/xform/testdata/external/tpch +++ b/pkg/sql/opt/xform/testdata/external/tpch @@ -2186,59 +2186,50 @@ sort │ │ ├── grouping columns: ps_suppkey:17!null │ │ ├── immutable │ │ ├── key: (17) - │ │ └── project - │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null + │ │ └── inner-join (lookup part) + │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null p_partkey:23!null p_name:24!null sum:52!null + │ │ ├── key columns: [16] = [23] + │ │ ├── lookup columns are key │ │ ├── immutable - │ │ ├── key: (16,17) - │ │ └── project - │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null p_partkey:23!null - │ │ ├── immutable - │ │ ├── key: (17,23) - │ │ ├── fd: (16)==(23), (23)==(16) - │ │ └── inner-join (lookup part) - │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null p_partkey:23!null p_name:24!null sum:52!null - │ │ ├── key columns: [16] = [23] - │ │ ├── lookup columns are key - │ │ ├── immutable - │ │ ├── key: (17,23) - │ │ ├── fd: (16,17)-->(18,52), (23)-->(24), (16)==(23), (23)==(16) - │ │ ├── select - │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null sum:52!null - │ │ │ ├── immutable - │ │ │ ├── key: (16,17) - │ │ │ ├── fd: (16,17)-->(18,52) - │ │ │ ├── group-by - │ │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null sum:52!null - │ │ │ │ ├── grouping columns: ps_partkey:16!null ps_suppkey:17!null - │ │ │ │ ├── key: (16,17) - │ │ │ │ ├── fd: (16,17)-->(18,52) - │ │ │ │ ├── inner-join (hash) - │ │ │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null l_partkey:35!null l_suppkey:36!null l_quantity:38!null l_shipdate:44!null - │ │ │ │ │ ├── multiplicity: left-rows(exactly-one), right-rows(zero-or-more) - │ │ │ │ │ ├── fd: (16,17)-->(18), (16)==(35), (35)==(16), (17)==(36), (36)==(17) - │ │ │ │ │ ├── index-join lineitem - │ │ │ │ │ │ ├── columns: l_partkey:35!null l_suppkey:36!null l_quantity:38!null l_shipdate:44!null - │ │ │ │ │ │ └── scan lineitem@l_sd - │ │ │ │ │ │ ├── columns: l_orderkey:34!null l_linenumber:37!null l_shipdate:44!null - │ │ │ │ │ │ ├── constraint: /44/34/37: [/'1994-01-01' - /'1994-12-31'] - │ │ │ │ │ │ ├── key: (34,37) - │ │ │ │ │ │ └── fd: (34,37)-->(44) - │ │ │ │ │ ├── scan partsupp - │ │ │ │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null - │ │ │ │ │ │ ├── key: (16,17) - │ │ │ │ │ │ └── fd: (16,17)-->(18) - │ │ │ │ │ └── filters - │ │ │ │ │ ├── l_partkey:35 = ps_partkey:16 [outer=(16,35), constraints=(/16: (/NULL - ]; /35: (/NULL - ]), fd=(16)==(35), (35)==(16)] - │ │ │ │ │ └── l_suppkey:36 = ps_suppkey:17 [outer=(17,36), constraints=(/17: (/NULL - ]; /36: (/NULL - ]), fd=(17)==(36), (36)==(17)] - │ │ │ │ └── aggregations - │ │ │ │ ├── sum [as=sum:52, outer=(38)] - │ │ │ │ │ └── l_quantity:38 - │ │ │ │ └── const-agg [as=ps_availqty:18, outer=(18)] - │ │ │ │ └── ps_availqty:18 - │ │ │ └── filters - │ │ │ └── ps_availqty:18 > (sum:52 * 0.5) [outer=(18,52), immutable, constraints=(/18: (/NULL - ])] - │ │ └── filters - │ │ └── p_name:24 LIKE 'forest%' [outer=(24), constraints=(/24: [/'forest' - /'foresu'); tight)] + │ │ ├── key: (17,23) + │ │ ├── fd: (16,17)-->(18,52), (23)-->(24), (16)==(23), (23)==(16) + │ │ ├── select + │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null sum:52!null + │ │ │ ├── immutable + │ │ │ ├── key: (16,17) + │ │ │ ├── fd: (16,17)-->(18,52) + │ │ │ ├── group-by + │ │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null sum:52!null + │ │ │ │ ├── grouping columns: ps_partkey:16!null ps_suppkey:17!null + │ │ │ │ ├── key: (16,17) + │ │ │ │ ├── fd: (16,17)-->(18,52) + │ │ │ │ ├── inner-join (hash) + │ │ │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null l_partkey:35!null l_suppkey:36!null l_quantity:38!null l_shipdate:44!null + │ │ │ │ │ ├── multiplicity: left-rows(exactly-one), right-rows(zero-or-more) + │ │ │ │ │ ├── fd: (16,17)-->(18), (16)==(35), (35)==(16), (17)==(36), (36)==(17) + │ │ │ │ │ ├── index-join lineitem + │ │ │ │ │ │ ├── columns: l_partkey:35!null l_suppkey:36!null l_quantity:38!null l_shipdate:44!null + │ │ │ │ │ │ └── scan lineitem@l_sd + │ │ │ │ │ │ ├── columns: l_orderkey:34!null l_linenumber:37!null l_shipdate:44!null + │ │ │ │ │ │ ├── constraint: /44/34/37: [/'1994-01-01' - /'1994-12-31'] + │ │ │ │ │ │ ├── key: (34,37) + │ │ │ │ │ │ └── fd: (34,37)-->(44) + │ │ │ │ │ ├── scan partsupp + │ │ │ │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null + │ │ │ │ │ │ ├── key: (16,17) + │ │ │ │ │ │ └── fd: (16,17)-->(18) + │ │ │ │ │ └── filters + │ │ │ │ │ ├── l_partkey:35 = ps_partkey:16 [outer=(16,35), constraints=(/16: (/NULL - ]; /35: (/NULL - ]), fd=(16)==(35), (35)==(16)] + │ │ │ │ │ └── l_suppkey:36 = ps_suppkey:17 [outer=(17,36), constraints=(/17: (/NULL - ]; /36: (/NULL - ]), fd=(17)==(36), (36)==(17)] + │ │ │ │ └── aggregations + │ │ │ │ ├── sum [as=sum:52, outer=(38)] + │ │ │ │ │ └── l_quantity:38 + │ │ │ │ └── const-agg [as=ps_availqty:18, outer=(18)] + │ │ │ │ └── ps_availqty:18 + │ │ │ └── filters + │ │ │ └── ps_availqty:18 > (sum:52 * 0.5) [outer=(18,52), immutable, constraints=(/18: (/NULL - ])] + │ │ └── filters + │ │ └── p_name:24 LIKE 'forest%' [outer=(24), constraints=(/24: [/'forest' - /'foresu'); tight)] │ └── filters (true) └── filters └── n_name:11 = 'CANADA' [outer=(11), constraints=(/11: [/'CANADA' - /'CANADA']; tight), fd=()-->(11)] diff --git a/pkg/sql/opt/xform/testdata/external/tpch-no-stats b/pkg/sql/opt/xform/testdata/external/tpch-no-stats index c8e544237b8e..1b0bdf712aa9 100644 --- a/pkg/sql/opt/xform/testdata/external/tpch-no-stats +++ b/pkg/sql/opt/xform/testdata/external/tpch-no-stats @@ -420,31 +420,27 @@ sort ├── grouping columns: o_orderpriority:6!null ├── key: (6) ├── fd: (6)-->(30) - ├── project - │ ├── columns: o_orderkey:1!null o_orderdate:5!null o_orderpriority:6!null - │ ├── key: (1) - │ ├── fd: (1)-->(5,6) - │ └── inner-join (lookup orders) - │ ├── columns: o_orderkey:1!null o_orderdate:5!null o_orderpriority:6!null l_orderkey:12!null - │ ├── key columns: [12] = [1] - │ ├── lookup columns are key - │ ├── key: (12) - │ ├── fd: (1)-->(5,6), (1)==(12), (12)==(1) - │ ├── distinct-on - │ │ ├── columns: l_orderkey:12!null - │ │ ├── grouping columns: l_orderkey:12!null - │ │ ├── internal-ordering: +12 - │ │ ├── key: (12) - │ │ └── select - │ │ ├── columns: l_orderkey:12!null l_commitdate:23!null l_receiptdate:24!null - │ │ ├── ordering: +12 - │ │ ├── scan lineitem - │ │ │ ├── columns: l_orderkey:12!null l_commitdate:23!null l_receiptdate:24!null - │ │ │ └── ordering: +12 - │ │ └── filters - │ │ └── l_commitdate:23 < l_receiptdate:24 [outer=(23,24), constraints=(/23: (/NULL - ]; /24: (/NULL - ])] - │ └── filters - │ └── (o_orderdate:5 >= '1993-07-01') AND (o_orderdate:5 < '1993-10-01') [outer=(5), constraints=(/5: [/'1993-07-01' - /'1993-09-30']; tight)] + ├── inner-join (lookup orders) + │ ├── columns: o_orderkey:1!null o_orderdate:5!null o_orderpriority:6!null l_orderkey:12!null + │ ├── key columns: [12] = [1] + │ ├── lookup columns are key + │ ├── key: (12) + │ ├── fd: (1)-->(5,6), (1)==(12), (12)==(1) + │ ├── distinct-on + │ │ ├── columns: l_orderkey:12!null + │ │ ├── grouping columns: l_orderkey:12!null + │ │ ├── internal-ordering: +12 + │ │ ├── key: (12) + │ │ └── select + │ │ ├── columns: l_orderkey:12!null l_commitdate:23!null l_receiptdate:24!null + │ │ ├── ordering: +12 + │ │ ├── scan lineitem + │ │ │ ├── columns: l_orderkey:12!null l_commitdate:23!null l_receiptdate:24!null + │ │ │ └── ordering: +12 + │ │ └── filters + │ │ └── l_commitdate:23 < l_receiptdate:24 [outer=(23,24), constraints=(/23: (/NULL - ]; /24: (/NULL - ])] + │ └── filters + │ └── (o_orderdate:5 >= '1993-07-01') AND (o_orderdate:5 < '1993-10-01') [outer=(5), constraints=(/5: [/'1993-07-01' - /'1993-09-30']; tight)] └── aggregations └── count-rows [as=count_rows:30] @@ -2124,50 +2120,47 @@ sort │ │ ├── grouping columns: ps_suppkey:17!null │ │ ├── immutable │ │ ├── key: (17) - │ │ └── semi-join (lookup part) - │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null + │ │ └── inner-join (lookup part) + │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null p_partkey:23!null p_name:24!null sum:52!null │ │ ├── key columns: [16] = [23] │ │ ├── lookup columns are key │ │ ├── immutable - │ │ ├── key: (16,17) - │ │ ├── project - │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null + │ │ ├── key: (17,23) + │ │ ├── fd: (16,17)-->(18,52), (23)-->(24), (16)==(23), (23)==(16) + │ │ ├── select + │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null sum:52!null │ │ │ ├── immutable │ │ │ ├── key: (16,17) - │ │ │ └── select - │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null sum:52!null - │ │ │ ├── immutable - │ │ │ ├── key: (16,17) - │ │ │ ├── fd: (16,17)-->(18,52) - │ │ │ ├── group-by - │ │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null sum:52!null - │ │ │ │ ├── grouping columns: ps_partkey:16!null ps_suppkey:17!null - │ │ │ │ ├── key: (16,17) - │ │ │ │ ├── fd: (16,17)-->(18,52) - │ │ │ │ ├── inner-join (hash) - │ │ │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null l_partkey:35!null l_suppkey:36!null l_quantity:38!null l_shipdate:44!null - │ │ │ │ │ ├── multiplicity: left-rows(zero-or-more), right-rows(exactly-one) - │ │ │ │ │ ├── fd: (16,17)-->(18), (16)==(35), (35)==(16), (17)==(36), (36)==(17) - │ │ │ │ │ ├── scan partsupp - │ │ │ │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null - │ │ │ │ │ │ ├── key: (16,17) - │ │ │ │ │ │ └── fd: (16,17)-->(18) - │ │ │ │ │ ├── select - │ │ │ │ │ │ ├── columns: l_partkey:35!null l_suppkey:36!null l_quantity:38!null l_shipdate:44!null - │ │ │ │ │ │ ├── scan lineitem - │ │ │ │ │ │ │ └── columns: l_partkey:35!null l_suppkey:36!null l_quantity:38!null l_shipdate:44!null - │ │ │ │ │ │ └── filters - │ │ │ │ │ │ └── (l_shipdate:44 >= '1994-01-01') AND (l_shipdate:44 < '1995-01-01') [outer=(44), constraints=(/44: [/'1994-01-01' - /'1994-12-31']; tight)] - │ │ │ │ │ └── filters - │ │ │ │ │ ├── l_partkey:35 = ps_partkey:16 [outer=(16,35), constraints=(/16: (/NULL - ]; /35: (/NULL - ]), fd=(16)==(35), (35)==(16)] - │ │ │ │ │ └── l_suppkey:36 = ps_suppkey:17 [outer=(17,36), constraints=(/17: (/NULL - ]; /36: (/NULL - ]), fd=(17)==(36), (36)==(17)] - │ │ │ │ └── aggregations - │ │ │ │ ├── sum [as=sum:52, outer=(38)] - │ │ │ │ │ └── l_quantity:38 - │ │ │ │ └── const-agg [as=ps_availqty:18, outer=(18)] - │ │ │ │ └── ps_availqty:18 - │ │ │ └── filters - │ │ │ └── ps_availqty:18 > (sum:52 * 0.5) [outer=(18,52), immutable, constraints=(/18: (/NULL - ])] + │ │ │ ├── fd: (16,17)-->(18,52) + │ │ │ ├── group-by + │ │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null sum:52!null + │ │ │ │ ├── grouping columns: ps_partkey:16!null ps_suppkey:17!null + │ │ │ │ ├── key: (16,17) + │ │ │ │ ├── fd: (16,17)-->(18,52) + │ │ │ │ ├── inner-join (hash) + │ │ │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null l_partkey:35!null l_suppkey:36!null l_quantity:38!null l_shipdate:44!null + │ │ │ │ │ ├── multiplicity: left-rows(zero-or-more), right-rows(exactly-one) + │ │ │ │ │ ├── fd: (16,17)-->(18), (16)==(35), (35)==(16), (17)==(36), (36)==(17) + │ │ │ │ │ ├── scan partsupp + │ │ │ │ │ │ ├── columns: ps_partkey:16!null ps_suppkey:17!null ps_availqty:18!null + │ │ │ │ │ │ ├── key: (16,17) + │ │ │ │ │ │ └── fd: (16,17)-->(18) + │ │ │ │ │ ├── select + │ │ │ │ │ │ ├── columns: l_partkey:35!null l_suppkey:36!null l_quantity:38!null l_shipdate:44!null + │ │ │ │ │ │ ├── scan lineitem + │ │ │ │ │ │ │ └── columns: l_partkey:35!null l_suppkey:36!null l_quantity:38!null l_shipdate:44!null + │ │ │ │ │ │ └── filters + │ │ │ │ │ │ └── (l_shipdate:44 >= '1994-01-01') AND (l_shipdate:44 < '1995-01-01') [outer=(44), constraints=(/44: [/'1994-01-01' - /'1994-12-31']; tight)] + │ │ │ │ │ └── filters + │ │ │ │ │ ├── l_partkey:35 = ps_partkey:16 [outer=(16,35), constraints=(/16: (/NULL - ]; /35: (/NULL - ]), fd=(16)==(35), (35)==(16)] + │ │ │ │ │ └── l_suppkey:36 = ps_suppkey:17 [outer=(17,36), constraints=(/17: (/NULL - ]; /36: (/NULL - ]), fd=(17)==(36), (36)==(17)] + │ │ │ │ └── aggregations + │ │ │ │ ├── sum [as=sum:52, outer=(38)] + │ │ │ │ │ └── l_quantity:38 + │ │ │ │ └── const-agg [as=ps_availqty:18, outer=(18)] + │ │ │ │ └── ps_availqty:18 + │ │ │ └── filters + │ │ │ └── ps_availqty:18 > (sum:52 * 0.5) [outer=(18,52), immutable, constraints=(/18: (/NULL - ])] │ │ └── filters │ │ └── p_name:24 LIKE 'forest%' [outer=(24), constraints=(/24: [/'forest' - /'foresu'); tight)] │ └── filters (true) diff --git a/pkg/sql/opt/xform/testdata/rules/groupby b/pkg/sql/opt/xform/testdata/rules/groupby index 11e30011bdfb..185d92f02cc5 100644 --- a/pkg/sql/opt/xform/testdata/rules/groupby +++ b/pkg/sql/opt/xform/testdata/rules/groupby @@ -1929,7 +1929,8 @@ CREATE TABLE regional ( e INT, UNIQUE (r, a, b) STORING (c), UNIQUE (r, d, e), - UNIQUE INDEX partial_a (r, a) WHERE b > 0 + UNIQUE INDEX partial_a (r, a) WHERE b > 0, + UNIQUE INDEX partial_d (r, d) WHERE e = 1 ) ---- @@ -1957,6 +1958,18 @@ ALTER TABLE regional INJECT STATISTICS '[ {"num_eq": 0, "num_range": 0, "distinct_range": 0, "upper_bound": "0"}, {"num_eq": 1, "num_range": 99999, "distinct_range": 99999, "upper_bound": "100000"} ] + }, + { + "columns": ["d"], + "distinct_count": 100000, + "row_count": 100000, + "created_at": "2018-01-01 1:00:00.00000+00:00" + }, + { + "columns": ["e"], + "distinct_count": 2, + "row_count": 100000, + "created_at": "2018-01-01 1:00:00.00000+00:00" } ]' ---- @@ -2076,7 +2089,7 @@ project # This query mimics the validation query for new partial unique constraints in # REGIONAL BY ROW tables. -opt expect=(SplitGroupByScanIntoUnionScans,EliminateIndexJoinInsideGroupBy) +opt expect=(SplitGroupByScanIntoUnionScans,EliminateIndexJoinOrProjectInsideGroupBy) SELECT a FROM regional WHERE a IS NOT NULL AND b > 0 @@ -2129,6 +2142,57 @@ project │ └── count_rows:10 > 1 [outer=(10), constraints=(/10: [/2 - ]; tight)] └── 1 +# This query mimics the validation query for new partial unique constraints in +# REGIONAL BY ROW tables. +opt expect=(SplitGroupByScanIntoUnionScans,EliminateIndexJoinOrProjectInsideGroupBy) +SELECT d +FROM regional +WHERE d IS NOT NULL AND e = 1 +GROUP BY d +HAVING count(*) > 1 +LIMIT 1 +---- +project + ├── columns: d:5!null + ├── cardinality: [0 - 1] + ├── key: () + ├── fd: ()-->(5) + └── limit + ├── columns: d:5!null count_rows:10!null + ├── cardinality: [0 - 1] + ├── key: () + ├── fd: ()-->(5,10) + ├── select + │ ├── columns: d:5!null count_rows:10!null + │ ├── key: (5) + │ ├── fd: (5)-->(10) + │ ├── limit hint: 1.00 + │ ├── group-by + │ │ ├── columns: d:5!null count_rows:10!null + │ │ ├── grouping columns: d:5!null + │ │ ├── internal-ordering: +5 + │ │ ├── key: (5) + │ │ ├── fd: (5)-->(10) + │ │ ├── limit hint: 3.00 + │ │ ├── union-all + │ │ │ ├── columns: d:5!null + │ │ │ ├── left columns: d:51 + │ │ │ ├── right columns: d:60 + │ │ │ ├── ordering: +5 + │ │ │ ├── scan regional@partial_d,partial + │ │ │ │ ├── columns: d:51!null + │ │ │ │ ├── constraint: /47/51: (/'east'/NULL - /'east'] + │ │ │ │ └── ordering: +51 + │ │ │ └── scan regional@partial_d,partial + │ │ │ ├── columns: d:60!null + │ │ │ ├── constraint: /56/60: (/'west'/NULL - /'west'] + │ │ │ └── ordering: +60 + │ │ └── aggregations + │ │ └── count-rows [as=count_rows:10] + │ └── filters + │ └── count_rows:10 > 1 [outer=(10), constraints=(/10: [/2 - ]; tight)] + └── 1 + # Rule applies for distinct-on. opt expect=SplitGroupByScanIntoUnionScans SELECT DISTINCT a, b @@ -2425,7 +2489,7 @@ group-by └── r:1 # ------------------------------------------------------------------------ -# EliminateIndexJoinInsideGroupBy +# EliminateIndexJoinOrProjectInsideGroupBy # ------------------------------------------------------------------------ exec-ddl @@ -2434,12 +2498,13 @@ CREATE TABLE abcd ( b FLOAT, c INT, d INT, - INDEX partial_ab (a, b) WHERE c > 0 + INDEX partial_ab (a, b) WHERE c > 0, + INDEX partial_cb (c, b) WHERE d = 1 ) ---- # Rule applies for group-by. -opt expect=EliminateIndexJoinInsideGroupBy +opt expect=EliminateIndexJoinOrProjectInsideGroupBy SELECT max(b), a FROM abcd WHERE c > 0 GROUP BY a ---- group-by @@ -2457,8 +2522,24 @@ group-by └── max [as=max:8, outer=(2)] └── b:2 +# Rule applies for group-by. +opt expect=EliminateIndexJoinOrProjectInsideGroupBy +SELECT count(*), c FROM abcd WHERE d = 1 GROUP BY c +---- +group-by + ├── columns: count:8!null c:3 + ├── grouping columns: c:3 + ├── internal-ordering: +3 + ├── key: (3) + ├── fd: (3)-->(8) + ├── scan abcd@partial_cb,partial + │ ├── columns: c:3 + │ └── ordering: +3 + └── aggregations + └── count-rows [as=count_rows:8] + # Rule applies for distinct-on. -opt expect=EliminateIndexJoinInsideGroupBy +opt expect=EliminateIndexJoinOrProjectInsideGroupBy SELECT DISTINCT a, b FROM abcd WHERE c > 0 ---- distinct-on @@ -2472,8 +2553,21 @@ distinct-on ├── fd: (5)-->(1,2) └── ordering: +1,+2 +# Rule applies for distinct-on. +opt expect=EliminateIndexJoinOrProjectInsideGroupBy +SELECT DISTINCT c FROM abcd WHERE d = 1 +---- +distinct-on + ├── columns: c:3 + ├── grouping columns: c:3 + ├── internal-ordering: +3 + ├── key: (3) + └── scan abcd@partial_cb,partial + ├── columns: c:3 + └── ordering: +3 + # Rule applies for ensure-upsert-distinct-on. -opt expect=EliminateIndexJoinInsideGroupBy +opt expect=EliminateIndexJoinOrProjectInsideGroupBy INSERT INTO xyz SELECT a, a, b FROM abcd WHERE c > 0 ON CONFLICT (x) DO UPDATE SET z=2.0 ---- upsert xyz @@ -2523,8 +2617,52 @@ upsert xyz └── projections └── CASE WHEN x:13 IS NULL THEN b:7 ELSE 2.0 END [as=upsert_z:21, outer=(7,13)] +# Rule applies for ensure-upsert-distinct-on. +opt expect=EliminateIndexJoinOrProjectInsideGroupBy +INSERT INTO xyz SELECT c, c, b FROM abcd WHERE d = 1 ON CONFLICT (x) DO UPDATE SET z=2.0 +---- +upsert xyz + ├── columns: + ├── arbiter indexes: primary + ├── canary column: x:13 + ├── fetch columns: x:13 y:14 z:15 + ├── insert-mapping: + │ ├── c:8 => x:1 + │ ├── c:8 => y:2 + │ └── b:7 => z:3 + ├── update-mapping: + │ └── upsert_z:21 => z:3 + ├── cardinality: [0 - 0] + ├── volatile, mutations + └── project + ├── columns: upsert_z:21 b:7 c:8 x:13 y:14 z:15 + ├── lax-key: (8,13) + ├── fd: (8)~~>(7), (13)-->(14,15), (8,13)~~>(7,21) + ├── left-join (lookup xyz) + │ ├── columns: b:7 c:8 x:13 y:14 z:15 + │ ├── key columns: [8] = [13] + │ ├── lookup columns are key + │ ├── lax-key: (8,13) + │ ├── fd: (8)~~>(7), (13)-->(14,15) + │ ├── ensure-upsert-distinct-on + │ │ ├── columns: b:7 c:8 + │ │ ├── grouping columns: c:8 + │ │ ├── internal-ordering: +8 + │ │ ├── error: "UPSERT or INSERT...ON CONFLICT command cannot affect row a second time" + │ │ ├── lax-key: (8) + │ │ ├── fd: (8)~~>(7) + │ │ ├── scan abcd@partial_cb,partial + │ │ │ ├── columns: b:7 c:8 + │ │ │ └── ordering: +8 + │ │ └── aggregations + │ │ └── first-agg [as=b:7, outer=(7)] + │ │ └── b:7 + │ └── filters (true) + └── projections + └── CASE WHEN x:13 IS NULL THEN b:7 ELSE 2.0 END [as=upsert_z:21, outer=(7,13)] + # Rule does not apply because c is used as a grouping column. -opt expect-not=EliminateIndexJoinInsideGroupBy +opt expect-not=EliminateIndexJoinOrProjectInsideGroupBy SELECT max(b), c FROM abcd WHERE c > 0 GROUP BY c ---- group-by @@ -2537,16 +2675,38 @@ group-by │ ├── scan abcd │ │ ├── columns: b:2 c:3 │ │ └── partial index predicates - │ │ └── partial_ab: filters - │ │ └── c:3 > 0 [outer=(3), constraints=(/3: [/1 - ]; tight)] + │ │ ├── partial_ab: filters + │ │ │ └── c:3 > 0 [outer=(3), constraints=(/3: [/1 - ]; tight)] + │ │ └── partial_cb: filters + │ │ └── d:4 = 1 [outer=(4), constraints=(/4: [/1 - /1]; tight), fd=()-->(4)] │ └── filters │ └── c:3 > 0 [outer=(3), constraints=(/3: [/1 - ]; tight)] └── aggregations └── max [as=max:8, outer=(2)] └── b:2 +# Rule does not apply because d is used as a grouping column. +opt expect-not=EliminateIndexJoinOrProjectInsideGroupBy +SELECT count(*), d FROM abcd WHERE d = 1 GROUP BY d +---- +group-by + ├── columns: count:8!null d:4!null + ├── cardinality: [0 - 1] + ├── key: () + ├── fd: ()-->(4,8) + ├── project + │ ├── columns: d:4!null + │ ├── fd: ()-->(4) + │ ├── scan abcd@partial_cb,partial + │ └── projections + │ └── 1 [as=d:4] + └── aggregations + ├── count-rows [as=count_rows:8] + └── const-agg [as=d:4, outer=(4)] + └── d:4 + # Rule does not apply because c is used in an aggregate. -opt expect-not=EliminateIndexJoinInsideGroupBy +opt expect-not=EliminateIndexJoinOrProjectInsideGroupBy SELECT max(c), a FROM abcd WHERE c > 0 GROUP BY a ---- group-by @@ -2559,16 +2719,41 @@ group-by │ ├── scan abcd │ │ ├── columns: a:1 c:3 │ │ └── partial index predicates - │ │ └── partial_ab: filters - │ │ └── c:3 > 0 [outer=(3), constraints=(/3: [/1 - ]; tight)] + │ │ ├── partial_ab: filters + │ │ │ └── c:3 > 0 [outer=(3), constraints=(/3: [/1 - ]; tight)] + │ │ └── partial_cb: filters + │ │ └── d:4 = 1 [outer=(4), constraints=(/4: [/1 - /1]; tight), fd=()-->(4)] │ └── filters │ └── c:3 > 0 [outer=(3), constraints=(/3: [/1 - ]; tight)] └── aggregations └── max [as=max:8, outer=(3)] └── c:3 +# Rule does not apply because d is used in an aggregate. +opt expect-not=EliminateIndexJoinOrProjectInsideGroupBy +SELECT max(d), c FROM abcd WHERE d = 1 GROUP BY c +---- +group-by + ├── columns: max:8!null c:3 + ├── grouping columns: c:3 + ├── internal-ordering: +3 opt(4) + ├── key: (3) + ├── fd: (3)-->(8) + ├── project + │ ├── columns: d:4!null c:3 + │ ├── fd: ()-->(4) + │ ├── ordering: +3 opt(4) [actual: +3] + │ ├── scan abcd@partial_cb,partial + │ │ ├── columns: c:3 + │ │ └── ordering: +3 + │ └── projections + │ └── 1 [as=d:4] + └── aggregations + └── max [as=max:8, outer=(4)] + └── d:4 + # Rule does not apply because c is needed for the ordering of array_agg. -opt expect-not=EliminateIndexJoinInsideGroupBy +opt expect-not=EliminateIndexJoinOrProjectInsideGroupBy SELECT a, array_agg(b) FROM (SELECT a, b FROM abcd WHERE c > 0 ORDER BY c) GROUP BY a @@ -2587,8 +2772,10 @@ group-by │ ├── scan abcd │ │ ├── columns: a:1 b:2 c:3 │ │ └── partial index predicates - │ │ └── partial_ab: filters - │ │ └── c:3 > 0 [outer=(3), constraints=(/3: [/1 - ]; tight)] + │ │ ├── partial_ab: filters + │ │ │ └── c:3 > 0 [outer=(3), constraints=(/3: [/1 - ]; tight)] + │ │ └── partial_cb: filters + │ │ └── d:4 = 1 [outer=(4), constraints=(/4: [/1 - /1]; tight), fd=()-->(4)] │ └── filters │ └── c:3 > 0 [outer=(3), constraints=(/3: [/1 - ]; tight)] └── aggregations