From f5b3d4fc226f70f46c3a3f41818b523f0e630874 Mon Sep 17 00:00:00 2001 From: Drew Kimball Date: Fri, 7 Aug 2020 17:40:38 -0700 Subject: [PATCH] opt: pull join commutation logic into join_order_builder.go Previously, inner joins and full joins were commuted by the CommuteJoin rule. This PR brings commutation into the addJoin function of JoinOrderBuilder, so that joins can be commuted at the same time as they are reordered. Note that CommuteLeftJoin remains because commuting a left join requires a change in the type of join operator. Also note that setting ReorderJoinsLimit to 0 now disallows commutation, while setting ReorderJoinsLimit to 1 allows commutation, but no other reordering. Release note: None --- pkg/sql/opt/memo/testdata/logprops/join | 24 +- .../opt/memo/testdata/stats_quality/tpch/q20 | 262 +++++++------ pkg/sql/opt/norm/testdata/rules/combo | 14 +- .../opttester/testdata/explore-trace | 75 +++- pkg/sql/opt/xform/custom_funcs.go | 38 +- pkg/sql/opt/xform/join_order_builder.go | 27 +- pkg/sql/opt/xform/rules/join.opt | 18 +- .../opt/xform/testdata/external/tpce-no-stats | 52 +-- pkg/sql/opt/xform/testdata/external/tpch | 158 ++++---- .../opt/xform/testdata/external/tpch-no-stats | 172 ++++----- pkg/sql/opt/xform/testdata/rules/combo | 34 -- pkg/sql/opt/xform/testdata/rules/join | 267 +++++++++++-- pkg/sql/opt/xform/testdata/rules/join_order | 361 +++++++++++++----- pkg/sql/opt/xform/testdata/rules/stats | 5 +- 14 files changed, 951 insertions(+), 556 deletions(-) diff --git a/pkg/sql/opt/memo/testdata/logprops/join b/pkg/sql/opt/memo/testdata/logprops/join index de54ad3ce57a..12a1e59b1fcf 100644 --- a/pkg/sql/opt/memo/testdata/logprops/join +++ b/pkg/sql/opt/memo/testdata/logprops/join @@ -2465,18 +2465,28 @@ limit ├── interesting orderings: (+6) (+8) (+10) (+14) ├── inner-join (hash) │ ├── columns: t_st_id:1(int!null) t_tt_id:2(int!null) t_s_symb:3(int!null) st_id:6(int!null) tt_id:8(int!null) s_symb:10(int!null) s_st_id:11(int!null) s_ex_id:12(int!null) ex_id:14(int!null) - │ ├── multiplicity: left-rows(zero-or-more), right-rows(zero-or-one) + │ ├── multiplicity: left-rows(zero-or-one), right-rows(zero-or-more) │ ├── fd: (10)-->(11,12), (12)==(14), (14)==(12), (1)==(6), (6)==(1), (2)==(8), (8)==(2), (3)==(10), (10)==(3) │ ├── limit hint: 50.00 │ ├── prune: (11) │ ├── interesting orderings: (+6) (+8) (+10) (+14) + │ ├── scan trade + │ │ ├── columns: t_st_id:1(int!null) t_tt_id:2(int!null) t_s_symb:3(int!null) + │ │ ├── prune: (1-3) + │ │ └── unfiltered-cols: (1-5) │ ├── inner-join (cross) │ │ ├── columns: st_id:6(int!null) tt_id:8(int!null) s_symb:10(int!null) s_st_id:11(int!null) s_ex_id:12(int!null) ex_id:14(int!null) - │ │ ├── multiplicity: left-rows(one-or-more), right-rows(zero-or-more) + │ │ ├── multiplicity: left-rows(zero-or-more), right-rows(one-or-more) │ │ ├── key: (6,8,10) │ │ ├── fd: (10)-->(11,12), (12)==(14), (14)==(12) │ │ ├── prune: (6,8,10,11) │ │ ├── interesting orderings: (+6) (+8) (+10) (+14) + │ │ ├── scan status_type + │ │ │ ├── columns: st_id:6(int!null) + │ │ │ ├── key: (6) + │ │ │ ├── prune: (6) + │ │ │ ├── interesting orderings: (+6) + │ │ │ └── unfiltered-cols: (6,7) │ │ ├── inner-join (cross) │ │ │ ├── columns: tt_id:8(int!null) s_symb:10(int!null) s_st_id:11(int!null) s_ex_id:12(int!null) ex_id:14(int!null) │ │ │ ├── key: (8,10) @@ -2515,17 +2525,7 @@ limit │ │ │ │ ├── variable: ex_id:14 [type=int] │ │ │ │ └── variable: s_ex_id:12 [type=int] │ │ │ └── filters (true) - │ │ ├── scan status_type - │ │ │ ├── columns: st_id:6(int!null) - │ │ │ ├── key: (6) - │ │ │ ├── prune: (6) - │ │ │ ├── interesting orderings: (+6) - │ │ │ └── unfiltered-cols: (6,7) │ │ └── filters (true) - │ ├── scan trade - │ │ ├── columns: t_st_id:1(int!null) t_tt_id:2(int!null) t_s_symb:3(int!null) - │ │ ├── prune: (1-3) - │ │ └── unfiltered-cols: (1-5) │ └── filters │ ├── eq [type=bool, outer=(1,6), constraints=(/1: (/NULL - ]; /6: (/NULL - ]), fd=(1)==(6), (6)==(1)] │ │ ├── variable: st_id:6 [type=int] diff --git a/pkg/sql/opt/memo/testdata/stats_quality/tpch/q20 b/pkg/sql/opt/memo/testdata/stats_quality/tpch/q20 index dc0d8e175097..fae2b3f9e38c 100644 --- a/pkg/sql/opt/memo/testdata/stats_quality/tpch/q20 +++ b/pkg/sql/opt/memo/testdata/stats_quality/tpch/q20 @@ -69,129 +69,129 @@ sort ├── columns: s_name:2(char!null) s_address:3(varchar!null) ├── immutable ├── stats: [rows=5.13396896, distinct(2)=5.13396829, null(2)=0, distinct(3)=5.13396896, null(3)=0] - └── project - ├── save-table-name: q20_project_3 + └── inner-join (hash) + ├── save-table-name: q20_inner_join_3 ├── columns: s_suppkey:1(int!null) s_name:2(char!null) s_address:3(varchar!null) s_nationkey:4(int!null) n_nationkey:9(int!null) n_name:10(char!null) + ├── multiplicity: left-rows(zero-or-one), right-rows(zero-or-more) ├── immutable ├── stats: [rows=5.13396896, distinct(1)=5.13312469, null(1)=0, distinct(2)=5.13396829, null(2)=0, distinct(3)=5.13396896, null(3)=0, distinct(4)=1, null(4)=0, distinct(9)=1, null(9)=0, distinct(10)=0.994700339, null(10)=0] ├── key: (1) ├── fd: ()-->(10), (1)-->(2-4), (4)==(9), (9)==(4) - └── inner-join (hash) - ├── save-table-name: q20_inner_join_4 - ├── columns: s_suppkey:1(int!null) s_name:2(char!null) s_address:3(varchar!null) s_nationkey:4(int!null) n_nationkey:9(int!null) n_name:10(char!null) ps_suppkey:15(int!null) - ├── multiplicity: left-rows(zero-or-one), right-rows(zero-or-more) - ├── immutable - ├── stats: [rows=126.594795, distinct(1)=126.574101, null(1)=0, distinct(2)=108.633373, null(2)=0, distinct(3)=108.633704, null(3)=0, distinct(4)=1, null(4)=0, distinct(9)=1, null(9)=0, distinct(10)=1, null(10)=0, distinct(15)=126.574101, null(15)=0] - ├── key: (15) - ├── fd: ()-->(10), (1)-->(2-4), (4)==(9), (9)==(4), (1)==(15), (15)==(1) - ├── inner-join (lookup supplier) - │ ├── save-table-name: q20_lookup_join_5 - │ ├── columns: s_suppkey:1(int!null) s_name:2(char!null) s_address:3(varchar!null) s_nationkey:4(int!null) ps_suppkey:15(int!null) - │ ├── key columns: [15] = [1] - │ ├── lookup columns are key - │ ├── immutable - │ ├── stats: [rows=127.59486, distinct(1)=126.574101, null(1)=0, distinct(2)=126.789831, null(2)=0, distinct(3)=126.790639, null(3)=0, distinct(4)=24.8481976, null(4)=0, distinct(15)=126.574101, null(15)=0] - │ ├── key: (15) - │ ├── fd: (1)-->(2-4), (1)==(15), (15)==(1) - │ ├── distinct-on - │ │ ├── save-table-name: q20_distinct_on_6 - │ │ ├── columns: ps_suppkey:15(int!null) - │ │ ├── grouping columns: ps_suppkey:15(int!null) - │ │ ├── immutable - │ │ ├── stats: [rows=126.574101, distinct(15)=126.574101, null(15)=0] - │ │ ├── key: (15) - │ │ └── semi-join (lookup part) - │ │ ├── save-table-name: q20_lookup_join_7 - │ │ ├── columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) - │ │ ├── key columns: [14] = [20] - │ │ ├── lookup columns are key - │ │ ├── immutable - │ │ ├── stats: [rows=126.574101, distinct(14)=126.574101, null(14)=0, distinct(15)=126.574101, null(15)=0] - │ │ ├── key: (14,15) - │ │ ├── project - │ │ │ ├── save-table-name: q20_project_8 - │ │ │ ├── columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) - │ │ │ ├── immutable - │ │ │ ├── stats: [rows=126.574101, distinct(14)=126.574101, null(14)=0, distinct(15)=126.574101, null(15)=0] - │ │ │ ├── key: (14,15) - │ │ │ └── select - │ │ │ ├── save-table-name: q20_select_9 - │ │ │ ├── columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) ps_availqty:16(int!null) sum:47(float!null) - │ │ │ ├── immutable - │ │ │ ├── stats: [rows=126.574101, distinct(14)=126.574101, null(14)=0, distinct(15)=126.574101, null(15)=0, distinct(16)=126.574101, null(16)=0, distinct(47)=126.574101, null(47)=0] - │ │ │ ├── key: (14,15) - │ │ │ ├── fd: (14,15)-->(16,47) - │ │ │ ├── group-by - │ │ │ │ ├── save-table-name: q20_group_by_10 - │ │ │ │ ├── columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) ps_availqty:16(int!null) sum:47(float!null) - │ │ │ │ ├── grouping columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) - │ │ │ │ ├── stats: [rows=379.722303, distinct(14)=379.722303, null(14)=0, distinct(15)=379.722303, null(15)=0, distinct(16)=379.722303, null(16)=0, distinct(47)=379.722303, null(47)=0, distinct(14,15)=379.722303, null(14,15)=0] - │ │ │ │ ├── key: (14,15) - │ │ │ │ ├── fd: (14,15)-->(16,47) - │ │ │ │ ├── inner-join (hash) - │ │ │ │ │ ├── save-table-name: q20_inner_join_11 - │ │ │ │ │ ├── columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) ps_availqty:16(int!null) l_partkey:31(int!null) l_suppkey:32(int!null) l_quantity:34(float!null) l_shipdate:40(date!null) - │ │ │ │ │ ├── multiplicity: left-rows(exactly-one), right-rows(zero-or-more) - │ │ │ │ │ ├── stats: [rows=379.722303, distinct(14)=379.722303, null(14)=0, distinct(15)=379.722303, null(15)=0, distinct(16)=372.546594, null(16)=0, distinct(31)=379.722303, null(31)=0, distinct(32)=379.722303, null(32)=0, distinct(34)=49.9748381, null(34)=0, distinct(40)=236.032274, null(40)=0, distinct(14,15)=379.722303, null(14,15)=0] - │ │ │ │ │ ├── fd: (14,15)-->(16), (14)==(31), (31)==(14), (15)==(32), (32)==(15) - │ │ │ │ │ ├── index-join lineitem - │ │ │ │ │ │ ├── save-table-name: q20_index_join_12 - │ │ │ │ │ │ ├── columns: l_partkey:31(int!null) l_suppkey:32(int!null) l_quantity:34(float!null) l_shipdate:40(date!null) - │ │ │ │ │ │ ├── stats: [rows=938137.516, distinct(31)=198050.435, null(31)=0, distinct(32)=9920, null(32)=0, distinct(34)=50, null(34)=0, distinct(40)=365, null(40)=0] - │ │ │ │ │ │ │ histogram(40)= 0 0 3150.6 4200 25805 3600 25805 3600 26405 3600 28805 1200 27605 2400 27005 3600 28805 1200 27005 4800 28205 3000 25205 4800 28805 4800 28805 600 28205 1200 24604 6601 24604 4800 28205 3600 27605 3600 27005 4200 28205 2400 28205 4200 28805 1200 28205 1800 28205 1200 28205 3000 27005 4800 28805 600 27005 3600 25805 5401 27005 2400 28205 3000 11502 2300.4 - │ │ │ │ │ │ │ <--- '1993-12-31' -------- '1994-01-02' ------- '1994-01-16' ------- '1994-01-30' ------- '1994-02-08' ------- '1994-02-18' ------- '1994-03-04' ------- '1994-03-15' ------- '1994-03-29' ------- '1994-04-10' ------- '1994-04-24' ------- '1994-05-03' ------- '1994-05-13' ------- '1994-05-24' ------- '1994-06-04' ------- '1994-06-13' ------- '1994-06-22' ------- '1994-07-05' ------- '1994-07-16' ------- '1994-07-29' ------- '1994-08-09' ------- '1994-08-22' ------- '1994-09-04' ------- '1994-09-15' ------- '1994-09-29' ------- '1994-10-10' ------- '1994-10-20' ------- '1994-11-03' ------- '1994-11-16' ------- '1994-11-29' ------- '1994-12-11' ------- '1994-12-25' ------- '1994-12-31' - │ │ │ │ │ │ └── scan lineitem@l_sd - │ │ │ │ │ │ ├── save-table-name: q20_scan_13 - │ │ │ │ │ │ ├── columns: l_orderkey:30(int!null) l_linenumber:33(int!null) l_shipdate:40(date!null) - │ │ │ │ │ │ ├── constraint: /40/30/33: [/'1994-01-01' - /'1994-12-31'] - │ │ │ │ │ │ ├── stats: [rows=938137.516, distinct(30)=744144.6, null(30)=0, distinct(33)=7, null(33)=0, distinct(40)=365, null(40)=0] - │ │ │ │ │ │ │ histogram(30)= 0 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 - │ │ │ │ │ │ │ <--- 326 --------- 28929 -------- 50503 -------- 89793 -------- 115938 -------- 146944 -------- 176768 -------- 211201 -------- 237860 -------- 266885 -------- 297604 -------- 330021 -------- 365889 -------- 398951 -------- 426117 -------- 451328 -------- 472134 -------- 499590 -------- 529284 -------- 557254 -------- 589154 -------- 619394 -------- 642951 -------- 670113 -------- 692931 -------- 721157 -------- 751687 -------- 777766 -------- 804582 -------- 836740 -------- 868868 -------- 898912 -------- 922500 -------- 946403 -------- 984870 -------- 1007936 -------- 1030117 -------- 1062275 -------- 1093572 -------- 1120709 -------- 1150981 -------- 1182786 -------- 1206406 -------- 1234116 -------- 1260961 -------- 1290502 -------- 1329510 -------- 1355426 -------- 1381313 -------- 1409796 -------- 1445254 -------- 1479233 -------- 1504935 -------- 1531079 -------- 1559650 -------- 1583616 -------- 1617504 -------- 1655749 -------- 1685185 -------- 1718183 -------- 1747716 -------- 1772131 -------- 1802372 -------- 1833315 -------- 1862403 -------- 1897894 -------- 1922819 -------- 1954405 -------- 1979329 -------- 2009859 -------- 2041670 -------- 2070851 -------- 2093828 -------- 2127973 -------- 2167777 -------- 2194883 -------- 2227814 -------- 2262437 -------- 2296353 -------- 2321024 -------- 2346051 -------- 2376257 -------- 2404932 -------- 2446273 -------- 2474081 -------- 2504515 -------- 2535302 -------- 2561413 -------- 2592737 -------- 2616801 -------- 2646112 -------- 2676546 -------- 2702116 -------- 2732454 -------- 2765382 -------- 2799495 -------- 2828866 -------- 2868737 -------- 2910625 -------- 2938464 -------- 2963140 -------- 3003302 -------- 3043264 -------- 3069123 -------- 3095909 -------- 3126693 -------- 3160485 -------- 3196039 -------- 3229504 -------- 3259712 -------- 3286439 -------- 3318852 -------- 3346821 -------- 3370119 -------- 3395204 -------- 3425888 -------- 3448611 -------- 3476130 -------- 3502372 -------- 3529474 -------- 3556390 -------- 3583553 -------- 3612550 -------- 3647875 -------- 3679140 -------- 3702661 -------- 3738017 -------- 3778050 -------- 3806114 -------- 3839074 -------- 3872805 -------- 3905697 -------- 3926212 -------- 3959841 -------- 3997281 -------- 4033861 -------- 4063591 -------- 4097831 -------- 4124807 -------- 4158656 -------- 4195748 -------- 4234274 -------- 4269952 -------- 4298949 -------- 4332806 -------- 4364705 -------- 4398246 -------- 4430695 -------- 4466403 -------- 4494662 -------- 4524420 -------- 4558561 -------- 4601092 -------- 4632871 -------- 4658694 -------- 4690501 -------- 4728066 -------- 4758657 -------- 4788294 -------- 4818597 -------- 4855874 -------- 4890913 -------- 4915366 -------- 4940709 -------- 4972357 -------- 4995298 -------- 5019523 -------- 5043329 -------- 5077376 -------- 5109920 -------- 5136582 -------- 5161152 -------- 5191846 -------- 5219973 -------- 5251015 -------- 5282021 -------- 5312355 -------- 5343207 -------- 5381318 -------- 5416163 -------- 5445382 -------- 5476933 -------- 5509185 -------- 5539237 -------- 5566818 -------- 5588739 -------- 5620481 -------- 5644001 -------- 5667010 -------- 5689476 -------- 5724709 -------- 5755398 -------- 5790598 -------- 5819425 -------- 5846341 -------- 5874656 -------- 5908067 -------- 5933572 -------- 5962659 -------- 5999971 - │ │ │ │ │ │ │ histogram(40)= 0 0 3150.6 4200 25805 3600 25805 3600 26405 3600 28805 1200 27605 2400 27005 3600 28805 1200 27005 4800 28205 3000 25205 4800 28805 4800 28805 600 28205 1200 24604 6601 24604 4800 28205 3600 27605 3600 27005 4200 28205 2400 28205 4200 28805 1200 28205 1800 28205 1200 28205 3000 27005 4800 28805 600 27005 3600 25805 5401 27005 2400 28205 3000 11502 2300.4 - │ │ │ │ │ │ │ <--- '1993-12-31' -------- '1994-01-02' ------- '1994-01-16' ------- '1994-01-30' ------- '1994-02-08' ------- '1994-02-18' ------- '1994-03-04' ------- '1994-03-15' ------- '1994-03-29' ------- '1994-04-10' ------- '1994-04-24' ------- '1994-05-03' ------- '1994-05-13' ------- '1994-05-24' ------- '1994-06-04' ------- '1994-06-13' ------- '1994-06-22' ------- '1994-07-05' ------- '1994-07-16' ------- '1994-07-29' ------- '1994-08-09' ------- '1994-08-22' ------- '1994-09-04' ------- '1994-09-15' ------- '1994-09-29' ------- '1994-10-10' ------- '1994-10-20' ------- '1994-11-03' ------- '1994-11-16' ------- '1994-11-29' ------- '1994-12-11' ------- '1994-12-25' ------- '1994-12-31' - │ │ │ │ │ │ ├── key: (30,33) - │ │ │ │ │ │ └── fd: (30,33)-->(40) - │ │ │ │ │ ├── scan partsupp - │ │ │ │ │ │ ├── save-table-name: q20_scan_14 - │ │ │ │ │ │ ├── columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) ps_availqty:16(int!null) - │ │ │ │ │ │ ├── stats: [rows=800000, distinct(14)=199241, null(14)=0, distinct(15)=9920, null(15)=0, distinct(16)=9920, null(16)=0, distinct(14,15)=798302, null(14,15)=0] - │ │ │ │ │ │ │ histogram(14)= 0 80 3920 80 3920 80 3920 80 3920 80 3840 160 3840 160 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 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 160 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 160 3920 80 3920 80 3920 80 3920 80 3920 80 3920 160 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 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 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 3920 160 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 - │ │ │ │ │ │ │ <--- 4 ------ 793 ------ 1856 ------ 2808 ------ 3809 ------ 4923 ------ 5975 ------ 6944 ------ 8085 ------ 8945 ------ 9831 ------ 10952 ------ 11932 ------ 12775 ------ 13849 ------ 14925 ------ 16016 ------ 16828 ------ 17768 ------ 18705 ------ 19631 ------ 20600 ------ 21491 ------ 22254 ------ 23327 ------ 24491 ------ 25470 ------ 26331 ------ 27327 ------ 28308 ------ 29359 ------ 30542 ------ 31592 ------ 32495 ------ 33408 ------ 34624 ------ 35726 ------ 36676 ------ 37637 ------ 38485 ------ 39368 ------ 40372 ------ 41034 ------ 42185 ------ 43333 ------ 44466 ------ 45440 ------ 46571 ------ 47469 ------ 48346 ------ 49379 ------ 50571 ------ 51830 ------ 52967 ------ 53673 ------ 54656 ------ 55504 ------ 56539 ------ 57393 ------ 58366 ------ 59577 ------ 60559 ------ 61676 ------ 62471 ------ 63421 ------ 64449 ------ 65409 ------ 66254 ------ 67127 ------ 68127 ------ 69177 ------ 70183 ------ 71209 ------ 72101 ------ 73102 ------ 73994 ------ 74899 ------ 76016 ------ 77098 ------ 77842 ------ 79137 ------ 80242 ------ 81364 ------ 82331 ------ 83158 ------ 84283 ------ 85282 ------ 86437 ------ 87450 ------ 88419 ------ 89493 ------ 90478 ------ 91468 ------ 92552 ------ 93200 ------ 94191 ------ 95067 ------ 96272 ------ 97228 ------ 98126 ------ 99198 ------ 100219 ------ 101057 ------ 102038 ------ 102775 ------ 103711 ------ 104623 ------ 105710 ------ 106734 ------ 107932 ------ 109255 ------ 110220 ------ 111235 ------ 112174 ------ 113260 ------ 114081 ------ 115103 ------ 115864 ------ 116794 ------ 117741 ------ 118712 ------ 119470 ------ 120528 ------ 121572 ------ 122536 ------ 123629 ------ 124404 ------ 125301 ------ 126257 ------ 127139 ------ 128267 ------ 129258 ------ 130442 ------ 131845 ------ 133164 ------ 134005 ------ 135076 ------ 135868 ------ 137297 ------ 138777 ------ 139806 ------ 140741 ------ 141896 ------ 142719 ------ 143727 ------ 144645 ------ 145510 ------ 146507 ------ 147449 ------ 148467 ------ 149635 ------ 150563 ------ 151751 ------ 152613 ------ 153416 ------ 154612 ------ 155853 ------ 156866 ------ 158311 ------ 159230 ------ 160390 ------ 161455 ------ 162555 ------ 163435 ------ 164549 ------ 165663 ------ 166891 ------ 167757 ------ 168732 ------ 169644 ------ 170532 ------ 171671 ------ 172778 ------ 173599 ------ 174321 ------ 175624 ------ 176663 ------ 177632 ------ 178555 ------ 179551 ------ 180510 ------ 181682 ------ 182648 ------ 183408 ------ 184543 ------ 185722 ------ 186713 ------ 187787 ------ 188730 ------ 189604 ------ 190711 ------ 191690 ------ 192692 ------ 193702 ------ 194685 ------ 195725 ------ 196730 ------ 197724 ------ 198701 ------ 199973 - │ │ │ │ │ │ │ histogram(15)= 0 80 3920 240 3920 80 3920 160 3920 80 3920 240 3920 80 3760 320 3680 320 3920 80 3920 160 3920 240 3920 80 3920 160 3840 160 3920 80 3920 80 3760 240 3840 160 3920 80 3840 160 3680 320 3920 80 3840 160 3840 160 3760 320 3840 160 3840 160 3920 80 3840 240 3920 80 3920 80 3840 160 3760 240 3920 160 3920 80 3920 80 3920 80 3920 320 3920 80 3920 160 3840 400 3760 240 3920 160 3920 160 3600 480 3920 80 3680 320 3840 160 3840 160 3920 240 3840 160 3920 160 3920 80 3920 160 3920 80 3760 240 3920 80 3920 80 3840 320 3840 160 3840 160 3920 240 3840 480 3920 160 3840 240 3920 160 3920 160 3920 80 3840 160 3920 80 3920 80 3920 80 3920 80 3840 240 3840 240 3920 80 3840 320 3920 80 3920 80 3920 240 3840 240 3920 160 3920 80 3840 160 3840 240 3920 240 3840 80 3680 320 3920 160 3840 160 3840 80 3920 80 3840 160 3840 160 3920 80 3920 80 3840 160 3920 80 3920 160 3840 240 3840 80 3840 160 3760 160 3920 80 3920 80 3840 240 3760 240 3840 80 3920 160 3840 80 3920 80 3920 80 3920 80 3920 160 3840 80 3920 80 3760 240 3920 80 3920 160 3760 160 3920 160 3840 80 3920 160 3840 160 3840 160 3600 320 3920 160 3840 80 3920 80 3680 320 3840 240 3760 160 3920 80 3920 80 3920 80 3920 80 3920 80 3680 320 3920 160 3840 160 3760 160 3920 240 3840 160 3840 240 3600 320 3840 80 3840 80 3920 160 3760 160 3840 160 3840 320 3840 80 3840 160 3760 240 3840 80 3840 240 3760 160 3840 160 3840 160 3920 240 3760 160 3840 80 3920 160 3680 240 3840 160 3840 160 3760 240 3920 80 3920 240 3760 160 3760 240 3840 80 3840 240 3840 240 3760 320 3760 240 3840 80 3840 160 3840 240 3760 320 3760 160 3840 160 3840 160 3840 80 3760 160 3840 80 3840 160 3920 160 3840 80 3920 80 3840 160 3920 80 3840 240 3840 80 3920 80 3760 240 3920 240 3840 80 3680 240 - │ │ │ │ │ │ │ <--- 2 ------ 49 ------ 90 ------ 141 ------ 183 ------ 235 ------ 278 ------ 319 ------ 360 ------ 406 ------ 458 ------ 511 ------ 561 ------ 622 ------ 674 ------ 731 ------ 781 ------ 822 ------ 882 ------ 934 ------ 988 ------ 1026 ------ 1072 ------ 1114 ------ 1188 ------ 1245 ------ 1291 ------ 1335 ------ 1380 ------ 1433 ------ 1488 ------ 1537 ------ 1590 ------ 1642 ------ 1692 ------ 1751 ------ 1807 ------ 1846 ------ 1887 ------ 1939 ------ 1994 ------ 2045 ------ 2097 ------ 2139 ------ 2190 ------ 2240 ------ 2293 ------ 2344 ------ 2385 ------ 2427 ------ 2484 ------ 2538 ------ 2601 ------ 2651 ------ 2730 ------ 2781 ------ 2825 ------ 2874 ------ 2938 ------ 2978 ------ 3034 ------ 3086 ------ 3139 ------ 3179 ------ 3231 ------ 3274 ------ 3334 ------ 3387 ------ 3431 ------ 3477 ------ 3530 ------ 3581 ------ 3633 ------ 3680 ------ 3725 ------ 3775 ------ 3820 ------ 3876 ------ 3923 ------ 3982 ------ 4036 ------ 4078 ------ 4116 ------ 4183 ------ 4227 ------ 4275 ------ 4336 ------ 4376 ------ 4424 ------ 4481 ------ 4537 ------ 4582 ------ 4630 ------ 4680 ------ 4727 ------ 4779 ------ 4828 ------ 4881 ------ 4938 ------ 4986 ------ 5040 ------ 5087 ------ 5138 ------ 5188 ------ 5237 ------ 5280 ------ 5318 ------ 5358 ------ 5405 ------ 5459 ------ 5516 ------ 5561 ------ 5615 ------ 5681 ------ 5744 ------ 5790 ------ 5847 ------ 5885 ------ 5927 ------ 5991 ------ 6042 ------ 6111 ------ 6165 ------ 6207 ------ 6259 ------ 6313 ------ 6359 ------ 6418 ------ 6471 ------ 6530 ------ 6587 ------ 6626 ------ 6672 ------ 6739 ------ 6784 ------ 6837 ------ 6886 ------ 6952 ------ 6994 ------ 7040 ------ 7081 ------ 7134 ------ 7178 ------ 7232 ------ 7280 ------ 7330 ------ 7378 ------ 7435 ------ 7486 ------ 7537 ------ 7593 ------ 7636 ------ 7680 ------ 7737 ------ 7788 ------ 7836 ------ 7877 ------ 7928 ------ 7993 ------ 8036 ------ 8083 ------ 8135 ------ 8180 ------ 8221 ------ 8263 ------ 8313 ------ 8352 ------ 8399 ------ 8453 ------ 8517 ------ 8566 ------ 8612 ------ 8664 ------ 8716 ------ 8766 ------ 8821 ------ 8871 ------ 8922 ------ 8956 ------ 9007 ------ 9050 ------ 9100 ------ 9154 ------ 9203 ------ 9246 ------ 9311 ------ 9358 ------ 9407 ------ 9470 ------ 9525 ------ 9564 ------ 9633 ------ 9672 ------ 9730 ------ 9778 ------ 9824 ------ 9868 ------ 9919 ------ 9959 ------ 10000 - │ │ │ │ │ │ ├── key: (14,15) - │ │ │ │ │ │ └── fd: (14,15)-->(16) - │ │ │ │ │ └── filters - │ │ │ │ │ ├── l_partkey:31 = ps_partkey:14 [type=bool, outer=(14,31), constraints=(/14: (/NULL - ]; /31: (/NULL - ]), fd=(14)==(31), (31)==(14)] - │ │ │ │ │ └── l_suppkey:32 = ps_suppkey:15 [type=bool, outer=(15,32), constraints=(/15: (/NULL - ]; /32: (/NULL - ]), fd=(15)==(32), (32)==(15)] - │ │ │ │ └── aggregations - │ │ │ │ ├── sum [as=sum:47, type=float, outer=(34)] - │ │ │ │ │ └── l_quantity:34 [type=float] - │ │ │ │ └── const-agg [as=ps_availqty:16, type=int, outer=(16)] - │ │ │ │ └── ps_availqty:16 [type=int] - │ │ │ └── filters - │ │ │ └── ps_availqty:16 > (sum:47 * 0.5) [type=bool, outer=(16,47), immutable, constraints=(/16: (/NULL - ])] - │ │ └── filters - │ │ └── p_name:21 LIKE 'forest%' [type=bool, outer=(21), constraints=(/21: [/'forest' - /'foresu'); tight)] - │ └── filters (true) - ├── select - │ ├── save-table-name: q20_select_15 - │ ├── columns: n_nationkey:9(int!null) n_name:10(char!null) - │ ├── stats: [rows=1, distinct(9)=1, null(9)=0, distinct(10)=1, null(10)=0] - │ ├── key: (9) - │ ├── fd: ()-->(10) - │ ├── scan nation - │ │ ├── save-table-name: q20_scan_16 - │ │ ├── columns: n_nationkey:9(int!null) n_name:10(char!null) - │ │ ├── stats: [rows=25, distinct(9)=25, null(9)=0, distinct(10)=25, null(10)=0] - │ │ │ histogram(9)= 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 - │ │ │ <--- 0 --- 1 --- 2 --- 3 --- 4 --- 5 --- 6 --- 7 --- 8 --- 9 --- 10 --- 11 --- 12 --- 13 --- 14 --- 15 --- 16 --- 17 --- 18 --- 19 --- 20 --- 21 --- 22 --- 23 --- 24 - │ │ ├── key: (9) - │ │ └── fd: (9)-->(10) - │ └── filters - │ └── n_name:10 = 'CANADA' [type=bool, outer=(10), constraints=(/10: [/'CANADA' - /'CANADA']; tight), fd=()-->(10)] - └── filters - └── s_nationkey:4 = n_nationkey:9 [type=bool, outer=(4,9), constraints=(/4: (/NULL - ]; /9: (/NULL - ]), fd=(4)==(9), (9)==(4)] + ├── project + │ ├── save-table-name: q20_project_4 + │ ├── columns: s_suppkey:1(int!null) s_name:2(char!null) s_address:3(varchar!null) s_nationkey:4(int!null) + │ ├── immutable + │ ├── stats: [rows=127.59486, distinct(1)=126.574101, null(1)=0, distinct(2)=127.594041, null(2)=0, distinct(3)=127.59486, null(3)=0, distinct(4)=24.8530641, null(4)=0] + │ ├── key: (1) + │ ├── fd: (1)-->(2-4) + │ └── inner-join (lookup supplier) + │ ├── save-table-name: q20_lookup_join_5 + │ ├── columns: s_suppkey:1(int!null) s_name:2(char!null) s_address:3(varchar!null) s_nationkey:4(int!null) ps_suppkey:15(int!null) + │ ├── key columns: [15] = [1] + │ ├── lookup columns are key + │ ├── immutable + │ ├── stats: [rows=127.59486, distinct(1)=126.574101, null(1)=0, distinct(2)=126.789831, null(2)=0, distinct(3)=126.790639, null(3)=0, distinct(4)=24.8481976, null(4)=0, distinct(15)=126.574101, null(15)=0] + │ ├── key: (15) + │ ├── fd: (1)-->(2-4), (1)==(15), (15)==(1) + │ ├── distinct-on + │ │ ├── save-table-name: q20_distinct_on_6 + │ │ ├── columns: ps_suppkey:15(int!null) + │ │ ├── grouping columns: ps_suppkey:15(int!null) + │ │ ├── immutable + │ │ ├── stats: [rows=126.574101, distinct(15)=126.574101, null(15)=0] + │ │ ├── key: (15) + │ │ └── semi-join (lookup part) + │ │ ├── save-table-name: q20_lookup_join_7 + │ │ ├── columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) + │ │ ├── key columns: [14] = [20] + │ │ ├── lookup columns are key + │ │ ├── immutable + │ │ ├── stats: [rows=126.574101, distinct(14)=126.574101, null(14)=0, distinct(15)=126.574101, null(15)=0] + │ │ ├── key: (14,15) + │ │ ├── project + │ │ │ ├── save-table-name: q20_project_8 + │ │ │ ├── columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) + │ │ │ ├── immutable + │ │ │ ├── stats: [rows=126.574101, distinct(14)=126.574101, null(14)=0, distinct(15)=126.574101, null(15)=0] + │ │ │ ├── key: (14,15) + │ │ │ └── select + │ │ │ ├── save-table-name: q20_select_9 + │ │ │ ├── columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) ps_availqty:16(int!null) sum:47(float!null) + │ │ │ ├── immutable + │ │ │ ├── stats: [rows=126.574101, distinct(14)=126.574101, null(14)=0, distinct(15)=126.574101, null(15)=0, distinct(16)=126.574101, null(16)=0, distinct(47)=126.574101, null(47)=0] + │ │ │ ├── key: (14,15) + │ │ │ ├── fd: (14,15)-->(16,47) + │ │ │ ├── group-by + │ │ │ │ ├── save-table-name: q20_group_by_10 + │ │ │ │ ├── columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) ps_availqty:16(int!null) sum:47(float!null) + │ │ │ │ ├── grouping columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) + │ │ │ │ ├── stats: [rows=379.722303, distinct(14)=379.722303, null(14)=0, distinct(15)=379.722303, null(15)=0, distinct(16)=379.722303, null(16)=0, distinct(47)=379.722303, null(47)=0, distinct(14,15)=379.722303, null(14,15)=0] + │ │ │ │ ├── key: (14,15) + │ │ │ │ ├── fd: (14,15)-->(16,47) + │ │ │ │ ├── inner-join (hash) + │ │ │ │ │ ├── save-table-name: q20_inner_join_11 + │ │ │ │ │ ├── columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) ps_availqty:16(int!null) l_partkey:31(int!null) l_suppkey:32(int!null) l_quantity:34(float!null) l_shipdate:40(date!null) + │ │ │ │ │ ├── multiplicity: left-rows(exactly-one), right-rows(zero-or-more) + │ │ │ │ │ ├── stats: [rows=379.722303, distinct(14)=379.722303, null(14)=0, distinct(15)=379.722303, null(15)=0, distinct(16)=372.546594, null(16)=0, distinct(31)=379.722303, null(31)=0, distinct(32)=379.722303, null(32)=0, distinct(34)=49.9748381, null(34)=0, distinct(40)=236.032274, null(40)=0, distinct(14,15)=379.722303, null(14,15)=0] + │ │ │ │ │ ├── fd: (14,15)-->(16), (14)==(31), (31)==(14), (15)==(32), (32)==(15) + │ │ │ │ │ ├── index-join lineitem + │ │ │ │ │ │ ├── save-table-name: q20_index_join_12 + │ │ │ │ │ │ ├── columns: l_partkey:31(int!null) l_suppkey:32(int!null) l_quantity:34(float!null) l_shipdate:40(date!null) + │ │ │ │ │ │ ├── stats: [rows=938137.516, distinct(31)=198050.435, null(31)=0, distinct(32)=9920, null(32)=0, distinct(34)=50, null(34)=0, distinct(40)=365, null(40)=0] + │ │ │ │ │ │ │ histogram(40)= 0 0 3150.6 4200 25805 3600 25805 3600 26405 3600 28805 1200 27605 2400 27005 3600 28805 1200 27005 4800 28205 3000 25205 4800 28805 4800 28805 600 28205 1200 24604 6601 24604 4800 28205 3600 27605 3600 27005 4200 28205 2400 28205 4200 28805 1200 28205 1800 28205 1200 28205 3000 27005 4800 28805 600 27005 3600 25805 5401 27005 2400 28205 3000 11502 2300.4 + │ │ │ │ │ │ │ <--- '1993-12-31' -------- '1994-01-02' ------- '1994-01-16' ------- '1994-01-30' ------- '1994-02-08' ------- '1994-02-18' ------- '1994-03-04' ------- '1994-03-15' ------- '1994-03-29' ------- '1994-04-10' ------- '1994-04-24' ------- '1994-05-03' ------- '1994-05-13' ------- '1994-05-24' ------- '1994-06-04' ------- '1994-06-13' ------- '1994-06-22' ------- '1994-07-05' ------- '1994-07-16' ------- '1994-07-29' ------- '1994-08-09' ------- '1994-08-22' ------- '1994-09-04' ------- '1994-09-15' ------- '1994-09-29' ------- '1994-10-10' ------- '1994-10-20' ------- '1994-11-03' ------- '1994-11-16' ------- '1994-11-29' ------- '1994-12-11' ------- '1994-12-25' ------- '1994-12-31' + │ │ │ │ │ │ └── scan lineitem@l_sd + │ │ │ │ │ │ ├── save-table-name: q20_scan_13 + │ │ │ │ │ │ ├── columns: l_orderkey:30(int!null) l_linenumber:33(int!null) l_shipdate:40(date!null) + │ │ │ │ │ │ ├── constraint: /40/30/33: [/'1994-01-01' - /'1994-12-31'] + │ │ │ │ │ │ ├── stats: [rows=938137.516, distinct(30)=744144.6, null(30)=0, distinct(33)=7, null(33)=0, distinct(40)=365, null(40)=0] + │ │ │ │ │ │ │ histogram(30)= 0 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4596.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 4690.7 93.795 + │ │ │ │ │ │ │ <--- 326 --------- 28929 -------- 50503 -------- 89793 -------- 115938 -------- 146944 -------- 176768 -------- 211201 -------- 237860 -------- 266885 -------- 297604 -------- 330021 -------- 365889 -------- 398951 -------- 426117 -------- 451328 -------- 472134 -------- 499590 -------- 529284 -------- 557254 -------- 589154 -------- 619394 -------- 642951 -------- 670113 -------- 692931 -------- 721157 -------- 751687 -------- 777766 -------- 804582 -------- 836740 -------- 868868 -------- 898912 -------- 922500 -------- 946403 -------- 984870 -------- 1007936 -------- 1030117 -------- 1062275 -------- 1093572 -------- 1120709 -------- 1150981 -------- 1182786 -------- 1206406 -------- 1234116 -------- 1260961 -------- 1290502 -------- 1329510 -------- 1355426 -------- 1381313 -------- 1409796 -------- 1445254 -------- 1479233 -------- 1504935 -------- 1531079 -------- 1559650 -------- 1583616 -------- 1617504 -------- 1655749 -------- 1685185 -------- 1718183 -------- 1747716 -------- 1772131 -------- 1802372 -------- 1833315 -------- 1862403 -------- 1897894 -------- 1922819 -------- 1954405 -------- 1979329 -------- 2009859 -------- 2041670 -------- 2070851 -------- 2093828 -------- 2127973 -------- 2167777 -------- 2194883 -------- 2227814 -------- 2262437 -------- 2296353 -------- 2321024 -------- 2346051 -------- 2376257 -------- 2404932 -------- 2446273 -------- 2474081 -------- 2504515 -------- 2535302 -------- 2561413 -------- 2592737 -------- 2616801 -------- 2646112 -------- 2676546 -------- 2702116 -------- 2732454 -------- 2765382 -------- 2799495 -------- 2828866 -------- 2868737 -------- 2910625 -------- 2938464 -------- 2963140 -------- 3003302 -------- 3043264 -------- 3069123 -------- 3095909 -------- 3126693 -------- 3160485 -------- 3196039 -------- 3229504 -------- 3259712 -------- 3286439 -------- 3318852 -------- 3346821 -------- 3370119 -------- 3395204 -------- 3425888 -------- 3448611 -------- 3476130 -------- 3502372 -------- 3529474 -------- 3556390 -------- 3583553 -------- 3612550 -------- 3647875 -------- 3679140 -------- 3702661 -------- 3738017 -------- 3778050 -------- 3806114 -------- 3839074 -------- 3872805 -------- 3905697 -------- 3926212 -------- 3959841 -------- 3997281 -------- 4033861 -------- 4063591 -------- 4097831 -------- 4124807 -------- 4158656 -------- 4195748 -------- 4234274 -------- 4269952 -------- 4298949 -------- 4332806 -------- 4364705 -------- 4398246 -------- 4430695 -------- 4466403 -------- 4494662 -------- 4524420 -------- 4558561 -------- 4601092 -------- 4632871 -------- 4658694 -------- 4690501 -------- 4728066 -------- 4758657 -------- 4788294 -------- 4818597 -------- 4855874 -------- 4890913 -------- 4915366 -------- 4940709 -------- 4972357 -------- 4995298 -------- 5019523 -------- 5043329 -------- 5077376 -------- 5109920 -------- 5136582 -------- 5161152 -------- 5191846 -------- 5219973 -------- 5251015 -------- 5282021 -------- 5312355 -------- 5343207 -------- 5381318 -------- 5416163 -------- 5445382 -------- 5476933 -------- 5509185 -------- 5539237 -------- 5566818 -------- 5588739 -------- 5620481 -------- 5644001 -------- 5667010 -------- 5689476 -------- 5724709 -------- 5755398 -------- 5790598 -------- 5819425 -------- 5846341 -------- 5874656 -------- 5908067 -------- 5933572 -------- 5962659 -------- 5999971 + │ │ │ │ │ │ │ histogram(40)= 0 0 3150.6 4200 25805 3600 25805 3600 26405 3600 28805 1200 27605 2400 27005 3600 28805 1200 27005 4800 28205 3000 25205 4800 28805 4800 28805 600 28205 1200 24604 6601 24604 4800 28205 3600 27605 3600 27005 4200 28205 2400 28205 4200 28805 1200 28205 1800 28205 1200 28205 3000 27005 4800 28805 600 27005 3600 25805 5401 27005 2400 28205 3000 11502 2300.4 + │ │ │ │ │ │ │ <--- '1993-12-31' -------- '1994-01-02' ------- '1994-01-16' ------- '1994-01-30' ------- '1994-02-08' ------- '1994-02-18' ------- '1994-03-04' ------- '1994-03-15' ------- '1994-03-29' ------- '1994-04-10' ------- '1994-04-24' ------- '1994-05-03' ------- '1994-05-13' ------- '1994-05-24' ------- '1994-06-04' ------- '1994-06-13' ------- '1994-06-22' ------- '1994-07-05' ------- '1994-07-16' ------- '1994-07-29' ------- '1994-08-09' ------- '1994-08-22' ------- '1994-09-04' ------- '1994-09-15' ------- '1994-09-29' ------- '1994-10-10' ------- '1994-10-20' ------- '1994-11-03' ------- '1994-11-16' ------- '1994-11-29' ------- '1994-12-11' ------- '1994-12-25' ------- '1994-12-31' + │ │ │ │ │ │ ├── key: (30,33) + │ │ │ │ │ │ └── fd: (30,33)-->(40) + │ │ │ │ │ ├── scan partsupp + │ │ │ │ │ │ ├── save-table-name: q20_scan_14 + │ │ │ │ │ │ ├── columns: ps_partkey:14(int!null) ps_suppkey:15(int!null) ps_availqty:16(int!null) + │ │ │ │ │ │ ├── stats: [rows=800000, distinct(14)=199241, null(14)=0, distinct(15)=9920, null(15)=0, distinct(16)=9920, null(16)=0, distinct(14,15)=798302, null(14,15)=0] + │ │ │ │ │ │ │ histogram(14)= 0 80 3920 80 3920 80 3920 80 3920 80 3840 160 3840 160 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 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 160 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 160 3920 80 3920 80 3920 80 3920 80 3920 80 3920 160 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 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 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 3920 160 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 + │ │ │ │ │ │ │ <--- 4 ------ 793 ------ 1856 ------ 2808 ------ 3809 ------ 4923 ------ 5975 ------ 6944 ------ 8085 ------ 8945 ------ 9831 ------ 10952 ------ 11932 ------ 12775 ------ 13849 ------ 14925 ------ 16016 ------ 16828 ------ 17768 ------ 18705 ------ 19631 ------ 20600 ------ 21491 ------ 22254 ------ 23327 ------ 24491 ------ 25470 ------ 26331 ------ 27327 ------ 28308 ------ 29359 ------ 30542 ------ 31592 ------ 32495 ------ 33408 ------ 34624 ------ 35726 ------ 36676 ------ 37637 ------ 38485 ------ 39368 ------ 40372 ------ 41034 ------ 42185 ------ 43333 ------ 44466 ------ 45440 ------ 46571 ------ 47469 ------ 48346 ------ 49379 ------ 50571 ------ 51830 ------ 52967 ------ 53673 ------ 54656 ------ 55504 ------ 56539 ------ 57393 ------ 58366 ------ 59577 ------ 60559 ------ 61676 ------ 62471 ------ 63421 ------ 64449 ------ 65409 ------ 66254 ------ 67127 ------ 68127 ------ 69177 ------ 70183 ------ 71209 ------ 72101 ------ 73102 ------ 73994 ------ 74899 ------ 76016 ------ 77098 ------ 77842 ------ 79137 ------ 80242 ------ 81364 ------ 82331 ------ 83158 ------ 84283 ------ 85282 ------ 86437 ------ 87450 ------ 88419 ------ 89493 ------ 90478 ------ 91468 ------ 92552 ------ 93200 ------ 94191 ------ 95067 ------ 96272 ------ 97228 ------ 98126 ------ 99198 ------ 100219 ------ 101057 ------ 102038 ------ 102775 ------ 103711 ------ 104623 ------ 105710 ------ 106734 ------ 107932 ------ 109255 ------ 110220 ------ 111235 ------ 112174 ------ 113260 ------ 114081 ------ 115103 ------ 115864 ------ 116794 ------ 117741 ------ 118712 ------ 119470 ------ 120528 ------ 121572 ------ 122536 ------ 123629 ------ 124404 ------ 125301 ------ 126257 ------ 127139 ------ 128267 ------ 129258 ------ 130442 ------ 131845 ------ 133164 ------ 134005 ------ 135076 ------ 135868 ------ 137297 ------ 138777 ------ 139806 ------ 140741 ------ 141896 ------ 142719 ------ 143727 ------ 144645 ------ 145510 ------ 146507 ------ 147449 ------ 148467 ------ 149635 ------ 150563 ------ 151751 ------ 152613 ------ 153416 ------ 154612 ------ 155853 ------ 156866 ------ 158311 ------ 159230 ------ 160390 ------ 161455 ------ 162555 ------ 163435 ------ 164549 ------ 165663 ------ 166891 ------ 167757 ------ 168732 ------ 169644 ------ 170532 ------ 171671 ------ 172778 ------ 173599 ------ 174321 ------ 175624 ------ 176663 ------ 177632 ------ 178555 ------ 179551 ------ 180510 ------ 181682 ------ 182648 ------ 183408 ------ 184543 ------ 185722 ------ 186713 ------ 187787 ------ 188730 ------ 189604 ------ 190711 ------ 191690 ------ 192692 ------ 193702 ------ 194685 ------ 195725 ------ 196730 ------ 197724 ------ 198701 ------ 199973 + │ │ │ │ │ │ │ histogram(15)= 0 80 3920 240 3920 80 3920 160 3920 80 3920 240 3920 80 3760 320 3680 320 3920 80 3920 160 3920 240 3920 80 3920 160 3840 160 3920 80 3920 80 3760 240 3840 160 3920 80 3840 160 3680 320 3920 80 3840 160 3840 160 3760 320 3840 160 3840 160 3920 80 3840 240 3920 80 3920 80 3840 160 3760 240 3920 160 3920 80 3920 80 3920 80 3920 320 3920 80 3920 160 3840 400 3760 240 3920 160 3920 160 3600 480 3920 80 3680 320 3840 160 3840 160 3920 240 3840 160 3920 160 3920 80 3920 160 3920 80 3760 240 3920 80 3920 80 3840 320 3840 160 3840 160 3920 240 3840 480 3920 160 3840 240 3920 160 3920 160 3920 80 3840 160 3920 80 3920 80 3920 80 3920 80 3840 240 3840 240 3920 80 3840 320 3920 80 3920 80 3920 240 3840 240 3920 160 3920 80 3840 160 3840 240 3920 240 3840 80 3680 320 3920 160 3840 160 3840 80 3920 80 3840 160 3840 160 3920 80 3920 80 3840 160 3920 80 3920 160 3840 240 3840 80 3840 160 3760 160 3920 80 3920 80 3840 240 3760 240 3840 80 3920 160 3840 80 3920 80 3920 80 3920 80 3920 160 3840 80 3920 80 3760 240 3920 80 3920 160 3760 160 3920 160 3840 80 3920 160 3840 160 3840 160 3600 320 3920 160 3840 80 3920 80 3680 320 3840 240 3760 160 3920 80 3920 80 3920 80 3920 80 3920 80 3680 320 3920 160 3840 160 3760 160 3920 240 3840 160 3840 240 3600 320 3840 80 3840 80 3920 160 3760 160 3840 160 3840 320 3840 80 3840 160 3760 240 3840 80 3840 240 3760 160 3840 160 3840 160 3920 240 3760 160 3840 80 3920 160 3680 240 3840 160 3840 160 3760 240 3920 80 3920 240 3760 160 3760 240 3840 80 3840 240 3840 240 3760 320 3760 240 3840 80 3840 160 3840 240 3760 320 3760 160 3840 160 3840 160 3840 80 3760 160 3840 80 3840 160 3920 160 3840 80 3920 80 3840 160 3920 80 3840 240 3840 80 3920 80 3760 240 3920 240 3840 80 3680 240 + │ │ │ │ │ │ │ <--- 2 ------ 49 ------ 90 ------ 141 ------ 183 ------ 235 ------ 278 ------ 319 ------ 360 ------ 406 ------ 458 ------ 511 ------ 561 ------ 622 ------ 674 ------ 731 ------ 781 ------ 822 ------ 882 ------ 934 ------ 988 ------ 1026 ------ 1072 ------ 1114 ------ 1188 ------ 1245 ------ 1291 ------ 1335 ------ 1380 ------ 1433 ------ 1488 ------ 1537 ------ 1590 ------ 1642 ------ 1692 ------ 1751 ------ 1807 ------ 1846 ------ 1887 ------ 1939 ------ 1994 ------ 2045 ------ 2097 ------ 2139 ------ 2190 ------ 2240 ------ 2293 ------ 2344 ------ 2385 ------ 2427 ------ 2484 ------ 2538 ------ 2601 ------ 2651 ------ 2730 ------ 2781 ------ 2825 ------ 2874 ------ 2938 ------ 2978 ------ 3034 ------ 3086 ------ 3139 ------ 3179 ------ 3231 ------ 3274 ------ 3334 ------ 3387 ------ 3431 ------ 3477 ------ 3530 ------ 3581 ------ 3633 ------ 3680 ------ 3725 ------ 3775 ------ 3820 ------ 3876 ------ 3923 ------ 3982 ------ 4036 ------ 4078 ------ 4116 ------ 4183 ------ 4227 ------ 4275 ------ 4336 ------ 4376 ------ 4424 ------ 4481 ------ 4537 ------ 4582 ------ 4630 ------ 4680 ------ 4727 ------ 4779 ------ 4828 ------ 4881 ------ 4938 ------ 4986 ------ 5040 ------ 5087 ------ 5138 ------ 5188 ------ 5237 ------ 5280 ------ 5318 ------ 5358 ------ 5405 ------ 5459 ------ 5516 ------ 5561 ------ 5615 ------ 5681 ------ 5744 ------ 5790 ------ 5847 ------ 5885 ------ 5927 ------ 5991 ------ 6042 ------ 6111 ------ 6165 ------ 6207 ------ 6259 ------ 6313 ------ 6359 ------ 6418 ------ 6471 ------ 6530 ------ 6587 ------ 6626 ------ 6672 ------ 6739 ------ 6784 ------ 6837 ------ 6886 ------ 6952 ------ 6994 ------ 7040 ------ 7081 ------ 7134 ------ 7178 ------ 7232 ------ 7280 ------ 7330 ------ 7378 ------ 7435 ------ 7486 ------ 7537 ------ 7593 ------ 7636 ------ 7680 ------ 7737 ------ 7788 ------ 7836 ------ 7877 ------ 7928 ------ 7993 ------ 8036 ------ 8083 ------ 8135 ------ 8180 ------ 8221 ------ 8263 ------ 8313 ------ 8352 ------ 8399 ------ 8453 ------ 8517 ------ 8566 ------ 8612 ------ 8664 ------ 8716 ------ 8766 ------ 8821 ------ 8871 ------ 8922 ------ 8956 ------ 9007 ------ 9050 ------ 9100 ------ 9154 ------ 9203 ------ 9246 ------ 9311 ------ 9358 ------ 9407 ------ 9470 ------ 9525 ------ 9564 ------ 9633 ------ 9672 ------ 9730 ------ 9778 ------ 9824 ------ 9868 ------ 9919 ------ 9959 ------ 10000 + │ │ │ │ │ │ ├── key: (14,15) + │ │ │ │ │ │ └── fd: (14,15)-->(16) + │ │ │ │ │ └── filters + │ │ │ │ │ ├── l_partkey:31 = ps_partkey:14 [type=bool, outer=(14,31), constraints=(/14: (/NULL - ]; /31: (/NULL - ]), fd=(14)==(31), (31)==(14)] + │ │ │ │ │ └── l_suppkey:32 = ps_suppkey:15 [type=bool, outer=(15,32), constraints=(/15: (/NULL - ]; /32: (/NULL - ]), fd=(15)==(32), (32)==(15)] + │ │ │ │ └── aggregations + │ │ │ │ ├── sum [as=sum:47, type=float, outer=(34)] + │ │ │ │ │ └── l_quantity:34 [type=float] + │ │ │ │ └── const-agg [as=ps_availqty:16, type=int, outer=(16)] + │ │ │ │ └── ps_availqty:16 [type=int] + │ │ │ └── filters + │ │ │ └── ps_availqty:16 > (sum:47 * 0.5) [type=bool, outer=(16,47), immutable, constraints=(/16: (/NULL - ])] + │ │ └── filters + │ │ └── p_name:21 LIKE 'forest%' [type=bool, outer=(21), constraints=(/21: [/'forest' - /'foresu'); tight)] + │ └── filters (true) + ├── select + │ ├── save-table-name: q20_select_15 + │ ├── columns: n_nationkey:9(int!null) n_name:10(char!null) + │ ├── stats: [rows=1, distinct(9)=1, null(9)=0, distinct(10)=1, null(10)=0] + │ ├── key: (9) + │ ├── fd: ()-->(10) + │ ├── scan nation + │ │ ├── save-table-name: q20_scan_16 + │ │ ├── columns: n_nationkey:9(int!null) n_name:10(char!null) + │ │ ├── stats: [rows=25, distinct(9)=25, null(9)=0, distinct(10)=25, null(10)=0] + │ │ │ histogram(9)= 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 + │ │ │ <--- 0 --- 1 --- 2 --- 3 --- 4 --- 5 --- 6 --- 7 --- 8 --- 9 --- 10 --- 11 --- 12 --- 13 --- 14 --- 15 --- 16 --- 17 --- 18 --- 19 --- 20 --- 21 --- 22 --- 23 --- 24 + │ │ ├── key: (9) + │ │ └── fd: (9)-->(10) + │ └── filters + │ └── n_name:10 = 'CANADA' [type=bool, outer=(10), constraints=(/10: [/'CANADA' - /'CANADA']; tight), fd=()-->(10)] + └── filters + └── s_nationkey:4 = n_nationkey:9 [type=bool, outer=(4,9), constraints=(/4: (/NULL - ]; /9: (/NULL - ]), fd=(4)==(9), (9)==(4)] ----Stats for q20_sort_1---- column_names row_count distinct_count null_count @@ -211,7 +211,7 @@ column_names row_count_est row_count_err distinct_count_est distinct_count_e {s_address} 5.00 37.20 <== 5.00 37.20 <== 0.00 1.00 {s_name} 5.00 37.20 <== 5.00 37.20 <== 0.00 1.00 -----Stats for q20_project_3---- +----Stats for q20_inner_join_3---- column_names row_count distinct_count null_count {n_name} 186 1 0 {n_nationkey} 186 1 0 @@ -228,24 +228,18 @@ column_names row_count_est row_count_err distinct_count_est distinct_count_ {s_nationkey} 5.00 37.20 <== 1.00 1.00 0.00 1.00 {s_suppkey} 5.00 37.20 <== 5.00 37.20 <== 0.00 1.00 -----Stats for q20_inner_join_4---- +----Stats for q20_project_4---- column_names row_count distinct_count null_count -{n_name} 186 1 0 -{n_nationkey} 186 1 0 -{ps_suppkey} 186 186 0 -{s_address} 186 186 0 -{s_name} 186 186 0 -{s_nationkey} 186 1 0 -{s_suppkey} 186 186 0 +{s_address} 4397 4369 0 +{s_name} 4397 4373 0 +{s_nationkey} 4397 25 0 +{s_suppkey} 4397 4434 0 ~~~~ column_names row_count_est row_count_err distinct_count_est distinct_count_err null_count_est null_count_err -{n_name} 127.00 1.46 1.00 1.00 0.00 1.00 -{n_nationkey} 127.00 1.46 1.00 1.00 0.00 1.00 -{ps_suppkey} 127.00 1.46 127.00 1.46 0.00 1.00 -{s_address} 127.00 1.46 109.00 1.71 0.00 1.00 -{s_name} 127.00 1.46 109.00 1.71 0.00 1.00 -{s_nationkey} 127.00 1.46 1.00 1.00 0.00 1.00 -{s_suppkey} 127.00 1.46 127.00 1.46 0.00 1.00 +{s_address} 128.00 34.35 <== 128.00 34.13 <== 0.00 1.00 +{s_name} 128.00 34.35 <== 128.00 34.16 <== 0.00 1.00 +{s_nationkey} 128.00 34.35 <== 25.00 1.00 0.00 1.00 +{s_suppkey} 128.00 34.35 <== 127.00 34.91 <== 0.00 1.00 ----Stats for q20_lookup_join_5---- column_names row_count distinct_count null_count diff --git a/pkg/sql/opt/norm/testdata/rules/combo b/pkg/sql/opt/norm/testdata/rules/combo index f63aeb58177f..2e6df512c2c2 100644 --- a/pkg/sql/opt/norm/testdata/rules/combo +++ b/pkg/sql/opt/norm/testdata/rules/combo @@ -308,11 +308,8 @@ GenerateConstrainedScans (no changes) -------------------------------------------------------------------------------- GenerateIndexScans (no changes) -------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -ReorderJoins (no changes) --------------------------------------------------------------------------------- ================================================================================ -CommuteJoin +ReorderJoins Cost: 2132.97 ================================================================================ project @@ -411,9 +408,6 @@ GenerateLookupJoins - │ └── ordering: +7 └── filters (true) -------------------------------------------------------------------------------- -CommuteJoin (no changes) --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- GenerateMergeJoins (higher cost) -------------------------------------------------------------------------------- project @@ -1036,15 +1030,9 @@ GenerateStreamingGroupBy (no changes) ReorderJoins (no changes) -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -CommuteJoin (no changes) --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- GenerateMergeJoins (no changes) -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -CommuteJoin (no changes) --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- GenerateMergeJoins (no changes) -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- diff --git a/pkg/sql/opt/testutils/opttester/testdata/explore-trace b/pkg/sql/opt/testutils/opttester/testdata/explore-trace index f364bea586d8..1ba3c18a7d6f 100644 --- a/pkg/sql/opt/testutils/opttester/testdata/explore-trace +++ b/pkg/sql/opt/testutils/opttester/testdata/explore-trace @@ -133,6 +133,37 @@ SELECT * FROM ORDER BY pid ---- ---- +================================================================================ +ReorderJoins +================================================================================ +Source expression: + sort + └── project + └── inner-join (hash) + ├── inner-join (hash) + │ ├── scan grandchild + │ ├── scan child + │ └── filters + │ ├── grandchild.pid = child.pid + │ └── grandchild.cid = child.cid + ├── scan parent + └── filters + └── grandchild.pid = parent.pid + +New expression 1 of 1: + sort + └── project + └── inner-join (hash) + ├── inner-join (hash) + │ ├── scan child + │ ├── scan grandchild + │ └── filters + │ ├── grandchild.pid = child.pid + │ └── grandchild.cid = child.cid + ├── scan parent + └── filters + └── grandchild.pid = parent.pid + ================================================================================ ReorderJoins ================================================================================ @@ -148,7 +179,7 @@ Source expression: └── filters └── grandchild.pid = parent.pid -New expression 1 of 2: +New expression 1 of 5: sort └── project └── inner-join (hash) @@ -162,7 +193,21 @@ New expression 1 of 2: ├── grandchild.pid = child.pid └── grandchild.cid = child.cid -New expression 2 of 2: +New expression 2 of 5: + sort + └── project + └── inner-join (hash) + ├── inner-join (hash) + │ ├── scan child + │ ├── scan parent + │ └── filters + │ └── child.pid = parent.pid + ├── scan grandchild + └── filters + ├── grandchild.pid = child.pid + └── grandchild.cid = child.cid + +New expression 3 of 5: sort └── project └── inner-join (hash) @@ -175,5 +220,31 @@ New expression 2 of 2: └── filters ├── grandchild.pid = child.pid └── grandchild.cid = child.cid + +New expression 4 of 5: + sort + └── project + └── inner-join (hash) + ├── inner-join (hash) + │ ├── scan grandchild + │ ├── scan parent + │ └── filters + │ └── grandchild.pid = parent.pid + ├── scan child + └── filters + ├── grandchild.pid = child.pid + └── grandchild.cid = child.cid + +New expression 5 of 5: + sort + └── project + └── inner-join (hash) + ├── scan parent + ├── inner-join (merge) + │ ├── scan grandchild + │ ├── scan child + │ └── filters (true) + └── filters + └── grandchild.pid = parent.pid ---- ---- diff --git a/pkg/sql/opt/xform/custom_funcs.go b/pkg/sql/opt/xform/custom_funcs.go index f3e406c1e2fb..2b09ea530ba4 100644 --- a/pkg/sql/opt/xform/custom_funcs.go +++ b/pkg/sql/opt/xform/custom_funcs.go @@ -1532,33 +1532,6 @@ func (c *CustomFuncs) getKnownScanConstraint( // // ---------------------------------------------------------------------- -// CommuteJoinFlags returns a join private for the commuted join (where the left -// and right sides are swapped). It adjusts any join flags that are specific to -// one side. -func (c *CustomFuncs) CommuteJoinFlags(p *memo.JoinPrivate) *memo.JoinPrivate { - if p.Flags.Empty() { - return p - } - - // swap is a helper function which swaps the values of two (single-bit) flags. - swap := func(f, a, b memo.JoinFlags) memo.JoinFlags { - // If the bits are different, flip them both. - if f.Has(a) != f.Has(b) { - f ^= (a | b) - } - return f - } - f := p.Flags - f = swap(f, memo.AllowLookupJoinIntoLeft, memo.AllowLookupJoinIntoRight) - f = swap(f, memo.AllowHashJoinStoreLeft, memo.AllowHashJoinStoreRight) - if p.Flags == f { - return p - } - res := *p - res.Flags = f - return &res -} - // GenerateMergeJoins spawns MergeJoinOps, based on any interesting orderings. func (c *CustomFuncs) GenerateMergeJoins( grp memo.RelExpr, @@ -1588,8 +1561,15 @@ func (c *CustomFuncs) GenerateMergeJoins( orders := DeriveInterestingOrderings(left).Copy() orders.RestrictToCols(leftEq.ToSet()) - if !joinPrivate.Flags.Has(memo.AllowHashJoinStoreLeft) && - !joinPrivate.Flags.Has(memo.AllowHashJoinStoreRight) { + if (!joinPrivate.Flags.Has(memo.AllowHashJoinStoreLeft) && + !joinPrivate.Flags.Has(memo.AllowHashJoinStoreRight)) || + c.e.evalCtx.SessionData.ReorderJoinsLimit == 0 { + // If we are using a hint, or the join limit is set to zero, the join won't + // be commuted. Add the orderings from the right side. + rightOrders := DeriveInterestingOrderings(right).Copy() + rightOrders.RestrictToCols(leftEq.ToSet()) + orders = append(orders, rightOrders...) + // If we don't allow hash join, we must do our best to generate a merge // join, even if it means sorting both sides. We append an arbitrary // ordering, in case the interesting orderings don't result in any merge diff --git a/pkg/sql/opt/xform/join_order_builder.go b/pkg/sql/opt/xform/join_order_builder.go index 1b90e2b02132..eb19ba1f0650 100644 --- a/pkg/sql/opt/xform/join_order_builder.go +++ b/pkg/sql/opt/xform/join_order_builder.go @@ -309,8 +309,7 @@ func (jb *JoinOrderBuilder) Init(f *norm.Factory, evalCtx *tree.EvalContext) { jb.joinCount = 0 } -// Reorder adds all valid (non-commutative) orderings of the given join to the -// memo. +// Reorder adds all valid orderings of the given join to the memo. func (jb *JoinOrderBuilder) Reorder(join memo.RelExpr) { switch t := join.(type) { case *memo.InnerJoinExpr, *memo.SemiJoinExpr, *memo.AntiJoinExpr, @@ -519,11 +518,9 @@ func (jb *JoinOrderBuilder) addJoins(s1, s2 vertexSet) { } if e.checkNonInnerJoin(s2, s1) { // If joining s1, s2 is not valid, try s2, s1. We only do this if the - // s1, s2 join fails, because commutation (for full joins) is handled by - // the CommuteJoin rule. - // - // This is necessary because we only iterate s1 up to subset / 2 in - // DPSube(). Take this transformation as an example: + // s1, s2 join fails, because commutation is handled by the addJoin + // function. This is necessary because we only iterate s1 up to subset / 2 + // in DPSube(). Take this transformation as an example: // // SELECT * // FROM (SELECT * FROM xy LEFT JOIN ab ON x = a) @@ -662,6 +659,7 @@ func (jb *JoinOrderBuilder) addJoin( // Hook for testing purposes. jb.callOnAddJoinFunc(s1, s2, joinFilters, op) } + left := jb.plans[s1] right := jb.plans[s2] union := s1.union(s2) @@ -670,6 +668,16 @@ func (jb *JoinOrderBuilder) addJoin( } else { jb.plans[union] = jb.memoize(op, left, right, joinFilters, selectFilters) } + + if commute(op) { + // Also add the commuted version of the join to the memo. + jb.addToGroup(op, right, left, joinFilters, selectFilters, jb.plans[union]) + + if jb.onAddJoinFunc != nil { + // Hook for testing purposes. + jb.callOnAddJoinFunc(s2, s1, joinFilters, op) + } + } } // areFiltersRedundant returns true if the given FiltersExpr contains a single @@ -1262,6 +1270,11 @@ func (e *edge) checkRules(s1, s2 vertexSet) bool { return true } +// commute returns true if the given join operator type is commutable. +func commute(op opt.Operator) bool { + return op == opt.InnerJoinOp || op == opt.FullJoinOp +} + // assoc returns true if two joins with the operator types and filters described // by the given edges are associative with each other. An example of an // application of the associative property: diff --git a/pkg/sql/opt/xform/rules/join.opt b/pkg/sql/opt/xform/rules/join.opt index 07f6f32afe64..a32fef0cd5ad 100644 --- a/pkg/sql/opt/xform/rules/join.opt +++ b/pkg/sql/opt/xform/rules/join.opt @@ -2,11 +2,10 @@ # join.opt contains exploration rules for the Join operator. # ============================================================================= -# ReorderJoins matches the first expression of an inner join group and adds to -# the memo all valid join orderings that do not introduce cross joins. If the -# join has join hints or is the result of a previous join reordering, the join -# tree is not reordered. For more information, see the comment in -# join_order_builder.go. +# ReorderJoins matches the first expression of a join group and adds to the memo +# all valid join orderings that do not introduce cross joins. If the join has +# join hints or is the result of a previous join reordering, the join tree is +# not reordered. For more information, see the comment in join_order_builder.go. # # Citations: [8] [ReorderJoins, Explore] @@ -16,15 +15,6 @@ => (ReorderJoins) -# CommuteJoin creates a Join with the left and right inputs swapped. This is -# useful for other rules that convert joins to other operators (like merge -# join). -# If any join hints are specified, we keep the order in the query. -[CommuteJoin, Explore] -(InnerJoin | FullJoin $left:* $right:* $on:* $private:*) -=> -((OpName) $right $left $on (CommuteJoinFlags $private)) - # CommuteLeftJoin creates a Join with the left and right inputs swapped. # This is symmetric with the CommuteRightJoin normalization rule. [CommuteLeftJoin, Explore] diff --git a/pkg/sql/opt/xform/testdata/external/tpce-no-stats b/pkg/sql/opt/xform/testdata/external/tpce-no-stats index 69a0e6ddb188..d19bb72824c9 100644 --- a/pkg/sql/opt/xform/testdata/external/tpce-no-stats +++ b/pkg/sql/opt/xform/testdata/external/tpce-no-stats @@ -775,46 +775,46 @@ project ├── fd: ()-->(4,7-9,12,14,18-20,22,23,25,26,29-32,35,36,39-43,47-50,53,54,56-60) ├── inner-join (lookup zip_code) │ ├── columns: s_symb:1!null s_name:4!null s_ex_id:5!null s_co_id:6!null s_num_out:7!null s_start_date:8!null s_exch_date:9!null security.s_pe:10!null security.s_52wk_high:11!null s_52wk_high_date:12!null security.s_52wk_low:13!null s_52wk_low_date:14!null security.s_dividend:15!null security.s_yield:16!null co_id:18!null co_st_id:19!null co_name:20!null co_sp_rate:22!null co_ceo:23!null co_ad_id:24!null co_desc:25!null co_open_date:26!null ca.ad_id:28!null ca.ad_line1:29 ca.ad_line2:30 ca.ad_zc_code:31!null ca.ad_ctry:32 zca.zc_code:34!null zca.zc_town:35!null zca.zc_div:36!null ex_id:38!null ex_name:39!null ex_num_symb:40!null ex_open:41!null ex_close:42!null ex_desc:43 ex_ad_id:44!null ea.ad_id:46!null ea.ad_line1:47 ea.ad_line2:48 ea.ad_zc_code:49!null ea.ad_ctry:50 zea.zc_code:52!null zea.zc_town:53!null zea.zc_div:54!null - │ ├── key columns: [49] = [52] + │ ├── key columns: [31] = [34] │ ├── lookup columns are key │ ├── cardinality: [0 - 1] │ ├── key: () │ ├── fd: ()-->(1,4-16,18-20,22-26,28-32,34-36,38-44,46-50,52-54) │ ├── inner-join (lookup address) - │ │ ├── columns: s_symb:1!null s_name:4!null s_ex_id:5!null s_co_id:6!null s_num_out:7!null s_start_date:8!null s_exch_date:9!null security.s_pe:10!null security.s_52wk_high:11!null s_52wk_high_date:12!null security.s_52wk_low:13!null s_52wk_low_date:14!null security.s_dividend:15!null security.s_yield:16!null co_id:18!null co_st_id:19!null co_name:20!null co_sp_rate:22!null co_ceo:23!null co_ad_id:24!null co_desc:25!null co_open_date:26!null ca.ad_id:28!null ca.ad_line1:29 ca.ad_line2:30 ca.ad_zc_code:31!null ca.ad_ctry:32 zca.zc_code:34!null zca.zc_town:35!null zca.zc_div:36!null ex_id:38!null ex_name:39!null ex_num_symb:40!null ex_open:41!null ex_close:42!null ex_desc:43 ex_ad_id:44!null ea.ad_id:46!null ea.ad_line1:47 ea.ad_line2:48 ea.ad_zc_code:49!null ea.ad_ctry:50 - │ │ ├── key columns: [44] = [46] + │ │ ├── columns: s_symb:1!null s_name:4!null s_ex_id:5!null s_co_id:6!null s_num_out:7!null s_start_date:8!null s_exch_date:9!null security.s_pe:10!null security.s_52wk_high:11!null s_52wk_high_date:12!null security.s_52wk_low:13!null s_52wk_low_date:14!null security.s_dividend:15!null security.s_yield:16!null co_id:18!null co_st_id:19!null co_name:20!null co_sp_rate:22!null co_ceo:23!null co_ad_id:24!null co_desc:25!null co_open_date:26!null ca.ad_id:28!null ca.ad_line1:29 ca.ad_line2:30 ca.ad_zc_code:31!null ca.ad_ctry:32 ex_id:38!null ex_name:39!null ex_num_symb:40!null ex_open:41!null ex_close:42!null ex_desc:43 ex_ad_id:44!null ea.ad_id:46!null ea.ad_line1:47 ea.ad_line2:48 ea.ad_zc_code:49!null ea.ad_ctry:50 zea.zc_code:52!null zea.zc_town:53!null zea.zc_div:54!null + │ │ ├── key columns: [24] = [28] │ │ ├── lookup columns are key │ │ ├── cardinality: [0 - 1] │ │ ├── key: () - │ │ ├── fd: ()-->(1,4-16,18-20,22-26,28-32,34-36,38-44,46-50) - │ │ ├── inner-join (lookup exchange) - │ │ │ ├── columns: s_symb:1!null s_name:4!null s_ex_id:5!null s_co_id:6!null s_num_out:7!null s_start_date:8!null s_exch_date:9!null security.s_pe:10!null security.s_52wk_high:11!null s_52wk_high_date:12!null security.s_52wk_low:13!null s_52wk_low_date:14!null security.s_dividend:15!null security.s_yield:16!null co_id:18!null co_st_id:19!null co_name:20!null co_sp_rate:22!null co_ceo:23!null co_ad_id:24!null co_desc:25!null co_open_date:26!null ca.ad_id:28!null ca.ad_line1:29 ca.ad_line2:30 ca.ad_zc_code:31!null ca.ad_ctry:32 zca.zc_code:34!null zca.zc_town:35!null zca.zc_div:36!null ex_id:38!null ex_name:39!null ex_num_symb:40!null ex_open:41!null ex_close:42!null ex_desc:43 ex_ad_id:44!null - │ │ │ ├── key columns: [5] = [38] + │ │ ├── fd: ()-->(1,4-16,18-20,22-26,28-32,38-44,46-50,52-54) + │ │ ├── inner-join (lookup company) + │ │ │ ├── columns: s_symb:1!null s_name:4!null s_ex_id:5!null s_co_id:6!null s_num_out:7!null s_start_date:8!null s_exch_date:9!null security.s_pe:10!null security.s_52wk_high:11!null s_52wk_high_date:12!null security.s_52wk_low:13!null s_52wk_low_date:14!null security.s_dividend:15!null security.s_yield:16!null co_id:18!null co_st_id:19!null co_name:20!null co_sp_rate:22!null co_ceo:23!null co_ad_id:24!null co_desc:25!null co_open_date:26!null ex_id:38!null ex_name:39!null ex_num_symb:40!null ex_open:41!null ex_close:42!null ex_desc:43 ex_ad_id:44!null ea.ad_id:46!null ea.ad_line1:47 ea.ad_line2:48 ea.ad_zc_code:49!null ea.ad_ctry:50 zea.zc_code:52!null zea.zc_town:53!null zea.zc_div:54!null + │ │ │ ├── key columns: [6] = [18] │ │ │ ├── lookup columns are key │ │ │ ├── cardinality: [0 - 1] │ │ │ ├── key: () - │ │ │ ├── fd: ()-->(1,4-16,18-20,22-26,28-32,34-36,38-44) + │ │ │ ├── fd: ()-->(1,4-16,18-20,22-26,38-44,46-50,52-54) │ │ │ ├── inner-join (lookup zip_code) - │ │ │ │ ├── columns: s_symb:1!null s_name:4!null s_ex_id:5!null s_co_id:6!null s_num_out:7!null s_start_date:8!null s_exch_date:9!null security.s_pe:10!null security.s_52wk_high:11!null s_52wk_high_date:12!null security.s_52wk_low:13!null s_52wk_low_date:14!null security.s_dividend:15!null security.s_yield:16!null co_id:18!null co_st_id:19!null co_name:20!null co_sp_rate:22!null co_ceo:23!null co_ad_id:24!null co_desc:25!null co_open_date:26!null ca.ad_id:28!null ca.ad_line1:29 ca.ad_line2:30 ca.ad_zc_code:31!null ca.ad_ctry:32 zca.zc_code:34!null zca.zc_town:35!null zca.zc_div:36!null - │ │ │ │ ├── key columns: [31] = [34] + │ │ │ │ ├── columns: s_symb:1!null s_name:4!null s_ex_id:5!null s_co_id:6!null s_num_out:7!null s_start_date:8!null s_exch_date:9!null security.s_pe:10!null security.s_52wk_high:11!null s_52wk_high_date:12!null security.s_52wk_low:13!null s_52wk_low_date:14!null security.s_dividend:15!null security.s_yield:16!null ex_id:38!null ex_name:39!null ex_num_symb:40!null ex_open:41!null ex_close:42!null ex_desc:43 ex_ad_id:44!null ea.ad_id:46!null ea.ad_line1:47 ea.ad_line2:48 ea.ad_zc_code:49!null ea.ad_ctry:50 zea.zc_code:52!null zea.zc_town:53!null zea.zc_div:54!null + │ │ │ │ ├── key columns: [49] = [52] │ │ │ │ ├── lookup columns are key │ │ │ │ ├── cardinality: [0 - 1] │ │ │ │ ├── key: () - │ │ │ │ ├── fd: ()-->(1,4-16,18-20,22-26,28-32,34-36) + │ │ │ │ ├── fd: ()-->(1,4-16,38-44,46-50,52-54) │ │ │ │ ├── inner-join (lookup address) - │ │ │ │ │ ├── columns: s_symb:1!null s_name:4!null s_ex_id:5!null s_co_id:6!null s_num_out:7!null s_start_date:8!null s_exch_date:9!null security.s_pe:10!null security.s_52wk_high:11!null s_52wk_high_date:12!null security.s_52wk_low:13!null s_52wk_low_date:14!null security.s_dividend:15!null security.s_yield:16!null co_id:18!null co_st_id:19!null co_name:20!null co_sp_rate:22!null co_ceo:23!null co_ad_id:24!null co_desc:25!null co_open_date:26!null ca.ad_id:28!null ca.ad_line1:29 ca.ad_line2:30 ca.ad_zc_code:31!null ca.ad_ctry:32 - │ │ │ │ │ ├── key columns: [24] = [28] + │ │ │ │ │ ├── columns: s_symb:1!null s_name:4!null s_ex_id:5!null s_co_id:6!null s_num_out:7!null s_start_date:8!null s_exch_date:9!null security.s_pe:10!null security.s_52wk_high:11!null s_52wk_high_date:12!null security.s_52wk_low:13!null s_52wk_low_date:14!null security.s_dividend:15!null security.s_yield:16!null ex_id:38!null ex_name:39!null ex_num_symb:40!null ex_open:41!null ex_close:42!null ex_desc:43 ex_ad_id:44!null ea.ad_id:46!null ea.ad_line1:47 ea.ad_line2:48 ea.ad_zc_code:49!null ea.ad_ctry:50 + │ │ │ │ │ ├── key columns: [44] = [46] │ │ │ │ │ ├── lookup columns are key │ │ │ │ │ ├── cardinality: [0 - 1] │ │ │ │ │ ├── key: () - │ │ │ │ │ ├── fd: ()-->(1,4-16,18-20,22-26,28-32) - │ │ │ │ │ ├── inner-join (lookup company) - │ │ │ │ │ │ ├── columns: s_symb:1!null s_name:4!null s_ex_id:5!null s_co_id:6!null s_num_out:7!null s_start_date:8!null s_exch_date:9!null security.s_pe:10!null security.s_52wk_high:11!null s_52wk_high_date:12!null security.s_52wk_low:13!null s_52wk_low_date:14!null security.s_dividend:15!null security.s_yield:16!null co_id:18!null co_st_id:19!null co_name:20!null co_sp_rate:22!null co_ceo:23!null co_ad_id:24!null co_desc:25!null co_open_date:26!null - │ │ │ │ │ │ ├── key columns: [6] = [18] + │ │ │ │ │ ├── fd: ()-->(1,4-16,38-44,46-50) + │ │ │ │ │ ├── inner-join (lookup exchange) + │ │ │ │ │ │ ├── columns: s_symb:1!null s_name:4!null s_ex_id:5!null s_co_id:6!null s_num_out:7!null s_start_date:8!null s_exch_date:9!null security.s_pe:10!null security.s_52wk_high:11!null s_52wk_high_date:12!null security.s_52wk_low:13!null s_52wk_low_date:14!null security.s_dividend:15!null security.s_yield:16!null ex_id:38!null ex_name:39!null ex_num_symb:40!null ex_open:41!null ex_close:42!null ex_desc:43 ex_ad_id:44!null + │ │ │ │ │ │ ├── key columns: [5] = [38] │ │ │ │ │ │ ├── lookup columns are key │ │ │ │ │ │ ├── cardinality: [0 - 1] │ │ │ │ │ │ ├── key: () - │ │ │ │ │ │ ├── fd: ()-->(1,4-16,18-20,22-26) + │ │ │ │ │ │ ├── fd: ()-->(1,4-16,38-44) │ │ │ │ │ │ ├── scan security │ │ │ │ │ │ │ ├── columns: s_symb:1!null s_name:4!null s_ex_id:5!null s_co_id:6!null s_num_out:7!null s_start_date:8!null s_exch_date:9!null security.s_pe:10!null security.s_52wk_high:11!null s_52wk_high_date:12!null security.s_52wk_low:13!null s_52wk_low_date:14!null security.s_dividend:15!null security.s_yield:16!null │ │ │ │ │ │ │ ├── constraint: /1: [/'SYMB' - /'SYMB'] @@ -3174,29 +3174,29 @@ project │ ├── key: (1) │ ├── fd: ()-->(9), (1)-->(2-4,6,7,10,12), (17)-->(18), (3)==(17), (17)==(3), (20)-->(21), (4)==(20), (20)==(4), (25)-->(28,29), (42)-->(43), (29)==(42), (42)==(29), (6)==(25), (25)==(6) │ ├── ordering: -2 opt(9) [actual: -2] - │ ├── inner-join (lookup security) + │ ├── inner-join (lookup status_type) │ │ ├── columns: t_id:1!null t_dts:2!null t_st_id:3!null t_tt_id:4!null t_s_symb:6!null t_qty:7!null t_ca_id:9!null t_exec_name:10!null trade.t_chrg:12!null st_id:17!null st_name:18!null tt_id:20!null tt_name:21!null s_symb:25!null s_name:28!null s_ex_id:29!null - │ │ ├── key columns: [6] = [25] + │ │ ├── key columns: [3] = [17] │ │ ├── lookup columns are key │ │ ├── cardinality: [0 - 50] │ │ ├── key: (1) │ │ ├── fd: ()-->(9), (17)-->(18), (20)-->(21), (1)-->(2-4,6,7,10,12), (25)-->(28,29), (6)==(25), (25)==(6), (4)==(20), (20)==(4), (3)==(17), (17)==(3) │ │ ├── ordering: -2 opt(9) [actual: -2] │ │ ├── inner-join (lookup trade_type) - │ │ │ ├── columns: t_id:1!null t_dts:2!null t_st_id:3!null t_tt_id:4!null t_s_symb:6!null t_qty:7!null t_ca_id:9!null t_exec_name:10!null trade.t_chrg:12!null st_id:17!null st_name:18!null tt_id:20!null tt_name:21!null + │ │ │ ├── columns: t_id:1!null t_dts:2!null t_st_id:3!null t_tt_id:4!null t_s_symb:6!null t_qty:7!null t_ca_id:9!null t_exec_name:10!null trade.t_chrg:12!null tt_id:20!null tt_name:21!null s_symb:25!null s_name:28!null s_ex_id:29!null │ │ │ ├── key columns: [4] = [20] │ │ │ ├── lookup columns are key │ │ │ ├── cardinality: [0 - 50] │ │ │ ├── key: (1) - │ │ │ ├── fd: ()-->(9), (1)-->(2-4,6,7,10,12), (17)-->(18), (3)==(17), (17)==(3), (20)-->(21), (4)==(20), (20)==(4) + │ │ │ ├── fd: ()-->(9), (20)-->(21), (1)-->(2-4,6,7,10,12), (25)-->(28,29), (6)==(25), (25)==(6), (4)==(20), (20)==(4) │ │ │ ├── ordering: -2 opt(9) [actual: -2] - │ │ │ ├── inner-join (lookup status_type) - │ │ │ │ ├── columns: t_id:1!null t_dts:2!null t_st_id:3!null t_tt_id:4!null t_s_symb:6!null t_qty:7!null t_ca_id:9!null t_exec_name:10!null trade.t_chrg:12!null st_id:17!null st_name:18!null - │ │ │ │ ├── key columns: [3] = [17] + │ │ │ ├── inner-join (lookup security) + │ │ │ │ ├── columns: t_id:1!null t_dts:2!null t_st_id:3!null t_tt_id:4!null t_s_symb:6!null t_qty:7!null t_ca_id:9!null t_exec_name:10!null trade.t_chrg:12!null s_symb:25!null s_name:28!null s_ex_id:29!null + │ │ │ │ ├── key columns: [6] = [25] │ │ │ │ ├── lookup columns are key │ │ │ │ ├── cardinality: [0 - 50] │ │ │ │ ├── key: (1) - │ │ │ │ ├── fd: ()-->(9), (1)-->(2-4,6,7,10,12), (17)-->(18), (3)==(17), (17)==(3) + │ │ │ │ ├── fd: ()-->(9), (1)-->(2-4,6,7,10,12), (25)-->(28,29), (6)==(25), (25)==(6) │ │ │ │ ├── ordering: -2 opt(9) [actual: -2] │ │ │ │ ├── scan trade@secondary │ │ │ │ │ ├── columns: t_id:1!null t_dts:2!null t_st_id:3!null t_tt_id:4!null t_s_symb:6!null t_qty:7!null t_ca_id:9!null t_exec_name:10!null trade.t_chrg:12!null diff --git a/pkg/sql/opt/xform/testdata/external/tpch b/pkg/sql/opt/xform/testdata/external/tpch index 9de991a0912f..0afcf2d9e84c 100644 --- a/pkg/sql/opt/xform/testdata/external/tpch +++ b/pkg/sql/opt/xform/testdata/external/tpch @@ -2176,89 +2176,89 @@ sort └── project ├── columns: s_name:2!null s_address:3!null ├── immutable - └── project + └── inner-join (hash) ├── columns: s_suppkey:1!null s_name:2!null s_address:3!null s_nationkey:4!null n_nationkey:9!null n_name:10!null + ├── multiplicity: left-rows(zero-or-one), right-rows(zero-or-more) ├── immutable ├── key: (1) ├── fd: ()-->(10), (1)-->(2-4), (4)==(9), (9)==(4) - └── inner-join (hash) - ├── columns: s_suppkey:1!null s_name:2!null s_address:3!null s_nationkey:4!null n_nationkey:9!null n_name:10!null ps_suppkey:15!null - ├── multiplicity: left-rows(zero-or-one), right-rows(zero-or-more) - ├── immutable - ├── key: (15) - ├── fd: ()-->(10), (1)-->(2-4), (4)==(9), (9)==(4), (1)==(15), (15)==(1) - ├── inner-join (lookup supplier) - │ ├── columns: s_suppkey:1!null s_name:2!null s_address:3!null s_nationkey:4!null ps_suppkey:15!null - │ ├── key columns: [15] = [1] - │ ├── lookup columns are key - │ ├── immutable - │ ├── key: (15) - │ ├── fd: (1)-->(2-4), (1)==(15), (15)==(1) - │ ├── distinct-on - │ │ ├── columns: ps_suppkey:15!null - │ │ ├── grouping columns: ps_suppkey:15!null - │ │ ├── immutable - │ │ ├── key: (15) - │ │ └── semi-join (lookup part) - │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null - │ │ ├── key columns: [14] = [20] - │ │ ├── lookup columns are key - │ │ ├── immutable - │ │ ├── key: (14,15) - │ │ ├── project - │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null - │ │ │ ├── immutable - │ │ │ ├── key: (14,15) - │ │ │ └── select - │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null sum:47!null - │ │ │ ├── immutable - │ │ │ ├── key: (14,15) - │ │ │ ├── fd: (14,15)-->(16,47) - │ │ │ ├── group-by - │ │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null sum:47!null - │ │ │ │ ├── grouping columns: ps_partkey:14!null ps_suppkey:15!null - │ │ │ │ ├── key: (14,15) - │ │ │ │ ├── fd: (14,15)-->(16,47) - │ │ │ │ ├── inner-join (hash) - │ │ │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null l_partkey:31!null l_suppkey:32!null l_quantity:34!null l_shipdate:40!null - │ │ │ │ │ ├── multiplicity: left-rows(exactly-one), right-rows(zero-or-more) - │ │ │ │ │ ├── fd: (14,15)-->(16), (14)==(31), (31)==(14), (15)==(32), (32)==(15) - │ │ │ │ │ ├── index-join lineitem - │ │ │ │ │ │ ├── columns: l_partkey:31!null l_suppkey:32!null l_quantity:34!null l_shipdate:40!null - │ │ │ │ │ │ └── scan lineitem@l_sd - │ │ │ │ │ │ ├── columns: l_orderkey:30!null l_linenumber:33!null l_shipdate:40!null - │ │ │ │ │ │ ├── constraint: /40/30/33: [/'1994-01-01' - /'1994-12-31'] - │ │ │ │ │ │ ├── key: (30,33) - │ │ │ │ │ │ └── fd: (30,33)-->(40) - │ │ │ │ │ ├── scan partsupp - │ │ │ │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null - │ │ │ │ │ │ ├── key: (14,15) - │ │ │ │ │ │ └── fd: (14,15)-->(16) - │ │ │ │ │ └── filters - │ │ │ │ │ ├── l_partkey:31 = ps_partkey:14 [outer=(14,31), constraints=(/14: (/NULL - ]; /31: (/NULL - ]), fd=(14)==(31), (31)==(14)] - │ │ │ │ │ └── l_suppkey:32 = ps_suppkey:15 [outer=(15,32), constraints=(/15: (/NULL - ]; /32: (/NULL - ]), fd=(15)==(32), (32)==(15)] - │ │ │ │ └── aggregations - │ │ │ │ ├── sum [as=sum:47, outer=(34)] - │ │ │ │ │ └── l_quantity:34 - │ │ │ │ └── const-agg [as=ps_availqty:16, outer=(16)] - │ │ │ │ └── ps_availqty:16 - │ │ │ └── filters - │ │ │ └── ps_availqty:16 > (sum:47 * 0.5) [outer=(16,47), immutable, constraints=(/16: (/NULL - ])] - │ │ └── filters - │ │ └── p_name:21 LIKE 'forest%' [outer=(21), constraints=(/21: [/'forest' - /'foresu'); tight)] - │ └── filters (true) - ├── select - │ ├── columns: n_nationkey:9!null n_name:10!null - │ ├── key: (9) - │ ├── fd: ()-->(10) - │ ├── scan nation - │ │ ├── columns: n_nationkey:9!null n_name:10!null - │ │ ├── key: (9) - │ │ └── fd: (9)-->(10) - │ └── filters - │ └── n_name:10 = 'CANADA' [outer=(10), constraints=(/10: [/'CANADA' - /'CANADA']; tight), fd=()-->(10)] - └── filters - └── s_nationkey:4 = n_nationkey:9 [outer=(4,9), constraints=(/4: (/NULL - ]; /9: (/NULL - ]), fd=(4)==(9), (9)==(4)] + ├── project + │ ├── columns: s_suppkey:1!null s_name:2!null s_address:3!null s_nationkey:4!null + │ ├── immutable + │ ├── key: (1) + │ ├── fd: (1)-->(2-4) + │ └── inner-join (lookup supplier) + │ ├── columns: s_suppkey:1!null s_name:2!null s_address:3!null s_nationkey:4!null ps_suppkey:15!null + │ ├── key columns: [15] = [1] + │ ├── lookup columns are key + │ ├── immutable + │ ├── key: (15) + │ ├── fd: (1)-->(2-4), (1)==(15), (15)==(1) + │ ├── distinct-on + │ │ ├── columns: ps_suppkey:15!null + │ │ ├── grouping columns: ps_suppkey:15!null + │ │ ├── immutable + │ │ ├── key: (15) + │ │ └── semi-join (lookup part) + │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null + │ │ ├── key columns: [14] = [20] + │ │ ├── lookup columns are key + │ │ ├── immutable + │ │ ├── key: (14,15) + │ │ ├── project + │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null + │ │ │ ├── immutable + │ │ │ ├── key: (14,15) + │ │ │ └── select + │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null sum:47!null + │ │ │ ├── immutable + │ │ │ ├── key: (14,15) + │ │ │ ├── fd: (14,15)-->(16,47) + │ │ │ ├── group-by + │ │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null sum:47!null + │ │ │ │ ├── grouping columns: ps_partkey:14!null ps_suppkey:15!null + │ │ │ │ ├── key: (14,15) + │ │ │ │ ├── fd: (14,15)-->(16,47) + │ │ │ │ ├── inner-join (hash) + │ │ │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null l_partkey:31!null l_suppkey:32!null l_quantity:34!null l_shipdate:40!null + │ │ │ │ │ ├── multiplicity: left-rows(exactly-one), right-rows(zero-or-more) + │ │ │ │ │ ├── fd: (14,15)-->(16), (14)==(31), (31)==(14), (15)==(32), (32)==(15) + │ │ │ │ │ ├── index-join lineitem + │ │ │ │ │ │ ├── columns: l_partkey:31!null l_suppkey:32!null l_quantity:34!null l_shipdate:40!null + │ │ │ │ │ │ └── scan lineitem@l_sd + │ │ │ │ │ │ ├── columns: l_orderkey:30!null l_linenumber:33!null l_shipdate:40!null + │ │ │ │ │ │ ├── constraint: /40/30/33: [/'1994-01-01' - /'1994-12-31'] + │ │ │ │ │ │ ├── key: (30,33) + │ │ │ │ │ │ └── fd: (30,33)-->(40) + │ │ │ │ │ ├── scan partsupp + │ │ │ │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null + │ │ │ │ │ │ ├── key: (14,15) + │ │ │ │ │ │ └── fd: (14,15)-->(16) + │ │ │ │ │ └── filters + │ │ │ │ │ ├── l_partkey:31 = ps_partkey:14 [outer=(14,31), constraints=(/14: (/NULL - ]; /31: (/NULL - ]), fd=(14)==(31), (31)==(14)] + │ │ │ │ │ └── l_suppkey:32 = ps_suppkey:15 [outer=(15,32), constraints=(/15: (/NULL - ]; /32: (/NULL - ]), fd=(15)==(32), (32)==(15)] + │ │ │ │ └── aggregations + │ │ │ │ ├── sum [as=sum:47, outer=(34)] + │ │ │ │ │ └── l_quantity:34 + │ │ │ │ └── const-agg [as=ps_availqty:16, outer=(16)] + │ │ │ │ └── ps_availqty:16 + │ │ │ └── filters + │ │ │ └── ps_availqty:16 > (sum:47 * 0.5) [outer=(16,47), immutable, constraints=(/16: (/NULL - ])] + │ │ └── filters + │ │ └── p_name:21 LIKE 'forest%' [outer=(21), constraints=(/21: [/'forest' - /'foresu'); tight)] + │ └── filters (true) + ├── select + │ ├── columns: n_nationkey:9!null n_name:10!null + │ ├── key: (9) + │ ├── fd: ()-->(10) + │ ├── scan nation + │ │ ├── columns: n_nationkey:9!null n_name:10!null + │ │ ├── key: (9) + │ │ └── fd: (9)-->(10) + │ └── filters + │ └── n_name:10 = 'CANADA' [outer=(10), constraints=(/10: [/'CANADA' - /'CANADA']; tight), fd=()-->(10)] + └── filters + └── s_nationkey:4 = n_nationkey:9 [outer=(4,9), constraints=(/4: (/NULL - ]; /9: (/NULL - ]), fd=(4)==(9), (9)==(4)] # -------------------------------------------------- # Q21 diff --git a/pkg/sql/opt/xform/testdata/external/tpch-no-stats b/pkg/sql/opt/xform/testdata/external/tpch-no-stats index 2fb534946d68..e24e1c771c79 100644 --- a/pkg/sql/opt/xform/testdata/external/tpch-no-stats +++ b/pkg/sql/opt/xform/testdata/external/tpch-no-stats @@ -980,26 +980,26 @@ sort ├── project │ ├── columns: o_year:57 amount:58!null n_name:53!null │ ├── immutable - │ ├── inner-join (lookup nation) + │ ├── inner-join (lookup part) │ │ ├── columns: p_partkey:1!null p_name:2!null s_suppkey:11!null s_nationkey:14!null l_orderkey:19!null l_partkey:20!null l_suppkey:21!null l_quantity:23!null l_extendedprice:24!null l_discount:25!null ps_partkey:36!null ps_suppkey:37!null ps_supplycost:39!null o_orderkey:42!null o_orderdate:46!null n_nationkey:52!null n_name:53!null - │ │ ├── key columns: [14] = [52] + │ │ ├── key columns: [20] = [1] │ │ ├── lookup columns are key │ │ ├── fd: (1)-->(2), (11)-->(14), (36,37)-->(39), (21)==(11,37), (37)==(11,21), (20)==(1,36), (36)==(1,20), (42)-->(46), (19)==(42), (42)==(19), (11)==(21,37), (52)-->(53), (14)==(52), (52)==(14), (1)==(20,36) - │ │ ├── inner-join (lookup orders) - │ │ │ ├── columns: p_partkey:1!null p_name:2!null s_suppkey:11!null s_nationkey:14!null l_orderkey:19!null l_partkey:20!null l_suppkey:21!null l_quantity:23!null l_extendedprice:24!null l_discount:25!null ps_partkey:36!null ps_suppkey:37!null ps_supplycost:39!null o_orderkey:42!null o_orderdate:46!null - │ │ │ ├── key columns: [19] = [42] + │ │ ├── inner-join (lookup nation) + │ │ │ ├── columns: s_suppkey:11!null s_nationkey:14!null l_orderkey:19!null l_partkey:20!null l_suppkey:21!null l_quantity:23!null l_extendedprice:24!null l_discount:25!null ps_partkey:36!null ps_suppkey:37!null ps_supplycost:39!null o_orderkey:42!null o_orderdate:46!null n_nationkey:52!null n_name:53!null + │ │ │ ├── key columns: [14] = [52] │ │ │ ├── lookup columns are key - │ │ │ ├── fd: (1)-->(2), (11)-->(14), (36,37)-->(39), (21)==(11,37), (37)==(11,21), (20)==(1,36), (36)==(1,20), (42)-->(46), (19)==(42), (42)==(19), (11)==(21,37), (1)==(20,36) - │ │ │ ├── inner-join (lookup part) - │ │ │ │ ├── columns: p_partkey:1!null p_name:2!null s_suppkey:11!null s_nationkey:14!null l_orderkey:19!null l_partkey:20!null l_suppkey:21!null l_quantity:23!null l_extendedprice:24!null l_discount:25!null ps_partkey:36!null ps_suppkey:37!null ps_supplycost:39!null - │ │ │ │ ├── key columns: [20] = [1] + │ │ │ ├── fd: (11)-->(14), (36,37)-->(39), (21)==(11,37), (37)==(11,21), (20)==(36), (36)==(20), (42)-->(46), (19)==(42), (42)==(19), (11)==(21,37), (52)-->(53), (14)==(52), (52)==(14) + │ │ │ ├── inner-join (lookup supplier) + │ │ │ │ ├── columns: s_suppkey:11!null s_nationkey:14!null l_orderkey:19!null l_partkey:20!null l_suppkey:21!null l_quantity:23!null l_extendedprice:24!null l_discount:25!null ps_partkey:36!null ps_suppkey:37!null ps_supplycost:39!null o_orderkey:42!null o_orderdate:46!null + │ │ │ │ ├── key columns: [21] = [11] │ │ │ │ ├── lookup columns are key - │ │ │ │ ├── fd: (1)-->(2), (11)-->(14), (36,37)-->(39), (21)==(11,37), (37)==(11,21), (20)==(1,36), (36)==(1,20), (11)==(21,37), (1)==(20,36) - │ │ │ │ ├── inner-join (lookup supplier) - │ │ │ │ │ ├── columns: s_suppkey:11!null s_nationkey:14!null l_orderkey:19!null l_partkey:20!null l_suppkey:21!null l_quantity:23!null l_extendedprice:24!null l_discount:25!null ps_partkey:36!null ps_suppkey:37!null ps_supplycost:39!null - │ │ │ │ │ ├── key columns: [21] = [11] + │ │ │ │ ├── fd: (11)-->(14), (36,37)-->(39), (21)==(11,37), (37)==(11,21), (20)==(36), (36)==(20), (42)-->(46), (19)==(42), (42)==(19), (11)==(21,37) + │ │ │ │ ├── inner-join (lookup orders) + │ │ │ │ │ ├── columns: l_orderkey:19!null l_partkey:20!null l_suppkey:21!null l_quantity:23!null l_extendedprice:24!null l_discount:25!null ps_partkey:36!null ps_suppkey:37!null ps_supplycost:39!null o_orderkey:42!null o_orderdate:46!null + │ │ │ │ │ ├── key columns: [19] = [42] │ │ │ │ │ ├── lookup columns are key - │ │ │ │ │ ├── fd: (11)-->(14), (36,37)-->(39), (21)==(11,37), (37)==(11,21), (20)==(36), (36)==(20), (11)==(21,37) + │ │ │ │ │ ├── fd: (36,37)-->(39), (21)==(37), (37)==(21), (20)==(36), (36)==(20), (42)-->(46), (19)==(42), (42)==(19) │ │ │ │ │ ├── inner-join (hash) │ │ │ │ │ │ ├── columns: l_orderkey:19!null l_partkey:20!null l_suppkey:21!null l_quantity:23!null l_extendedprice:24!null l_discount:25!null ps_partkey:36!null ps_suppkey:37!null ps_supplycost:39!null │ │ │ │ │ │ ├── multiplicity: left-rows(exactly-one), right-rows(zero-or-more) @@ -1014,10 +1014,10 @@ sort │ │ │ │ │ │ ├── ps_suppkey:37 = l_suppkey:21 [outer=(21,37), constraints=(/21: (/NULL - ]; /37: (/NULL - ]), fd=(21)==(37), (37)==(21)] │ │ │ │ │ │ └── ps_partkey:36 = l_partkey:20 [outer=(20,36), constraints=(/20: (/NULL - ]; /36: (/NULL - ]), fd=(20)==(36), (36)==(20)] │ │ │ │ │ └── filters (true) - │ │ │ │ └── filters - │ │ │ │ └── p_name:2 LIKE '%green%' [outer=(2), constraints=(/2: (/NULL - ])] + │ │ │ │ └── filters (true) │ │ │ └── filters (true) - │ │ └── filters (true) + │ │ └── filters + │ │ └── p_name:2 LIKE '%green%' [outer=(2), constraints=(/2: (/NULL - ])] │ └── projections │ ├── extract('year', o_orderdate:46) [as=o_year:57, outer=(46), immutable] │ └── (l_extendedprice:24 * (1.0 - l_discount:25)) - (ps_supplycost:39 * l_quantity:23) [as=amount:58, outer=(23-25,39), immutable] @@ -2109,79 +2109,79 @@ sort └── project ├── columns: s_name:2!null s_address:3!null ├── immutable - └── project + └── inner-join (lookup nation) ├── columns: s_suppkey:1!null s_name:2!null s_address:3!null s_nationkey:4!null n_nationkey:9!null n_name:10!null + ├── key columns: [4] = [9] + ├── lookup columns are key ├── immutable ├── key: (1) ├── fd: ()-->(10), (1)-->(2-4), (4)==(9), (9)==(4) - └── inner-join (lookup nation) - ├── columns: s_suppkey:1!null s_name:2!null s_address:3!null s_nationkey:4!null n_nationkey:9!null n_name:10!null ps_suppkey:15!null - ├── key columns: [4] = [9] - ├── lookup columns are key - ├── immutable - ├── key: (15) - ├── fd: ()-->(10), (1)-->(2-4), (4)==(9), (9)==(4), (1)==(15), (15)==(1) - ├── inner-join (lookup supplier) - │ ├── columns: s_suppkey:1!null s_name:2!null s_address:3!null s_nationkey:4!null ps_suppkey:15!null - │ ├── key columns: [15] = [1] - │ ├── lookup columns are key - │ ├── immutable - │ ├── key: (15) - │ ├── fd: (1)-->(2-4), (1)==(15), (15)==(1) - │ ├── distinct-on - │ │ ├── columns: ps_suppkey:15!null - │ │ ├── grouping columns: ps_suppkey:15!null - │ │ ├── immutable - │ │ ├── key: (15) - │ │ └── semi-join (lookup part) - │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null - │ │ ├── key columns: [14] = [20] - │ │ ├── lookup columns are key - │ │ ├── immutable - │ │ ├── key: (14,15) - │ │ ├── project - │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null - │ │ │ ├── immutable - │ │ │ ├── key: (14,15) - │ │ │ └── select - │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null sum:47!null - │ │ │ ├── immutable - │ │ │ ├── key: (14,15) - │ │ │ ├── fd: (14,15)-->(16,47) - │ │ │ ├── group-by - │ │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null sum:47!null - │ │ │ │ ├── grouping columns: ps_partkey:14!null ps_suppkey:15!null - │ │ │ │ ├── key: (14,15) - │ │ │ │ ├── fd: (14,15)-->(16,47) - │ │ │ │ ├── inner-join (hash) - │ │ │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null l_partkey:31!null l_suppkey:32!null l_quantity:34!null l_shipdate:40!null - │ │ │ │ │ ├── multiplicity: left-rows(zero-or-more), right-rows(exactly-one) - │ │ │ │ │ ├── fd: (14,15)-->(16), (14)==(31), (31)==(14), (15)==(32), (32)==(15) - │ │ │ │ │ ├── scan partsupp - │ │ │ │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null - │ │ │ │ │ │ ├── key: (14,15) - │ │ │ │ │ │ └── fd: (14,15)-->(16) - │ │ │ │ │ ├── select - │ │ │ │ │ │ ├── columns: l_partkey:31!null l_suppkey:32!null l_quantity:34!null l_shipdate:40!null - │ │ │ │ │ │ ├── scan lineitem - │ │ │ │ │ │ │ └── columns: l_partkey:31!null l_suppkey:32!null l_quantity:34!null l_shipdate:40!null - │ │ │ │ │ │ └── filters - │ │ │ │ │ │ └── (l_shipdate:40 >= '1994-01-01') AND (l_shipdate:40 < '1995-01-01') [outer=(40), constraints=(/40: [/'1994-01-01' - /'1994-12-31']; tight)] - │ │ │ │ │ └── filters - │ │ │ │ │ ├── l_partkey:31 = ps_partkey:14 [outer=(14,31), constraints=(/14: (/NULL - ]; /31: (/NULL - ]), fd=(14)==(31), (31)==(14)] - │ │ │ │ │ └── l_suppkey:32 = ps_suppkey:15 [outer=(15,32), constraints=(/15: (/NULL - ]; /32: (/NULL - ]), fd=(15)==(32), (32)==(15)] - │ │ │ │ └── aggregations - │ │ │ │ ├── sum [as=sum:47, outer=(34)] - │ │ │ │ │ └── l_quantity:34 - │ │ │ │ └── const-agg [as=ps_availqty:16, outer=(16)] - │ │ │ │ └── ps_availqty:16 - │ │ │ └── filters - │ │ │ └── ps_availqty:16 > (sum:47 * 0.5) [outer=(16,47), immutable, constraints=(/16: (/NULL - ])] - │ │ └── filters - │ │ └── p_name:21 LIKE 'forest%' [outer=(21), constraints=(/21: [/'forest' - /'foresu'); tight)] - │ └── filters (true) - └── filters - └── n_name:10 = 'CANADA' [outer=(10), constraints=(/10: [/'CANADA' - /'CANADA']; tight), fd=()-->(10)] + ├── project + │ ├── columns: s_suppkey:1!null s_name:2!null s_address:3!null s_nationkey:4!null + │ ├── immutable + │ ├── key: (1) + │ ├── fd: (1)-->(2-4) + │ └── inner-join (lookup supplier) + │ ├── columns: s_suppkey:1!null s_name:2!null s_address:3!null s_nationkey:4!null ps_suppkey:15!null + │ ├── key columns: [15] = [1] + │ ├── lookup columns are key + │ ├── immutable + │ ├── key: (15) + │ ├── fd: (1)-->(2-4), (1)==(15), (15)==(1) + │ ├── distinct-on + │ │ ├── columns: ps_suppkey:15!null + │ │ ├── grouping columns: ps_suppkey:15!null + │ │ ├── immutable + │ │ ├── key: (15) + │ │ └── semi-join (lookup part) + │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null + │ │ ├── key columns: [14] = [20] + │ │ ├── lookup columns are key + │ │ ├── immutable + │ │ ├── key: (14,15) + │ │ ├── project + │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null + │ │ │ ├── immutable + │ │ │ ├── key: (14,15) + │ │ │ └── select + │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null sum:47!null + │ │ │ ├── immutable + │ │ │ ├── key: (14,15) + │ │ │ ├── fd: (14,15)-->(16,47) + │ │ │ ├── group-by + │ │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null sum:47!null + │ │ │ │ ├── grouping columns: ps_partkey:14!null ps_suppkey:15!null + │ │ │ │ ├── key: (14,15) + │ │ │ │ ├── fd: (14,15)-->(16,47) + │ │ │ │ ├── inner-join (hash) + │ │ │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null l_partkey:31!null l_suppkey:32!null l_quantity:34!null l_shipdate:40!null + │ │ │ │ │ ├── multiplicity: left-rows(zero-or-more), right-rows(exactly-one) + │ │ │ │ │ ├── fd: (14,15)-->(16), (14)==(31), (31)==(14), (15)==(32), (32)==(15) + │ │ │ │ │ ├── scan partsupp + │ │ │ │ │ │ ├── columns: ps_partkey:14!null ps_suppkey:15!null ps_availqty:16!null + │ │ │ │ │ │ ├── key: (14,15) + │ │ │ │ │ │ └── fd: (14,15)-->(16) + │ │ │ │ │ ├── select + │ │ │ │ │ │ ├── columns: l_partkey:31!null l_suppkey:32!null l_quantity:34!null l_shipdate:40!null + │ │ │ │ │ │ ├── scan lineitem + │ │ │ │ │ │ │ └── columns: l_partkey:31!null l_suppkey:32!null l_quantity:34!null l_shipdate:40!null + │ │ │ │ │ │ └── filters + │ │ │ │ │ │ └── (l_shipdate:40 >= '1994-01-01') AND (l_shipdate:40 < '1995-01-01') [outer=(40), constraints=(/40: [/'1994-01-01' - /'1994-12-31']; tight)] + │ │ │ │ │ └── filters + │ │ │ │ │ ├── l_partkey:31 = ps_partkey:14 [outer=(14,31), constraints=(/14: (/NULL - ]; /31: (/NULL - ]), fd=(14)==(31), (31)==(14)] + │ │ │ │ │ └── l_suppkey:32 = ps_suppkey:15 [outer=(15,32), constraints=(/15: (/NULL - ]; /32: (/NULL - ]), fd=(15)==(32), (32)==(15)] + │ │ │ │ └── aggregations + │ │ │ │ ├── sum [as=sum:47, outer=(34)] + │ │ │ │ │ └── l_quantity:34 + │ │ │ │ └── const-agg [as=ps_availqty:16, outer=(16)] + │ │ │ │ └── ps_availqty:16 + │ │ │ └── filters + │ │ │ └── ps_availqty:16 > (sum:47 * 0.5) [outer=(16,47), immutable, constraints=(/16: (/NULL - ])] + │ │ └── filters + │ │ └── p_name:21 LIKE 'forest%' [outer=(21), constraints=(/21: [/'forest' - /'foresu'); tight)] + │ └── filters (true) + └── filters + └── n_name:10 = 'CANADA' [outer=(10), constraints=(/10: [/'CANADA' - /'CANADA']; tight), fd=()-->(10)] # -------------------------------------------------- # Q21 diff --git a/pkg/sql/opt/xform/testdata/rules/combo b/pkg/sql/opt/xform/testdata/rules/combo index 390ed8d6a560..9870f839b017 100644 --- a/pkg/sql/opt/xform/testdata/rules/combo +++ b/pkg/sql/opt/xform/testdata/rules/combo @@ -94,23 +94,6 @@ Source expression: ├── a:1 = x:6 [outer=(1,6), constraints=(/1: (/NULL - ]; /6: (/NULL - ]), fd=(1)==(6), (6)==(1)] └── b:2 = y:7 [outer=(2,7), constraints=(/2: (/NULL - ]; /7: (/NULL - ]), fd=(2)==(7), (7)==(2)] -No new expressions. - -================================================================================ -CommuteJoin -================================================================================ -Source expression: - inner-join (hash) - ├── columns: a:1!null b:2!null c:3 x:6!null y:7!null z:8 - ├── fd: (1)==(6), (6)==(1), (2)==(7), (7)==(2) - ├── scan abc - │ └── columns: a:1 b:2 c:3 - ├── scan xyz - │ └── columns: x:6 y:7 z:8 - └── filters - ├── a:1 = x:6 [outer=(1,6), constraints=(/1: (/NULL - ]; /6: (/NULL - ]), fd=(1)==(6), (6)==(1)] - └── b:2 = y:7 [outer=(2,7), constraints=(/2: (/NULL - ]; /7: (/NULL - ]), fd=(2)==(7), (7)==(2)] - New expression 1 of 1: inner-join (hash) ├── columns: a:1!null b:2!null c:3 x:6!null y:7!null z:8 @@ -176,23 +159,6 @@ New expression 1 of 1: │ └── columns: a:1 b:2 c:3 └── filters (true) -================================================================================ -CommuteJoin -================================================================================ -Source expression: - inner-join (hash) - ├── columns: a:1!null b:2!null c:3 x:6!null y:7!null z:8 - ├── fd: (1)==(6), (6)==(1), (2)==(7), (7)==(2) - ├── scan xyz - │ └── columns: x:6 y:7 z:8 - ├── scan abc - │ └── columns: a:1 b:2 c:3 - └── filters - ├── a:1 = x:6 [outer=(1,6), constraints=(/1: (/NULL - ]; /6: (/NULL - ]), fd=(1)==(6), (6)==(1)] - └── b:2 = y:7 [outer=(2,7), constraints=(/2: (/NULL - ]; /7: (/NULL - ]), fd=(2)==(7), (7)==(2)] - -No new expressions. - ================================================================================ GenerateMergeJoins ================================================================================ diff --git a/pkg/sql/opt/xform/testdata/rules/join b/pkg/sql/opt/xform/testdata/rules/join index ddaf7e842e3c..ed50992a0572 100644 --- a/pkg/sql/opt/xform/testdata/rules/join +++ b/pkg/sql/opt/xform/testdata/rules/join @@ -181,7 +181,7 @@ memo expect=ReorderJoins SELECT * FROM abc, stu, xyz WHERE abc.a=stu.s AND stu.s=xyz.x ---- memo (optimized, ~36KB, required=[presentation: a:1,b:2,c:3,s:6,t:7,u:8,x:10,y:11,z:12]) - ├── G1: (inner-join G2 G3 G4) (inner-join G5 G6 G7) (inner-join G8 G9 G7) (inner-join G3 G2 G4) (merge-join G2 G3 G10 inner-join,+1,+6) (inner-join G6 G5 G7) (merge-join G5 G6 G10 inner-join,+6,+10) (inner-join G9 G8 G7) (merge-join G8 G9 G10 inner-join,+6,+10) (lookup-join G8 G10 xyz@xy,keyCols=[6],outCols=(1-3,6-8,10-12)) (merge-join G3 G2 G10 inner-join,+6,+1) (lookup-join G3 G10 abc@ab,keyCols=[6],outCols=(1-3,6-8,10-12)) (merge-join G6 G5 G10 inner-join,+10,+6) (lookup-join G6 G10 stu,keyCols=[10],outCols=(1-3,6-8,10-12)) (merge-join G9 G8 G10 inner-join,+10,+6) + ├── G1: (inner-join G2 G3 G4) (inner-join G3 G2 G4) (inner-join G5 G6 G7) (inner-join G6 G5 G7) (inner-join G8 G9 G7) (inner-join G9 G8 G7) (merge-join G2 G3 G10 inner-join,+1,+6) (merge-join G3 G2 G10 inner-join,+6,+1) (lookup-join G3 G10 abc@ab,keyCols=[6],outCols=(1-3,6-8,10-12)) (merge-join G5 G6 G10 inner-join,+6,+10) (merge-join G6 G5 G10 inner-join,+10,+6) (lookup-join G6 G10 stu,keyCols=[10],outCols=(1-3,6-8,10-12)) (merge-join G8 G9 G10 inner-join,+6,+10) (lookup-join G8 G10 xyz@xy,keyCols=[6],outCols=(1-3,6-8,10-12)) (merge-join G9 G8 G10 inner-join,+10,+6) │ └── [presentation: a:1,b:2,c:3,s:6,t:7,u:8,x:10,y:11,z:12] │ ├── best: (merge-join G5="[ordering: +6]" G6="[ordering: +(1|10)]" G10 inner-join,+6,+10) │ └── cost: 12980.08 @@ -316,7 +316,7 @@ memo (optimized, ~34KB, required=[presentation: pid1:1,cid1:2,gcid1:3,gca1:4,ca1 │ └── [] │ ├── best: (project G2 G3 pid1 cid1 gcid1 gca1 ca1 pa1) │ └── cost: 2767.07 - ├── G2: (inner-join G4 G5 G6) (inner-join G7 G8 G9) (inner-join G10 G11 G9) (inner-join G5 G4 G6) (merge-join G4 G5 G12 inner-join,+1,+10) (lookup-join G4 G12 parent1,keyCols=[1],outCols=(1-4,6-8,10,11)) (inner-join G8 G7 G9) (merge-join G7 G8 G12 inner-join,+1,+2,+6,+7) (inner-join G11 G10 G9) (merge-join G10 G11 G12 inner-join,+6,+7,+1,+2) (merge-join G5 G4 G12 inner-join,+10,+1) (merge-join G8 G7 G12 inner-join,+6,+7,+1,+2) (lookup-join G8 G12 grandchild1,keyCols=[6 7],outCols=(1-4,6-8,10,11)) (merge-join G11 G10 G12 inner-join,+1,+2,+6,+7) (lookup-join G11 G12 child1,keyCols=[1 2],outCols=(1-4,6-8,10,11)) + ├── G2: (inner-join G4 G5 G6) (inner-join G7 G8 G9) (inner-join G8 G7 G9) (inner-join G10 G11 G9) (inner-join G11 G10 G9) (inner-join G5 G4 G6) (merge-join G4 G5 G12 inner-join,+1,+10) (lookup-join G4 G12 parent1,keyCols=[1],outCols=(1-4,6-8,10,11)) (merge-join G7 G8 G12 inner-join,+1,+2,+6,+7) (merge-join G8 G7 G12 inner-join,+6,+7,+1,+2) (lookup-join G8 G12 grandchild1,keyCols=[6 7],outCols=(1-4,6-8,10,11)) (merge-join G10 G11 G12 inner-join,+6,+7,+1,+2) (merge-join G11 G10 G12 inner-join,+1,+2,+6,+7) (lookup-join G11 G12 child1,keyCols=[1 2],outCols=(1-4,6-8,10,11)) (merge-join G5 G4 G12 inner-join,+10,+1) │ ├── [ordering: +(1|6|10)] │ │ ├── best: (lookup-join G4="[ordering: +(1|6)]" G12 parent1,keyCols=[1],outCols=(1-4,6-8,10,11)) │ │ └── cost: 2766.06 @@ -597,7 +597,12 @@ Source expression: └── filters └── a = s -No new expressions. +New expression 1 of 1: + inner-join (hash) + ├── scan stu + ├── scan abc + └── filters + └── a = s ---- ---- @@ -673,7 +678,16 @@ Source expression: └── filters └── b = y -No new expressions. +New expression 1 of 1: + inner-join (hash) + ├── inner-join (hash) + │ ├── scan abc + │ ├── scan stu + │ └── filters + │ └── s = a + ├── scan xyz + └── filters + └── b = y ================================================================================ ReorderJoins @@ -688,7 +702,7 @@ Source expression: └── filters └── b = y -New expression 1 of 1: +New expression 1 of 3: inner-join (hash) ├── scan stu ├── inner-join (hash) @@ -698,6 +712,27 @@ New expression 1 of 1: │ └── b = y └── filters └── s = a + +New expression 2 of 3: + inner-join (hash) + ├── inner-join (hash) + │ ├── scan abc + │ ├── scan xyz + │ └── filters + │ └── b = y + ├── scan stu + └── filters + └── s = a + +New expression 3 of 3: + inner-join (hash) + ├── scan xyz + ├── inner-join (merge) + │ ├── scan stu + │ ├── scan abc@ab + │ └── filters (true) + └── filters + └── b = y ---- ---- @@ -864,7 +899,17 @@ Source expression: └── filters └── small.m = large.m -No new expressions. +New expression 1 of 1: + project + └── left-join (hash) + ├── scan small + ├── inner-join (hash) + │ ├── scan medium + │ ├── scan large + │ └── filters + │ └── large.n = medium.n + └── filters + └── small.m = large.m ================================================================================ ReorderJoins @@ -938,7 +983,7 @@ Source expression: ├── scan xyz └── filters (true) -New expression 1 of 1: +New expression 1 of 2: project └── inner-join (cross) ├── select @@ -956,6 +1001,22 @@ New expression 1 of 1: ├── scan xyz └── filters (true) +New expression 2 of 2: + project + └── inner-join (cross) + ├── inner-join (hash) + │ ├── scan small + │ ├── right-join (hash) + │ │ ├── scan large + │ │ ├── scan medium + │ │ └── filters + │ │ └── large.m = medium.m + │ └── filters + │ ├── medium.n = small.n + │ └── (small.m = large.n) OR (large.n IS NULL) + ├── scan xyz + └── filters (true) + ================================================================================ ReorderJoins ================================================================================ @@ -977,7 +1038,23 @@ Source expression: ├── scan xyz └── filters (true) -No new expressions. +New expression 1 of 1: + project + └── inner-join (cross) + ├── scan xyz + ├── select + │ ├── right-join (hash) + │ │ ├── scan large + │ │ ├── inner-join (hash) + │ │ │ ├── scan medium + │ │ │ ├── scan small + │ │ │ └── filters + │ │ │ └── medium.n = small.n + │ │ └── filters + │ │ └── large.m = medium.m + │ └── filters + │ └── (small.m = large.n) OR (large.n IS NULL) + └── filters (true) ---- ---- @@ -1002,7 +1079,16 @@ Source expression: └── filters └── b = y -No new expressions. +New expression 1 of 1: + full-join (hash) + ├── full-join (hash) + │ ├── scan stu + │ ├── scan abc + │ └── filters + │ └── s = a + ├── scan xyz + └── filters + └── b = y ================================================================================ ReorderJoins @@ -1017,7 +1103,7 @@ Source expression: └── filters └── b = y -New expression 1 of 1: +New expression 1 of 3: full-join (hash) ├── full-join (hash) │ ├── scan abc @@ -1027,6 +1113,27 @@ New expression 1 of 1: ├── scan stu └── filters └── s = a + +New expression 2 of 3: + full-join (hash) + ├── scan stu + ├── full-join (hash) + │ ├── scan abc + │ ├── scan xyz + │ └── filters + │ └── b = y + └── filters + └── s = a + +New expression 3 of 3: + full-join (hash) + ├── scan xyz + ├── full-join (merge) + │ ├── scan abc@ab + │ ├── scan stu + │ └── filters (true) + └── filters + └── b = y ---- ---- @@ -1055,7 +1162,16 @@ Source expression: └── filters └── a = x -No new expressions. +New expression 1 of 1: + full-join (hash) + ├── scan abc + ├── full-join (hash) + │ ├── scan xyz + │ ├── scan stu + │ └── filters + │ └── t = y + └── filters + └── a = x ================================================================================ ReorderJoins @@ -1071,7 +1187,18 @@ Source expression: └── filters └── a = x -New expression 1 of 1: +New expression 1 of 3: + full-join (hash) + ├── full-join (hash) + │ ├── scan stu + │ ├── scan xyz + │ └── filters + │ └── t = y + ├── scan abc + └── filters + └── a = x + +New expression 2 of 3: full-join (hash) ├── scan stu ├── full-join (hash) @@ -1081,6 +1208,17 @@ New expression 1 of 1: │ └── a = x └── filters └── t = y + +New expression 3 of 3: + full-join (hash) + ├── full-join (hash) + │ ├── scan abc + │ ├── scan xyz + │ └── filters + │ └── a = x + ├── scan stu + └── filters + └── t = y ---- ---- @@ -1154,7 +1292,16 @@ Source expression: └── filters └── b = y -No new expressions. +New expression 1 of 1: + left-join (hash) + ├── full-join (hash) + │ ├── scan stu + │ ├── scan abc + │ └── filters + │ └── s = a + ├── scan xyz + └── filters + └── b = y ================================================================================ ReorderJoins @@ -1169,7 +1316,7 @@ Source expression: └── filters └── b = y -New expression 1 of 1: +New expression 1 of 2: full-join (hash) ├── left-join (hash) │ ├── scan abc @@ -1179,16 +1326,23 @@ New expression 1 of 1: ├── scan stu └── filters └── s = a + +New expression 2 of 2: + full-join (hash) + ├── scan stu + ├── left-join (hash) + │ ├── scan abc + │ ├── scan xyz + │ └── filters + │ └── b = y + └── filters + └── s = a ---- ---- -# -------------------------------------------------- -# CommuteJoin -# -------------------------------------------------- - # Verify that the reversed join expressions get added to the memo, and there # are no duplicates. -memo expect=CommuteJoin +memo expect=ReorderJoins SELECT * FROM abc JOIN xyz ON a=z ---- memo (optimized, ~10KB, required=[presentation: a:1,b:2,c:3,x:6,y:7,z:8]) @@ -1216,7 +1370,7 @@ memo (optimized, ~10KB, required=[presentation: a:1,b:2,c:3,x:6,y:7,z:8]) ├── G7: (variable a) └── G8: (variable z) -memo expect=CommuteJoin +memo expect=ReorderJoins SELECT * FROM abc FULL OUTER JOIN xyz ON a=z ---- memo (optimized, ~9KB, required=[presentation: a:1,b:2,c:3,x:6,y:7,z:8]) @@ -1245,7 +1399,7 @@ memo (optimized, ~9KB, required=[presentation: a:1,b:2,c:3,x:6,y:7,z:8]) └── G8: (variable z) # Verify that we swap to get the smaller side on the right. -opt expect=CommuteJoin +opt expect=ReorderJoins SELECT * FROM abc INNER JOIN xyz ON a=c WHERE b=1 ---- inner-join (cross) @@ -1265,7 +1419,7 @@ inner-join (cross) └── filters (true) # Verify that the hash join hint prevents swapping the sides. -opt expect=CommuteJoin +opt expect-not=ReorderJoins SELECT * FROM abc INNER HASH JOIN xyz ON a=c WHERE b=1 ---- inner-join (cross) @@ -1285,7 +1439,7 @@ inner-join (cross) │ └── columns: x:6 y:7 z:8 └── filters (true) -opt expect=CommuteJoin +opt expect=ReorderJoins SELECT * FROM (SELECT * FROM abc WHERE b=1) FULL OUTER JOIN xyz ON a=z ---- full-join (hash) @@ -1302,11 +1456,11 @@ full-join (hash) # Verify that commuting works correctly when there is a lookup join hint # (specifically that it returns the original expression and flags when applied # twice; if it didn't, we'd see more inner-join expressions). -memo expect=CommuteJoin +memo expect=ReorderJoins SELECT * FROM abc INNER LOOKUP JOIN xyz ON a=x ---- memo (optimized, ~10KB, required=[presentation: a:1,b:2,c:3,x:6,y:7,z:8]) - ├── G1: (inner-join G2 G3 G4) (inner-join G3 G2 G4) (lookup-join G2 G5 xyz@xy,keyCols=[1],outCols=(1-3,6-8)) + ├── G1: (inner-join G2 G3 G4) (lookup-join G2 G5 xyz@xy,keyCols=[1],outCols=(1-3,6-8)) │ └── [presentation: a:1,b:2,c:3,x:6,y:7,z:8] │ ├── best: (lookup-join G2 G5 xyz@xy,keyCols=[1],outCols=(1-3,6-8)) │ └── cost: 23150.03 @@ -1324,6 +1478,63 @@ memo (optimized, ~10KB, required=[presentation: a:1,b:2,c:3,x:6,y:7,z:8]) ├── G7: (variable a) └── G8: (variable x) +# Verify that setting the join limit to 1 allows only commutation. +exploretrace rule=ReorderJoins format=hide-all join-limit=1 +SELECT * FROM abc +INNER JOIN stu ON s = a +INNER JOIN xyz ON s = x +---- +---- +================================================================================ +ReorderJoins +================================================================================ +Source expression: + inner-join (hash) + ├── inner-join (hash) + │ ├── scan abc + │ ├── scan stu + │ └── filters + │ └── s = a + ├── scan xyz + └── filters + └── s = x + +New expression 1 of 1: + inner-join (hash) + ├── inner-join (hash) + │ ├── scan stu + │ ├── scan abc + │ └── filters + │ └── s = a + ├── scan xyz + └── filters + └── s = x + +================================================================================ +ReorderJoins +================================================================================ +Source expression: + inner-join (hash) + ├── inner-join (merge) + │ ├── scan abc@ab + │ ├── scan stu + │ └── filters (true) + ├── scan xyz + └── filters + └── s = x + +New expression 1 of 1: + inner-join (hash) + ├── scan xyz + ├── inner-join (merge) + │ ├── scan abc@ab + │ ├── scan stu + │ └── filters (true) + └── filters + └── s = x +---- +---- + # -------------------------------------------------- # CommuteLeftJoin # -------------------------------------------------- @@ -1469,8 +1680,8 @@ memo (optimized, ~12KB, required=[presentation: a:1,b:2,c:3,x:6,y:7,z:8]) memo SELECT * FROM abc INNER HASH JOIN xyz ON a=x ---- -memo (optimized, ~9KB, required=[presentation: a:1,b:2,c:3,x:6,y:7,z:8]) - ├── G1: (inner-join G2 G3 G4) (inner-join G3 G2 G4) +memo (optimized, ~8KB, required=[presentation: a:1,b:2,c:3,x:6,y:7,z:8]) + ├── G1: (inner-join G2 G3 G4) │ └── [presentation: a:1,b:2,c:3,x:6,y:7,z:8] │ ├── best: (inner-join G2 G3 G4) │ └── cost: 2180.06 @@ -2237,7 +2448,7 @@ memo SELECT a,b,n,m FROM small INNER HASH JOIN abcd ON a=m ---- memo (optimized, ~8KB, required=[presentation: a:5,b:6,n:2,m:1]) - ├── G1: (inner-join G2 G3 G4) (inner-join G3 G2 G4) + ├── G1: (inner-join G2 G3 G4) │ └── [presentation: a:5,b:6,n:2,m:1] │ ├── best: (inner-join G2 G3 G4) │ └── cost: 1079.17 diff --git a/pkg/sql/opt/xform/testdata/rules/join_order b/pkg/sql/opt/xform/testdata/rules/join_order index 7c818c41d540..81eace1d983d 100644 --- a/pkg/sql/opt/xform/testdata/rules/join_order +++ b/pkg/sql/opt/xform/testdata/rules/join_order @@ -57,20 +57,20 @@ inner-join (lookup cy) opt join-limit=2 expect=ReorderJoins SELECT * FROM bx, abc, cy WHERE a = 1 AND abc.b = bx.b AND abc.c = cy.c ---- -inner-join (lookup cy) +inner-join (lookup bx) ├── columns: b:1!null x:2 a:4!null b:5!null c:6!null d:7 c:9!null y:10 - ├── key columns: [6] = [9] + ├── key columns: [5] = [1] ├── lookup columns are key ├── cardinality: [0 - 1] ├── key: () ├── fd: ()-->(1,2,4-7,9,10) - ├── inner-join (lookup bx) - │ ├── columns: bx.b:1!null x:2 a:4!null abc.b:5!null abc.c:6 d:7 - │ ├── key columns: [5] = [1] + ├── inner-join (lookup cy) + │ ├── columns: a:4!null abc.b:5 abc.c:6!null d:7 cy.c:9!null y:10 + │ ├── key columns: [6] = [9] │ ├── lookup columns are key │ ├── cardinality: [0 - 1] │ ├── key: () - │ ├── fd: ()-->(1,2,4-7) + │ ├── fd: ()-->(4-7,9,10) │ ├── scan abc │ │ ├── columns: a:4!null abc.b:5 abc.c:6 d:7 │ │ ├── constraint: /4: [/1 - /1] @@ -132,7 +132,21 @@ Source expression: └── filters └── abc.b = bx.b -No new expressions. +New expression 1 of 1: + inner-join (hash) + ├── scan bx + ├── inner-join (hash) + │ ├── scan cy + │ ├── inner-join (hash) + │ │ ├── scan abc + │ │ │ └── constraint: /10: [/1 - /1] + │ │ ├── scan dz + │ │ └── filters + │ │ └── dz.d = abc.c + │ └── filters + │ └── cy.c = dz.d + └── filters + └── abc.b = bx.b ================================================================================ ReorderJoins @@ -152,7 +166,22 @@ Source expression: └── filters └── abc.b = bx.b -New expression 1 of 1: +New expression 1 of 3: + inner-join (hash) + ├── scan bx + ├── inner-join (hash) + │ ├── inner-join (lookup dz) + │ │ ├── lookup columns are key + │ │ ├── scan abc + │ │ │ └── constraint: /10: [/1 - /1] + │ │ └── filters (true) + │ ├── scan cy + │ └── filters + │ └── cy.c = dz.d + └── filters + └── abc.b = bx.b + +New expression 2 of 3: inner-join (hash) ├── scan bx ├── inner-join (hash) @@ -168,6 +197,22 @@ New expression 1 of 1: └── filters └── abc.b = bx.b +New expression 3 of 3: + inner-join (hash) + ├── scan bx + ├── inner-join (hash) + │ ├── scan abc + │ │ └── constraint: /10: [/1 - /1] + │ ├── inner-join (hash) + │ │ ├── scan cy + │ │ ├── scan dz + │ │ └── filters + │ │ └── cy.c = dz.d + │ └── filters + │ └── dz.d = abc.c + └── filters + └── abc.b = bx.b + ================================================================================ ReorderJoins ================================================================================ @@ -185,7 +230,21 @@ Source expression: └── filters └── abc.b = bx.b -New expression 1 of 1: +New expression 1 of 3: + inner-join (hash) + ├── inner-join (lookup cy) + │ ├── lookup columns are key + │ ├── inner-join (lookup dz) + │ │ ├── lookup columns are key + │ │ ├── scan abc + │ │ │ └── constraint: /10: [/1 - /1] + │ │ └── filters (true) + │ └── filters (true) + ├── scan bx + └── filters + └── abc.b = bx.b + +New expression 2 of 3: inner-join (hash) ├── scan cy ├── inner-join (hash) @@ -199,6 +258,21 @@ New expression 1 of 1: │ └── abc.b = bx.b └── filters └── cy.c = dz.d + +New expression 3 of 3: + inner-join (hash) + ├── inner-join (hash) + │ ├── scan bx + │ ├── inner-join (lookup dz) + │ │ ├── lookup columns are key + │ │ ├── scan abc + │ │ │ └── constraint: /10: [/1 - /1] + │ │ └── filters (true) + │ └── filters + │ └── abc.b = bx.b + ├── scan cy + └── filters + └── cy.c = dz.d ---- ---- @@ -206,11 +280,11 @@ New expression 1 of 1: memo join-limit=0 expect-not=ReorderJoins SELECT * FROM bx, cy, abc WHERE a = 1 AND abc.b = bx.b AND abc.c = cy.c ---- -memo (optimized, ~26KB, required=[presentation: b:1,x:2,c:4,y:5,a:7,b:8,c:9,d:10]) - ├── G1: (inner-join G2 G3 G4) (inner-join G3 G2 G4) (merge-join G2 G3 G5 inner-join,+1,+8) (lookup-join G3 G5 bx,keyCols=[8],outCols=(1,2,4,5,7-10)) +memo (optimized, ~23KB, required=[presentation: b:1,x:2,c:4,y:5,a:7,b:8,c:9,d:10]) + ├── G1: (inner-join G2 G3 G4) (merge-join G2 G3 G5 inner-join,+1,+8) │ └── [presentation: b:1,x:2,c:4,y:5,a:7,b:8,c:9,d:10] - │ ├── best: (lookup-join G3 G5 bx,keyCols=[8],outCols=(1,2,4,5,7-10)) - │ └── cost: 13.13 + │ ├── best: (merge-join G2="[ordering: +1]" G3 G5 inner-join,+1,+8) + │ └── cost: 2101.19 ├── G2: (scan bx,cols=(1,2)) │ ├── [ordering: +1] │ │ ├── best: (scan bx,cols=(1,2)) @@ -218,10 +292,10 @@ memo (optimized, ~26KB, required=[presentation: b:1,x:2,c:4,y:5,a:7,b:8,c:9,d:10 │ └── [] │ ├── best: (scan bx,cols=(1,2)) │ └── cost: 1040.02 - ├── G3: (inner-join G6 G7 G8) (inner-join G7 G6 G8) (merge-join G6 G7 G5 inner-join,+4,+9) (lookup-join G9 G8 abc,keyCols=[12],outCols=(4,5,7-10)) (lookup-join G7 G5 cy,keyCols=[9],outCols=(4,5,7-10)) + ├── G3: (inner-join G6 G7 G8) (merge-join G6 G7 G5 inner-join,+4,+9) (lookup-join G9 G8 abc,keyCols=[12],outCols=(4,5,7-10)) │ └── [] - │ ├── best: (lookup-join G7 G5 cy,keyCols=[9],outCols=(4,5,7-10)) - │ └── cost: 7.13 + │ ├── best: (merge-join G6="[ordering: +4]" G7 G5 inner-join,+4,+9) + │ └── cost: 1051.14 ├── G4: (filters G10) ├── G5: (filters) ├── G6: (scan cy,cols=(4,5)) @@ -260,7 +334,7 @@ memo join-limit=2 SELECT * FROM bx, cy, abc WHERE a = 1 AND abc.b = bx.b AND abc.c = cy.c ---- memo (optimized, ~35KB, required=[presentation: b:1,x:2,c:4,y:5,a:7,b:8,c:9,d:10]) - ├── G1: (inner-join G2 G3 G4) (inner-join G5 G6 G7) (inner-join G3 G2 G4) (merge-join G2 G3 G8 inner-join,+1,+8) (inner-join G6 G5 G7) (merge-join G5 G6 G8 inner-join,+4,+9) (lookup-join G3 G8 bx,keyCols=[8],outCols=(1,2,4,5,7-10)) (lookup-join G6 G8 cy,keyCols=[9],outCols=(1,2,4,5,7-10)) + ├── G1: (inner-join G2 G3 G4) (inner-join G3 G2 G4) (inner-join G5 G6 G7) (inner-join G6 G5 G7) (merge-join G2 G3 G8 inner-join,+1,+8) (lookup-join G3 G8 bx,keyCols=[8],outCols=(1,2,4,5,7-10)) (merge-join G5 G6 G8 inner-join,+4,+9) (lookup-join G6 G8 cy,keyCols=[9],outCols=(1,2,4,5,7-10)) │ └── [presentation: b:1,x:2,c:4,y:5,a:7,b:8,c:9,d:10] │ ├── best: (lookup-join G3 G8 bx,keyCols=[8],outCols=(1,2,4,5,7-10)) │ └── cost: 13.13 @@ -431,45 +505,57 @@ memo join-limit=0 SELECT * FROM bx, cy, dz, abc WHERE x = y AND y = z AND z = a ---- memo (optimized, ~24KB, required=[presentation: b:1,x:2,c:4,y:5,d:7,z:8,a:10,b:11,c:12,d:13]) - ├── G1: (inner-join G2 G3 G4) (inner-join G3 G2 G4) + ├── G1: (inner-join G2 G3 G4) (merge-join G2 G3 G5 inner-join,+2,+5) │ └── [presentation: b:1,x:2,c:4,y:5,d:7,z:8,a:10,b:11,c:12,d:13] - │ ├── best: (inner-join G3 G2 G4) - │ └── cost: 5478.19 + │ ├── best: (inner-join G2 G3 G4) + │ └── cost: 5522.19 ├── G2: (scan bx,cols=(1,2)) + │ ├── [ordering: +2] + │ │ ├── best: (sort G2) + │ │ └── cost: 1259.35 │ └── [] │ ├── best: (scan bx,cols=(1,2)) │ └── cost: 1040.02 - ├── G3: (inner-join G5 G6 G7) (inner-join G6 G5 G7) + ├── G3: (inner-join G6 G7 G8) (merge-join G6 G7 G5 inner-join,+5,+8) + │ ├── [ordering: +(5|8|10)] + │ │ ├── best: (merge-join G6="[ordering: +5]" G7="[ordering: +(8|10)]" G5 inner-join,+5,+8) + │ │ └── cost: 3746.54 │ └── [] - │ ├── best: (inner-join G5 G6 G7) + │ ├── best: (inner-join G6 G7 G8) │ └── cost: 3327.84 - ├── G4: (filters G8) - ├── G5: (scan cy,cols=(4,5)) + ├── G4: (filters G9) + ├── G5: (filters) + ├── G6: (scan cy,cols=(4,5)) + │ ├── [ordering: +5] + │ │ ├── best: (sort G6) + │ │ └── cost: 1259.35 │ └── [] │ ├── best: (scan cy,cols=(4,5)) │ └── cost: 1040.02 - ├── G6: (inner-join G9 G10 G11) (inner-join G10 G9 G11) (lookup-join G9 G12 abc,keyCols=[8],outCols=(7,8,10-13)) (merge-join G10 G9 G12 inner-join,+10,+8) + ├── G7: (inner-join G10 G11 G12) (merge-join G10 G11 G5 inner-join,+8,+10) (lookup-join G10 G5 abc,keyCols=[8],outCols=(7,8,10-13)) + │ ├── [ordering: +(8|10)] + │ │ ├── best: (merge-join G10="[ordering: +8]" G11="[ordering: +10]" G5 inner-join,+8,+10) + │ │ └── cost: 2369.28 │ └── [] - │ ├── best: (inner-join G9 G10 G11) + │ ├── best: (inner-join G10 G11 G12) │ └── cost: 2159.96 - ├── G7: (filters G13) - ├── G8: (eq G14 G15) - ├── G9: (scan dz,cols=(7,8)) + ├── G8: (filters G13) + ├── G9: (eq G14 G15) + ├── G10: (scan dz,cols=(7,8)) │ ├── [ordering: +8] - │ │ ├── best: (sort G9) + │ │ ├── best: (sort G10) │ │ └── cost: 1259.35 │ └── [] │ ├── best: (scan dz,cols=(7,8)) │ └── cost: 1040.02 - ├── G10: (scan abc,cols=(10-13)) + ├── G11: (scan abc,cols=(10-13)) │ ├── [ordering: +10] │ │ ├── best: (scan abc,cols=(10-13)) │ │ └── cost: 1080.02 │ └── [] │ ├── best: (scan abc,cols=(10-13)) │ └── cost: 1080.02 - ├── G11: (filters G16) - ├── G12: (filters) + ├── G12: (filters G16) ├── G13: (eq G15 G17) ├── G14: (variable x) ├── G15: (variable y) @@ -485,9 +571,9 @@ memo join-limit=3 SELECT * FROM bx, cy, dz, abc WHERE x = y AND y = z AND z = a ---- memo (optimized, ~51KB, required=[presentation: b:1,x:2,c:4,y:5,d:7,z:8,a:10,b:11,c:12,d:13]) - ├── G1: (inner-join G2 G3 G4) (inner-join G5 G6 G7) (inner-join G8 G9 G7) (inner-join G10 G11 G12) (inner-join G13 G14 G12) (inner-join G15 G16 G12) (inner-join G17 G18 G12) (inner-join G3 G2 G4) (inner-join G6 G5 G7) (inner-join G9 G8 G7) (inner-join G11 G10 G12) (inner-join G14 G13 G12) (inner-join G16 G15 G12) (inner-join G18 G17 G12) (lookup-join G17 G19 abc,keyCols=[8],outCols=(1,2,4,5,7,8,10-13)) (merge-join G11 G10 G19 inner-join,+10,+8) (merge-join G14 G13 G19 inner-join,+10,+8) (merge-join G16 G15 G19 inner-join,+10,+8) (merge-join G18 G17 G19 inner-join,+10,+8) + ├── G1: (inner-join G2 G3 G4) (inner-join G3 G2 G4) (inner-join G5 G6 G7) (inner-join G6 G5 G7) (inner-join G8 G9 G7) (inner-join G9 G8 G7) (inner-join G10 G11 G12) (inner-join G11 G10 G12) (inner-join G13 G14 G12) (inner-join G14 G13 G12) (inner-join G15 G16 G12) (inner-join G16 G15 G12) (inner-join G17 G18 G12) (inner-join G18 G17 G12) (merge-join G11 G10 G19 inner-join,+10,+8) (merge-join G14 G13 G19 inner-join,+10,+8) (merge-join G16 G15 G19 inner-join,+10,+8) (lookup-join G17 G19 abc,keyCols=[8],outCols=(1,2,4,5,7,8,10-13)) (merge-join G18 G17 G19 inner-join,+10,+8) │ └── [presentation: b:1,x:2,c:4,y:5,d:7,z:8,a:10,b:11,c:12,d:13] - │ ├── best: (inner-join G8 G9 G7) + │ ├── best: (inner-join G3 G2 G4) │ └── cost: 5478.19 ├── G2: (scan bx,cols=(1,2)) │ ├── [ordering: +2] @@ -496,7 +582,7 @@ memo (optimized, ~51KB, required=[presentation: b:1,x:2,c:4,y:5,d:7,z:8,a:10,b:1 │ └── [] │ ├── best: (scan bx,cols=(1,2)) │ └── cost: 1040.02 - ├── G3: (inner-join G5 G9 G7) (inner-join G10 G14 G12) (inner-join G15 G18 G12) (inner-join G9 G5 G7) (inner-join G14 G10 G12) (inner-join G18 G15 G12) (lookup-join G15 G19 abc,keyCols=[8],outCols=(4,5,7,8,10-13)) (merge-join G14 G10 G19 inner-join,+10,+8) (merge-join G18 G15 G19 inner-join,+10,+8) + ├── G3: (inner-join G5 G9 G7) (inner-join G9 G5 G7) (inner-join G10 G14 G12) (inner-join G14 G10 G12) (inner-join G15 G18 G12) (inner-join G18 G15 G12) (merge-join G14 G10 G19 inner-join,+10,+8) (lookup-join G15 G19 abc,keyCols=[8],outCols=(4,5,7,8,10-13)) (merge-join G18 G15 G19 inner-join,+10,+8) │ └── [] │ ├── best: (inner-join G5 G9 G7) │ └── cost: 3327.84 @@ -508,7 +594,7 @@ memo (optimized, ~51KB, required=[presentation: b:1,x:2,c:4,y:5,d:7,z:8,a:10,b:1 │ └── [] │ ├── best: (scan cy,cols=(4,5)) │ └── cost: 1040.02 - ├── G6: (inner-join G2 G9 G21) (inner-join G10 G16 G12) (inner-join G13 G18 G12) (inner-join G9 G2 G21) (inner-join G16 G10 G12) (inner-join G18 G13 G12) (lookup-join G13 G19 abc,keyCols=[8],outCols=(1,2,7,8,10-13)) (merge-join G16 G10 G19 inner-join,+10,+8) (merge-join G18 G13 G19 inner-join,+10,+8) + ├── G6: (inner-join G2 G9 G21) (inner-join G9 G2 G21) (inner-join G10 G16 G12) (inner-join G16 G10 G12) (inner-join G13 G18 G12) (inner-join G18 G13 G12) (merge-join G16 G10 G19 inner-join,+10,+8) (lookup-join G13 G19 abc,keyCols=[8],outCols=(1,2,7,8,10-13)) (merge-join G18 G13 G19 inner-join,+10,+8) │ └── [] │ ├── best: (inner-join G2 G9 G21) │ └── cost: 3327.84 @@ -531,7 +617,7 @@ memo (optimized, ~51KB, required=[presentation: b:1,x:2,c:4,y:5,d:7,z:8,a:10,b:1 │ └── [] │ ├── best: (scan dz,cols=(7,8)) │ └── cost: 1040.02 - ├── G11: (inner-join G2 G14 G4) (inner-join G5 G16 G4) (inner-join G8 G18 G23) (inner-join G14 G2 G4) (inner-join G16 G5 G4) (inner-join G18 G8 G23) (lookup-join G8 G19 abc,keyCols=[5],outCols=(1,2,4,5,10-13)) (merge-join G18 G8 G19 inner-join,+10,+5) + ├── G11: (inner-join G2 G14 G4) (inner-join G14 G2 G4) (inner-join G5 G16 G4) (inner-join G16 G5 G4) (inner-join G8 G18 G23) (inner-join G18 G8 G23) (lookup-join G8 G19 abc,keyCols=[5],outCols=(1,2,4,5,10-13)) (merge-join G18 G8 G19 inner-join,+10,+5) │ ├── [ordering: +(2|5|10)] │ │ ├── best: (sort G11) │ │ └── cost: 6122.84 @@ -567,12 +653,12 @@ memo (optimized, ~51KB, required=[presentation: b:1,x:2,c:4,y:5,d:7,z:8,a:10,b:1 │ └── [] │ ├── best: (inner-join G2 G18 G25) │ └── cost: 2159.96 - ├── G17: (inner-join G2 G15 G4) (inner-join G5 G13 G7) (inner-join G8 G10 G7) (inner-join G15 G2 G4) (inner-join G13 G5 G7) (inner-join G10 G8 G7) + ├── G17: (inner-join G2 G15 G4) (inner-join G15 G2 G4) (inner-join G5 G13 G7) (inner-join G13 G5 G7) (inner-join G8 G10 G7) (inner-join G10 G8 G7) │ ├── [ordering: +(2|5|8)] │ │ ├── best: (sort G17) │ │ └── cost: 38447.25 │ └── [] - │ ├── best: (inner-join G8 G10 G7) + │ ├── best: (inner-join G15 G2 G4) │ └── cost: 4358.42 ├── G18: (scan abc,cols=(10-13)) │ ├── [ordering: +10] @@ -604,36 +690,36 @@ inner-join (hash) ├── key: (1,4,7) ├── fd: (1)-->(2), (4)-->(5), (7)-->(8), (10)-->(11-13), (8)==(2,5,10), (10)==(2,5,8), (5)==(2,8,10), (2)==(5,8,10) ├── inner-join (hash) - │ ├── columns: bx.b:1!null x:2!null cy.c:4!null y:5!null - │ ├── key: (1,4) - │ ├── fd: (1)-->(2), (4)-->(5), (2)==(5), (5)==(2) - │ ├── scan bx - │ │ ├── columns: bx.b:1!null x:2 - │ │ ├── key: (1) - │ │ └── fd: (1)-->(2) + │ ├── columns: cy.c:4!null y:5!null dz.d:7!null z:8!null a:10!null abc.b:11 abc.c:12 abc.d:13 + │ ├── key: (4,7) + │ ├── fd: (4)-->(5), (7)-->(8), (10)-->(11-13), (8)==(5,10), (10)==(5,8), (5)==(8,10) │ ├── scan cy │ │ ├── columns: cy.c:4!null y:5 │ │ ├── key: (4) │ │ └── fd: (4)-->(5) - │ └── filters - │ └── x:2 = y:5 [outer=(2,5), constraints=(/2: (/NULL - ]; /5: (/NULL - ]), fd=(2)==(5), (5)==(2)] - ├── inner-join (hash) - │ ├── columns: dz.d:7!null z:8!null a:10!null abc.b:11 abc.c:12 abc.d:13 - │ ├── multiplicity: left-rows(zero-or-one), right-rows(zero-or-more) - │ ├── key: (7) - │ ├── fd: (7)-->(8), (10)-->(11-13), (8)==(10), (10)==(8) - │ ├── scan dz - │ │ ├── columns: dz.d:7!null z:8 + │ ├── inner-join (hash) + │ │ ├── columns: dz.d:7!null z:8!null a:10!null abc.b:11 abc.c:12 abc.d:13 + │ │ ├── multiplicity: left-rows(zero-or-one), right-rows(zero-or-more) │ │ ├── key: (7) - │ │ └── fd: (7)-->(8) - │ ├── scan abc - │ │ ├── columns: a:10!null abc.b:11 abc.c:12 abc.d:13 - │ │ ├── key: (10) - │ │ └── fd: (10)-->(11-13) + │ │ ├── fd: (7)-->(8), (10)-->(11-13), (8)==(10), (10)==(8) + │ │ ├── scan dz + │ │ │ ├── columns: dz.d:7!null z:8 + │ │ │ ├── key: (7) + │ │ │ └── fd: (7)-->(8) + │ │ ├── scan abc + │ │ │ ├── columns: a:10!null abc.b:11 abc.c:12 abc.d:13 + │ │ │ ├── key: (10) + │ │ │ └── fd: (10)-->(11-13) + │ │ └── filters + │ │ └── z:8 = a:10 [outer=(8,10), constraints=(/8: (/NULL - ]; /10: (/NULL - ]), fd=(8)==(10), (10)==(8)] │ └── filters - │ └── z:8 = a:10 [outer=(8,10), constraints=(/8: (/NULL - ]; /10: (/NULL - ]), fd=(8)==(10), (10)==(8)] + │ └── y:5 = z:8 [outer=(5,8), constraints=(/5: (/NULL - ]; /8: (/NULL - ]), fd=(5)==(8), (8)==(5)] + ├── scan bx + │ ├── columns: bx.b:1!null x:2 + │ ├── key: (1) + │ └── fd: (1)-->(2) └── filters - └── y:5 = z:8 [outer=(5,8), constraints=(/5: (/NULL - ]; /8: (/NULL - ]), fd=(5)==(8), (8)==(5)] + └── x:2 = y:5 [outer=(2,5), constraints=(/2: (/NULL - ]; /5: (/NULL - ]), fd=(2)==(5), (5)==(2)] # Regression test for #34795. exec-ddl @@ -743,8 +829,9 @@ b = c [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] -Joins Considered: 1 +Joins Considered: 2 -------------------------------------------------------------------------------- ----Join Tree #2---- inner-join (hash) @@ -780,16 +867,22 @@ b = d [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] ----Joining AC---- A C refs [AC] [inner] +C A refs [AC] [inner] ----Joining BC---- B C refs [BC] [inner] +C B refs [BC] [inner] ----Joining ABC---- A BC refs [AB] [inner] +BC A refs [AB] [inner] B AC refs [AB] [inner] +AC B refs [AB] [inner] AB C refs [BC] [inner] +C AB refs [BC] [inner] -Joins Considered: 6 +Joins Considered: 12 -------------------------------------------------------------------------------- ----Final Plan---- inner-join (merge) @@ -833,8 +926,9 @@ bx.b = cy.c [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] -Joins Considered: 1 +Joins Considered: 2 -------------------------------------------------------------------------------- ----Join Tree #2---- inner-join (hash) @@ -871,13 +965,17 @@ y = max [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] ----Joining BC---- B C refs [BC] [inner] +C B refs [BC] [inner] ----Joining ABC---- A BC refs [AB] [inner] +BC A refs [AB] [inner] AB C refs [BC] [inner] +C AB refs [BC] [inner] -Joins Considered: 4 +Joins Considered: 8 -------------------------------------------------------------------------------- ----Join Tree #3---- inner-join (hash) @@ -923,29 +1021,44 @@ y = a [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] ----Joining BC---- B C refs [BC] [inner] +C B refs [BC] [inner] ----Joining ABC---- A BC refs [AB] [inner] +BC A refs [AB] [inner] AB C refs [BC] [inner] +C AB refs [BC] [inner] ----Joining BD---- B D refs [BD] [inner] +D B refs [BD] [inner] ----Joining ABD---- A BD refs [AB] [inner] +BD A refs [AB] [inner] AB D refs [BD] [inner] +D AB refs [BD] [inner] ----Joining CD---- C D refs [CD] [inner] +D C refs [CD] [inner] ----Joining BCD---- B CD refs [BCD] [inner] +CD B refs [BCD] [inner] C BD refs [BC] [inner] +BD C refs [BC] [inner] BC D refs [CD] [inner] +D BC refs [CD] [inner] ----Joining ABCD---- A BCD refs [AB] [inner] +BCD A refs [AB] [inner] AB CD refs [BCD] [inner] +CD AB refs [BCD] [inner] C ABD refs [BC] [inner] +ABD C refs [BC] [inner] ABC D refs [CD] [inner] +D ABC refs [CD] [inner] -Joins Considered: 15 +Joins Considered: 30 -------------------------------------------------------------------------------- ----Final Plan---- inner-join (lookup bx) @@ -1010,8 +1123,9 @@ x = z [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] -Joins Considered: 1 +Joins Considered: 2 -------------------------------------------------------------------------------- ----Join Tree #2---- inner-join (hash) @@ -1053,16 +1167,22 @@ y = a [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] ----Joining AC---- A C refs [AC] [inner] +C A refs [AC] [inner] ----Joining BC---- B C refs [BC] [inner] +C B refs [BC] [inner] ----Joining ABC---- A BC refs [AB] [inner] +BC A refs [AB] [inner] B AC refs [AB] [inner] +AC B refs [AB] [inner] AB C refs [BC] [inner] +C AB refs [BC] [inner] -Joins Considered: 6 +Joins Considered: 12 -------------------------------------------------------------------------------- ----Final Plan---- inner-join (hash) @@ -1117,8 +1237,9 @@ y = z [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] -Joins Considered: 1 +Joins Considered: 2 -------------------------------------------------------------------------------- ----Join Tree #2---- inner-join (hash) @@ -1148,16 +1269,22 @@ y = a [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] ----Joining AC---- A C refs [AC] [inner] +C A refs [AC] [inner] ----Joining BC---- B C refs [BC] [inner] +C B refs [BC] [inner] ----Joining ABC---- A BC refs [AB] [inner] +BC A refs [AB] [inner] B AC refs [AB] [inner] +AC B refs [AB] [inner] AB C refs [BC] [inner] +C AB refs [BC] [inner] -Joins Considered: 6 +Joins Considered: 12 -------------------------------------------------------------------------------- ----Join Tree #3---- inner-join (cross) @@ -1196,18 +1323,25 @@ y = a [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] ----Joining AC---- A C refs [AC] [inner] +C A refs [AC] [inner] ----Joining BC---- B C refs [BC] [inner] +C B refs [BC] [inner] ----Joining ABC---- A BC refs [AB] [inner] +BC A refs [AB] [inner] B AC refs [AB] [inner] +AC B refs [AB] [inner] AB C refs [BC] [inner] +C AB refs [BC] [inner] ----Joining DABC---- D ABC refs [] [inner] +ABC D refs [] [inner] -Joins Considered: 7 +Joins Considered: 14 -------------------------------------------------------------------------------- ----Final Plan---- inner-join-apply @@ -1267,8 +1401,9 @@ x = y [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] -Joins Considered: 1 +Joins Considered: 2 -------------------------------------------------------------------------------- ----Join Tree #2---- inner-join (hash) @@ -1289,8 +1424,9 @@ a = z [inner] ----Joining CD---- C D refs [CD] [inner] +D C refs [CD] [inner] -Joins Considered: 1 +Joins Considered: 2 -------------------------------------------------------------------------------- ----Join Tree #3---- inner-join (hash) @@ -1329,29 +1465,44 @@ abc.c = cy.c [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] ----Joining AC---- A C refs [AC] [inner] +C A refs [AC] [inner] ----Joining BC---- B C refs [BC] [inner] +C B refs [BC] [inner] ----Joining ABC---- A BC refs [ABC] [inner] +BC A refs [ABC] [inner] B AC refs [ABC] [inner] +AC B refs [ABC] [inner] AB C refs [ABC] [inner] +C AB refs [ABC] [inner] ----Joining CD---- C D refs [CD] [inner] +D C refs [CD] [inner] ----Joining ACD---- A CD refs [AC] [inner] +CD A refs [AC] [inner] AC D refs [CD] [inner] +D AC refs [CD] [inner] ----Joining BCD---- B CD refs [BC] [inner] +CD B refs [BC] [inner] BC D refs [CD] [inner] +D BC refs [CD] [inner] ----Joining ABCD---- A BCD refs [ABC] [inner] +BCD A refs [ABC] [inner] B ACD refs [ABC] [inner] +ACD B refs [ABC] [inner] AB CD refs [ABC] [inner] +CD AB refs [ABC] [inner] ABC D refs [CD] [inner] +D ABC refs [CD] [inner] -Joins Considered: 15 +Joins Considered: 30 -------------------------------------------------------------------------------- ----Final Plan---- project @@ -1400,8 +1551,9 @@ b = c [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] -Joins Considered: 1 +Joins Considered: 2 -------------------------------------------------------------------------------- ----Join Tree #2---- left-join (hash) @@ -1430,13 +1582,15 @@ x = z [left] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] ----Joining AC---- A C refs [AC] [left] ----Joining ABC---- B AC refs [AB] [inner] +AC B refs [AB] [inner] AB C refs [AC] [left] -Joins Considered: 4 +Joins Considered: 6 -------------------------------------------------------------------------------- ----Final Plan---- left-join (hash) @@ -1710,11 +1864,13 @@ bx.b = dz.d [inner] A B refs [AB] [anti] ----Joining AC---- A C refs [AC] [inner] +C A refs [AC] [inner] ----Joining ABC---- AC B refs [AB] [anti] AB C refs [AC] [inner] +C AB refs [AC] [inner] -Joins Considered: 4 +Joins Considered: 6 -------------------------------------------------------------------------------- ----Join Tree #4---- left-join (hash) @@ -1813,18 +1969,22 @@ AB D refs [AD] [left] AD B refs [AB] [anti] ----Joining AC---- A C refs [AC] [inner] +C A refs [AC] [inner] ----Joining ADC---- AC D refs [AD] [left] AD C refs [AC] [inner] +C AD refs [AC] [inner] ----Joining ABC---- AC B refs [AB] [anti] AB C refs [AC] [inner] +C AB refs [AC] [inner] ----Joining ADBC---- ABC D refs [AD] [left] ADC B refs [AB] [anti] ADB C refs [AC] [inner] +C ADB refs [AC] [inner] -Joins Considered: 12 +Joins Considered: 16 -------------------------------------------------------------------------------- ----Final Plan---- semi-join (lookup dz) @@ -1867,8 +2027,9 @@ cross [inner] ----Joining AB---- A B refs [] [inner] +B A refs [] [inner] -Joins Considered: 1 +Joins Considered: 2 -------------------------------------------------------------------------------- ----Join Tree #2---- inner-join (cross) @@ -1895,10 +2056,12 @@ cross [inner] ----Joining AB---- A B refs [] [inner] +B A refs [] [inner] ----Joining ABC---- AB C refs [] [inner] +C AB refs [] [inner] -Joins Considered: 2 +Joins Considered: 4 -------------------------------------------------------------------------------- ----Final Plan---- inner-join (cross) @@ -1939,8 +2102,9 @@ b = c [full] ----Joining AB---- A B refs [AB] [full] +B A refs [AB] [full] -Joins Considered: 1 +Joins Considered: 2 -------------------------------------------------------------------------------- ----Join Tree #2---- full-join (hash) @@ -1969,13 +2133,17 @@ y = z [full] ----Joining AB---- A B refs [AB] [full] +B A refs [AB] [full] ----Joining BC---- B C refs [BC] [full] +C B refs [BC] [full] ----Joining ABC---- A BC refs [AB] [full] +BC A refs [AB] [full] AB C refs [BC] [full] +C AB refs [BC] [full] -Joins Considered: 4 +Joins Considered: 8 -------------------------------------------------------------------------------- ----Final Plan---- full-join (hash) @@ -2043,8 +2211,9 @@ a2.c = a5.c [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] -Joins Considered: 1 +Joins Considered: 2 -------------------------------------------------------------------------------- ----Join Tree #3---- inner-join (hash) @@ -2073,13 +2242,15 @@ a1.a = a2.a [inner] ----Joining CA---- C A refs [CA] [inner] +A C refs [CA] [inner] ----Joining AB---- A B refs [AB] [semi] ----Joining CAB---- C AB refs [CA] [inner] +AB C refs [CA] [inner] CA B refs [AB] [semi] -Joins Considered: 4 +Joins Considered: 6 -------------------------------------------------------------------------------- ----Join Tree #4---- inner-join (hash) @@ -2110,13 +2281,17 @@ a2.c = a5.c [inner] ----Joining CA---- C A refs [CA] [inner] +A C refs [CA] [inner] ----Joining AB---- A B refs [AB] [inner] +B A refs [AB] [inner] ----Joining CAB---- C AB refs [CA] [inner] +AB C refs [CA] [inner] CA B refs [AB] [inner] +B CA refs [AB] [inner] -Joins Considered: 4 +Joins Considered: 8 -------------------------------------------------------------------------------- ----Join Tree #5---- inner-join (hash) @@ -2153,13 +2328,17 @@ a2.b = a3.b [inner] ----Joining CA---- C A refs [CA] [inner] +A C refs [CA] [inner] ----Joining AD---- A D refs [AD] [inner] +D A refs [AD] [inner] ----Joining CAD---- C AD refs [CA] [inner] +AD C refs [CA] [inner] CA D refs [AD] [inner] +D CA refs [AD] [inner] -Joins Considered: 4 +Joins Considered: 8 -------------------------------------------------------------------------------- ----Join Tree #6---- inner-join (hash) @@ -2204,13 +2383,17 @@ a3.a = a4.a [inner] ----Joining CD---- C D refs [CD] [inner] +D C refs [CD] [inner] ----Joining DE---- D E refs [DE] [inner] +E D refs [DE] [inner] ----Joining CDE---- C DE refs [CD] [inner] +DE C refs [CD] [inner] CD E refs [DE] [inner] +E CD refs [DE] [inner] -Joins Considered: 4 +Joins Considered: 8 -------------------------------------------------------------------------------- ----Final Plan---- inner-join (hash) diff --git a/pkg/sql/opt/xform/testdata/rules/stats b/pkg/sql/opt/xform/testdata/rules/stats index 2e80aa982856..58a6ba5d2fb0 100644 --- a/pkg/sql/opt/xform/testdata/rules/stats +++ b/pkg/sql/opt/xform/testdata/rules/stats @@ -14,10 +14,9 @@ Top normalization rules: EliminateProject applied 1 times. PruneJoinLeftCols applied 1 times. PruneJoinRightCols applied 1 times. -Exploration rules applied 9 times, added 5 expressions. +Exploration rules applied 7 times, added 5 expressions. Top exploration rules: - CommuteJoin applied 2 times, added 1 expressions. GenerateMergeJoins applied 2 times, added 2 expressions. GenerateLookupJoins applied 2 times, added 2 expressions. GenerateIndexScans applied 2 times, added 0 expressions. - ReorderJoins applied 1 times, added 0 expressions. + ReorderJoins applied 1 times, added 1 expressions.