From 04eb457f7d78589f66c1552409ea58fb227e0ba5 Mon Sep 17 00:00:00 2001 From: Mark Sirek Date: Sat, 17 Dec 2022 16:32:50 -0800 Subject: [PATCH] xform: use ordering from LIMIT as a hint for streaming group by Fixes #93410 A query with a grouped aggregation, a LIMIT and an ORDER BY may not always explore the best-cost query plan. Due to the existence of unique constraints on a table, the set of grouping columns may be reduced during normalization via rule ReduceGroupingCols such that it no longer includes columns present in the ORDER BY clause. This eliminates possibly cheap plans from consideration, for example, if the input to the aggregation is a lookup join, it may be cheaper to sort the input to the lookup join on the ORDER BY columns if they overlap with the grouping columns, so that a streaming group-by with no TopK operator can be used, and a full scan of the inputs to the join is avoided. This fix adds a new exploration rule which ensures that a grouped aggregation with a LIMIT and ORDER BY clause considers using streaming group-by with no TopK when possible. Release note (bug fix): This patch fixes join queries involving tables with unique constraints using LIMIT, GROUP BY and ORDER BY clauses to ensure the optimizer considers streaming group-by with no TopK operation, when possible. This is often the most efficient query plan. --- .../opt/exec/execbuilder/testdata/tpch_vec | 19 +- .../opt/memo/testdata/stats_quality/tpch/q18 | 272 +++++----- pkg/sql/opt/norm/factory.go | 22 + .../opttester/testfixtures/rewrite_stats.sh | 4 +- pkg/sql/opt/xform/groupby_funcs.go | 124 +++++ pkg/sql/opt/xform/rules/limit.opt | 36 ++ pkg/sql/opt/xform/testdata/external/tpch | 139 +++--- pkg/sql/opt/xform/testdata/external/trading | 193 ++++---- .../xform/testdata/external/trading-mutation | 193 ++++---- pkg/sql/opt/xform/testdata/rules/limit | 466 ++++++++++++++++++ 10 files changed, 1054 insertions(+), 414 deletions(-) diff --git a/pkg/sql/opt/exec/execbuilder/testdata/tpch_vec b/pkg/sql/opt/exec/execbuilder/testdata/tpch_vec index 7f02dd3744d5..f79ad2f450c8 100644 --- a/pkg/sql/opt/exec/execbuilder/testdata/tpch_vec +++ b/pkg/sql/opt/exec/execbuilder/testdata/tpch_vec @@ -20906,17 +20906,16 @@ EXPLAIN (VEC) SELECT c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, s ---- │ └ Node 1 - └ *colexec.topKSorter + └ *colexec.limitOp └ *colexec.hashAggregator - └ *colexecjoin.hashJoiner - ├ *colexecjoin.mergeJoinInnerOp - │ ├ *colfetcher.ColBatchScan - │ └ *colexecjoin.mergeJoinLeftSemiOp - │ ├ *colfetcher.ColBatchScan - │ └ *colexecsel.selGTFloat64Float64ConstOp - │ └ *colexec.orderedAggregator - │ └ *colfetcher.ColBatchScan - └ *colfetcher.ColBatchScan + └ *rowexec.joinReader + └ *rowexec.joinReader + └ *colexec.sortOp + └ *colexecjoin.mergeJoinLeftSemiOp + ├ *colfetcher.ColBatchScan + └ *colexecsel.selGTFloat64Float64ConstOp + └ *colexec.orderedAggregator + └ *colfetcher.ColBatchScan # Query 19 query T diff --git a/pkg/sql/opt/memo/testdata/stats_quality/tpch/q18 b/pkg/sql/opt/memo/testdata/stats_quality/tpch/q18 index 47f9c2801495..170738f64e76 100644 --- a/pkg/sql/opt/memo/testdata/stats_quality/tpch/q18 +++ b/pkg/sql/opt/memo/testdata/stats_quality/tpch/q18 @@ -51,125 +51,116 @@ ORDER BY LIMIT 100; ---- ---- -top-k - ├── save-table-name: q18_top_k_1 +limit + ├── save-table-name: q18_limit_1 ├── columns: c_name:2(varchar!null) c_custkey:1(int!null) o_orderkey:11(int!null) o_orderdate:15(date!null) o_totalprice:14(float!null) sum:59(float!null) ├── internal-ordering: -14,+15 - ├── k: 100 ├── cardinality: [0 - 100] ├── stats: [rows=100, distinct(1)=100, null(1)=0, distinct(2)=100, null(2)=0, distinct(11)=100, null(11)=0, distinct(14)=100, null(14)=0, distinct(15)=100, null(15)=0, distinct(59)=100, null(59)=0] ├── key: (11) ├── fd: (1)-->(2), (11)-->(1,2,14,15,59) ├── ordering: -14,+15 - └── group-by (hash) - ├── save-table-name: q18_group_by_2 - ├── columns: c_custkey:1(int!null) c_name:2(varchar!null) o_orderkey:11(int!null) o_totalprice:14(float!null) o_orderdate:15(date!null) sum:59(float!null) - ├── grouping columns: o_orderkey:11(int!null) - ├── stats: [rows=499392.2, distinct(1)=499392, null(1)=0, distinct(2)=499392, null(2)=0, distinct(11)=499392, null(11)=0, distinct(14)=499392, null(14)=0, distinct(15)=499392, null(15)=0, distinct(59)=499392, null(59)=0] - ├── key: (11) - ├── fd: (1)-->(2), (11)-->(1,2,14,15,59) - ├── inner-join (hash) - │ ├── save-table-name: q18_inner_join_3 - │ ├── columns: c_custkey:1(int!null) c_name:2(varchar!null) o_orderkey:11(int!null) o_custkey:12(int!null) o_totalprice:14(float!null) o_orderdate:15(date!null) l_orderkey:22(int!null) l_quantity:26(float!null) - │ ├── multiplicity: left-rows(exactly-one), right-rows(zero-or-more) - │ ├── stats: [rows=2016361, distinct(1)=99649.1, null(1)=0, distinct(2)=150000, null(2)=0, distinct(11)=499392, null(11)=0, distinct(12)=99649.1, null(12)=0, distinct(14)=488044, null(14)=0, distinct(15)=2406, null(15)=0, distinct(22)=499392, null(22)=0, distinct(26)=50, null(26)=0] - │ ├── fd: (1)-->(2), (11)-->(12,14,15), (11)==(22), (22)==(11), (1)==(12), (12)==(1) - │ ├── inner-join (merge) - │ │ ├── save-table-name: q18_merge_join_4 - │ │ ├── columns: o_orderkey:11(int!null) o_custkey:12(int!null) o_totalprice:14(float!null) o_orderdate:15(date!null) l_orderkey:22(int!null) l_quantity:26(float!null) - │ │ ├── left ordering: +22 - │ │ ├── right ordering: +11 - │ │ ├── stats: [rows=2000405, distinct(11)=509090, null(11)=0, distinct(12)=99649.1, null(12)=0, distinct(14)=496607, null(14)=0, distinct(15)=2406, null(15)=0, distinct(22)=509090, null(22)=0, distinct(26)=50, null(26)=0] - │ │ ├── fd: (11)-->(12,14,15), (11)==(22), (22)==(11) - │ │ ├── scan lineitem - │ │ │ ├── save-table-name: q18_scan_5 - │ │ │ ├── columns: l_orderkey:22(int!null) l_quantity:26(float!null) - │ │ │ ├── stats: [rows=6001215, distinct(22)=1.52727e+06, null(22)=0, distinct(26)=50, null(26)=0] - │ │ │ │ histogram(22)= 0 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 28806 1200 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 28806 1200 29406 600 29406 600 29406 600 29406 600 28806 1200 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 - │ │ │ │ <--- 197 ------- 23686 ------- 53253 ------- 90435 ------- 121730 ------- 153280 ------- 175456 ------- 208548 ------- 242209 ------- 273057 ------- 296640 ------- 330307 ------- 360999 ------- 386307 ------- 420225 ------- 450050 ------- 477795 ------- 504711 ------- 533153 ------- 556672 ------- 582243 ------- 613729 ------- 646117 ------- 675840 ------- 706048 ------- 733063 ------- 769282 ------- 793922 ------- 820357 ------- 849536 ------- 875719 ------- 905028 ------- 940643 ------- 968355 ------- 998721 ------- 1023621 ------- 1059424 ------- 1084932 ------- 1115553 ------- 1139363 ------- 1167361 ------- 1194400 ------- 1225984 ------- 1253861 ------- 1281633 ------- 1304999 ------- 1336355 ------- 1370759 ------- 1400832 ------- 1434085 ------- 1458852 ------- 1491427 ------- 1525120 ------- 1555205 ------- 1591300 ------- 1619426 ------- 1651458 ------- 1682950 ------- 1711399 ------- 1747591 ------- 1787205 ------- 1822240 ------- 1856163 ------- 1886915 ------- 1910949 ------- 1947202 ------- 1974311 ------- 2009286 ------- 2044034 ------- 2079104 ------- 2103488 ------- 2134657 ------- 2164293 ------- 2204514 ------- 2230823 ------- 2265253 ------- 2289826 ------- 2329539 ------- 2364455 ------- 2393507 ------- 2414628 ------- 2440228 ------- 2465255 ------- 2489568 ------- 2520900 ------- 2554919 ------- 2583333 ------- 2612966 ------- 2644833 ------- 2667362 ------- 2702784 ------- 2727394 ------- 2759748 ------- 2794531 ------- 2822214 ------- 2846624 ------- 2883748 ------- 2919586 ------- 2951908 ------- 2980068 ------- 3014726 ------- 3050725 ------- 3081028 ------- 3113351 ------- 3150243 ------- 3185669 ------- 3214311 ------- 3241281 ------- 3275748 ------- 3303232 ------- 3339559 ------- 3370627 ------- 3393664 ------- 3435265 ------- 3464581 ------- 3489026 ------- 3516096 ------- 3548480 ------- 3587015 ------- 3611239 ------- 3638724 ------- 3668641 ------- 3695751 ------- 3729636 ------- 3751523 ------- 3784608 ------- 3815715 ------- 3848608 ------- 3881184 ------- 3908738 ------- 3940002 ------- 3966176 ------- 4001984 ------- 4035687 ------- 4065283 ------- 4092834 ------- 4133062 ------- 4160613 ------- 4196421 ------- 4223713 ------- 4254788 ------- 4291040 ------- 4313664 ------- 4342823 ------- 4369952 ------- 4391684 ------- 4419040 ------- 4449921 ------- 4471781 ------- 4506210 ------- 4538176 ------- 4571297 ------- 4601121 ------- 4630887 ------- 4657476 ------- 4684803 ------- 4714566 ------- 4744070 ------- 4776385 ------- 4807777 ------- 4839491 ------- 4873953 ------- 4902245 ------- 4936263 ------- 4970721 ------- 5003140 ------- 5029729 ------- 5059010 ------- 5087521 ------- 5121093 ------- 5150405 ------- 5178375 ------- 5203683 ------- 5234531 ------- 5268195 ------- 5300004 ------- 5331558 ------- 5362178 ------- 5385762 ------- 5418498 ------- 5445762 ------- 5483109 ------- 5514561 ------- 5542052 ------- 5569572 ------- 5596102 ------- 5622401 ------- 5652194 ------- 5671362 ------- 5699591 ------- 5727136 ------- 5753284 ------- 5780742 ------- 5809189 ------- 5836545 ------- 5864454 ------- 5894917 ------- 5933825 ------- 5968933 ------- 5999590 - │ │ │ │ histogram(26)= 0 1.1342e+05 5.766e+06 1.2182e+05 - │ │ │ │ <----- 1.0 ---------------- 50.0 -- - │ │ │ └── ordering: +22 - │ │ ├── semi-join (merge) - │ │ │ ├── save-table-name: q18_merge_join_6 - │ │ │ ├── columns: o_orderkey:11(int!null) o_custkey:12(int!null) o_totalprice:14(float!null) o_orderdate:15(date!null) - │ │ │ ├── left ordering: +11 - │ │ │ ├── right ordering: +40 - │ │ │ ├── stats: [rows=509090, distinct(11)=509090, null(11)=0, distinct(12)=99649.1, null(12)=0, distinct(14)=506350, null(14)=0, distinct(15)=2406, null(15)=0] - │ │ │ ├── key: (11) - │ │ │ ├── fd: (11)-->(12,14,15) - │ │ │ ├── ordering: +11 - │ │ │ ├── scan orders - │ │ │ │ ├── save-table-name: q18_scan_7 - │ │ │ │ ├── columns: o_orderkey:11(int!null) o_custkey:12(int!null) o_totalprice:14(float!null) o_orderdate:15(date!null) - │ │ │ │ ├── stats: [rows=1500000, distinct(11)=1.5e+06, null(11)=0, distinct(12)=99846, null(12)=0, distinct(14)=1.45917e+06, null(14)=0, distinct(15)=2406, null(15)=0] - │ │ │ │ │ histogram(11)= 0 0 0 0.99998 7406.9 0.99998 7327.9 0.99998 7748.9 0.99998 7433.9 0.99998 8029.9 0.99998 7265.9 0.99998 7439.9 0.99998 7823.9 0.99998 7526.9 0.99998 7553.9 0.99998 7426.9 0.99998 7490.9 0.99998 7595.9 0.99998 7527.9 0.99998 7640.9 0.99998 7593.9 0.99998 7384.9 0.99998 7713.9 0.99998 7409.9 0.99998 7249.9 0.99998 7518.9 0.99998 7434.9 0.99998 7575.9 0.99998 7471.9 0.99998 7302.9 0.99998 7109.9 0.99998 7646.9 0.99998 7619.9 0.99998 7579.9 0.99998 7489.9 0.99998 7409.9 0.99998 7619.9 0.99998 7805.9 0.99998 7418.9 0.99998 7454.9 0.99998 7651.9 0.99998 7407.9 0.99998 7278.9 0.99998 7402.9 0.99998 7375.9 0.99998 7375.9 0.99998 7517.9 0.99998 7626.9 0.99998 7675.9 0.99998 7470.9 0.99998 7352.9 0.99998 7597.9 0.99998 7649.9 0.99998 7509.9 0.99998 7320.9 0.99998 7287.9 0.99998 7365.9 0.99998 7381.9 0.99998 7478.9 0.99998 7526.9 0.99998 7233.9 0.99998 7676.9 0.99998 7400.9 0.99998 7739.9 0.99998 7638.9 0.99998 7515.9 0.99998 7211.9 0.99998 7231.9 0.99998 7194.9 0.99998 7187.9 0.99998 7885.9 0.99998 7359.9 0.99998 7301.9 0.99998 7493.9 0.99998 7529.9 0.99998 7558.9 0.99998 7148.9 0.99998 7437.9 0.99998 7337.9 0.99998 7299.9 0.99998 7683.9 0.99998 7430.9 0.99998 7252.9 0.99998 7440.9 0.99998 7467.9 0.99998 7694.9 0.99998 7528.9 0.99998 7441.9 0.99998 7694.9 0.99998 7737.9 0.99998 7523.9 0.99998 7400.9 0.99998 7523.9 0.99998 7700.9 0.99998 7156.9 0.99998 7352.9 0.99998 7359.9 0.99998 7334.9 0.99998 7444.9 0.99998 7766.9 0.99998 7675.9 0.99998 7511.9 0.99998 7616.9 0.99998 7308.9 0.99998 7593.9 0.99998 7296.9 0.99998 7557.9 0.99998 7416.9 0.99998 7613.9 0.99998 7421.9 0.99998 7322.9 0.99998 7584.9 0.99998 7726.9 0.99998 7495.9 0.99998 7434.9 0.99998 7337.9 0.99998 7450.9 0.99998 7576.9 0.99998 7245.9 0.99998 7625.9 0.99998 7748.9 0.99998 7417.9 0.99998 7701.9 0.99998 7437.9 0.99998 7345.9 0.99998 7517.9 0.99998 7621.9 0.99998 7359.9 0.99998 7393.9 0.99998 7632.9 0.99998 7715.9 0.99998 7558.9 0.99998 7350.9 0.99998 7557.9 0.99998 7400.9 0.99998 7297.9 0.99998 7875.9 0.99998 7364.9 0.99998 7332.9 0.99998 7458.9 0.99998 7471.9 0.99998 7564.9 0.99998 7523.9 0.99998 7270.9 0.99998 7309.9 0.99998 7418.9 0.99998 7959.9 0.99998 7382.9 0.99998 7507.9 0.99998 7524.9 0.99998 7566.9 0.99998 7705.9 0.99998 7841.9 0.99998 7483.9 0.99998 7685.9 0.99998 7605.9 0.99998 7677.9 0.99998 7647.9 0.99998 7985.9 0.99998 7859.9 0.99998 7673.9 0.99998 7732.9 0.99998 7501.9 0.99998 7498.9 0.99998 7596.9 0.99998 7572.9 0.99998 7848.9 0.99998 7567.9 0.99998 7549.9 0.99998 7493.9 0.99998 7869.9 0.99998 7508.9 0.99998 7626.9 0.99998 7774.9 0.99998 7908.9 0.99998 7501.9 0.99998 7841.9 0.99998 7542.9 0.99998 7623.9 0.99998 7523.9 0.99998 7548.9 0.99998 7977.9 0.99998 7569.9 0.99998 7916.9 0.99998 7613.9 0.99998 7883.9 0.99998 7579.9 0.99998 8076.9 0.99998 7698.9 0.99998 7635.9 0.99998 7530.9 0.99998 7515.9 0.99998 7673.9 0.99998 7781.9 0.99998 7698.9 0.99998 7482.9 0.99998 7805.9 0.99998 7774.9 0.99998 7657.9 0.99998 7655.9 0.99998 7579.9 0.99998 7506.9 0.99998 7736.9 0.99998 7584.9 0.99998 0 0 - │ │ │ │ │ <--- -9223372036854775808 --- 1505 --------- 29025 -------- 54400 -------- 91106 -------- 119366 -------- 163554 -------- 187236 -------- 215651 -------- 254373 -------- 285123 -------- 316614 -------- 344678 -------- 374465 -------- 407078 -------- 437861 -------- 471683 -------- 504230 -------- 531168 -------- 566951 -------- 594561 -------- 617825 -------- 648358 -------- 676640 -------- 708706 -------- 737986 -------- 762690 -------- 782081 -------- 816064 -------- 849318 -------- 881511 -------- 911271 -------- 938885 -------- 972135 -------- 1010370 -------- 1038212 -------- 1067041 -------- 1101158 -------- 1128704 -------- 1152742 -------- 1180165 -------- 1206852 -------- 1233537 -------- 1264064 -------- 1297504 -------- 1332260 -------- 1361504 -------- 1387553 -------- 1420224 -------- 1454275 -------- 1484580 -------- 1509766 -------- 1534050 -------- 1560452 -------- 1587299 -------- 1616771 -------- 1647526 -------- 1670343 -------- 1705121 -------- 1732486 -------- 1768967 -------- 1802725 -------- 1833189 -------- 1855398 -------- 1878146 -------- 1899877 -------- 1921414 -------- 1961765 -------- 1988000 -------- 2012672 -------- 2042529 -------- 2073381 -------- 2104999 -------- 2125477 -------- 2153825 -------- 2179462 -------- 2204065 -------- 2239044 -------- 2267205 -------- 2290530 -------- 2318977 -------- 2348134 -------- 2383399 -------- 2414215 -------- 2442695 -------- 2477955 -------- 2514372 -------- 2545062 -------- 2572418 -------- 2603108 -------- 2638534 -------- 2659232 -------- 2685286 -------- 2711527 -------- 2737088 -------- 2765639 -------- 2802818 -------- 2837570 -------- 2867911 -------- 2901088 -------- 2925954 -------- 2958501 -------- 2983042 -------- 3014626 -------- 3042406 -------- 3075489 -------- 3103425 -------- 3128673 -------- 3160994 -------- 3197125 -------- 3227043 -------- 3255328 -------- 3280965 -------- 3309669 -------- 3341767 -------- 3364898 -------- 3398305 -------- 3435008 -------- 3462818 -------- 3498272 -------- 3526631 -------- 3552485 -------- 3583014 -------- 3616322 -------- 3642566 -------- 3669732 -------- 3703330 -------- 3739170 -------- 3770791 -------- 3796804 -------- 3828387 -------- 3855751 -------- 3880321 -------- 3920422 -------- 3946818 -------- 3972322 -------- 4001250 -------- 4030533 -------- 4062306 -------- 4092992 -------- 4116803 -------- 4141697 -------- 4169536 -------- 4211878 -------- 4238753 -------- 4268994 -------- 4299686 -------- 4331525 -------- 4367079 -------- 4406277 -------- 4435878 -------- 4470914 -------- 4500294 -------- 4531617 -------- 4562114 -------- 4601666 -------- 4637856 -------- 4669060 -------- 4701861 -------- 4728416 -------- 4754881 -------- 4784001 -------- 4812482 -------- 4848389 -------- 4876741 -------- 4904612 -------- 4930945 -------- 4967397 -------- 4994146 -------- 5024099 -------- 5058023 -------- 5095527 -------- 5122081 -------- 5157798 -------- 5185472 -------- 5215332 -------- 5242497 -------- 5270338 -------- 5309699 -------- 5338112 -------- 5375843 -------- 5405441 -------- 5442277 -------- 5470945 -------- 5512930 -------- 5544807 -------- 5574980 -------- 5602340 -------- 5629280 -------- 5660482 -------- 5694599 -------- 5726466 -------- 5752519 -------- 5787268 -------- 5821185 -------- 5851973 -------- 5882689 -------- 5911363 -------- 5938052 -------- 5970949 -------- 5999748 --- 9223372036854775807 - │ │ │ │ │ histogram(12)= 0 150 7350 150 7350 150 7350 150 7350 150 7200 300 7350 150 7200 450 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7200 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 300 7350 150 7350 150 7350 300 7350 300 7350 150 7350 150 7350 150 7200 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7200 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7200 300 7350 150 7350 150 7350 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7200 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7200 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7500 150 7500 300 7350 150 7500 300 7350 150 7500 300 7350 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 300 7350 300 7350 300 7350 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 300 7350 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7350 300 7500 150 7500 150 - │ │ │ │ │ <--- 4 ------ 959 ------ 1858 ------ 2773 ------ 3466 ------ 4333 ------ 5026 ------ 5872 ------ 6571 ------ 7069 ------ 7897 ------ 8611 ------ 9514 ------ 10309 ------ 11038 ------ 11893 ------ 12632 ------ 13450 ------ 14104 ------ 14923 ------ 15719 ------ 16382 ------ 17119 ------ 17882 ------ 18701 ------ 19576 ------ 20314 ------ 20950 ------ 21727 ------ 22261 ------ 23059 ------ 23692 ------ 24488 ------ 25144 ------ 25895 ------ 26747 ------ 27650 ------ 28408 ------ 29140 ------ 29920 ------ 30511 ------ 31261 ------ 31999 ------ 32920 ------ 33688 ------ 34525 ------ 35197 ------ 35876 ------ 36580 ------ 37313 ------ 37924 ------ 38768 ------ 39440 ------ 40127 ------ 41005 ------ 41810 ------ 42422 ------ 43310 ------ 44095 ------ 44644 ------ 45347 ------ 45970 ------ 46634 ------ 47284 ------ 48055 ------ 48850 ------ 49712 ------ 50356 ------ 51268 ------ 52048 ------ 52571 ------ 53125 ------ 54088 ------ 54913 ------ 55771 ------ 56386 ------ 57085 ------ 57877 ------ 58729 ------ 59353 ------ 60133 ------ 60947 ------ 61672 ------ 62411 ------ 63296 ------ 64000 ------ 64586 ------ 65251 ------ 65914 ------ 66403 ------ 66991 ------ 67798 ------ 68494 ------ 69406 ------ 70106 ------ 70921 ------ 71770 ------ 72482 ------ 73256 ------ 74083 ------ 74681 ------ 75412 ------ 76201 ------ 76876 ------ 77684 ------ 78421 ------ 79058 ------ 79909 ------ 80591 ------ 81247 ------ 81964 ------ 82835 ------ 83731 ------ 84467 ------ 85012 ------ 85874 ------ 86647 ------ 87151 ------ 87853 ------ 88543 ------ 89425 ------ 90046 ------ 90640 ------ 91544 ------ 92257 ------ 93107 ------ 93835 ------ 94424 ------ 95383 ------ 96313 ------ 96938 ------ 97808 ------ 98689 ------ 99505 ------ 100144 ------ 100981 ------ 101797 ------ 102556 ------ 103504 ------ 104113 ------ 104980 ------ 105622 ------ 106241 ------ 106988 ------ 107578 ------ 108302 ------ 108905 ------ 109765 ------ 110663 ------ 111409 ------ 112093 ------ 113033 ------ 113683 ------ 114346 ------ 115006 ------ 115798 ------ 116261 ------ 116908 ------ 117610 ------ 118319 ------ 119203 ------ 120058 ------ 120922 ------ 121702 ------ 122486 ------ 123253 ------ 124142 ------ 124795 ------ 125689 ------ 126277 ------ 126904 ------ 127684 ------ 128251 ------ 129032 ------ 129916 ------ 130717 ------ 131554 ------ 132482 ------ 133408 ------ 134272 ------ 135073 ------ 135869 ------ 136963 ------ 137806 ------ 138412 ------ 139103 ------ 139982 ------ 140794 ------ 141455 ------ 142396 ------ 143047 ------ 143788 ------ 144620 ------ 145336 ------ 146170 ------ 147014 ------ 147769 ------ 148508 ------ 149234 ------ 149995 - │ │ │ │ │ histogram(14)= 0 150 1.4997e+06 150 - │ │ │ │ │ <--- 1094.65 ------------ 477728.86 - │ │ │ │ │ histogram(15)= 0 450 6900 600 7350 600 6750 900 7050 1350 7350 1350 6750 900 6600 900 7350 600 7200 600 7350 1050 6900 750 6900 750 7350 450 7350 600 7200 750 7350 450 7200 750 7350 750 6150 1200 7050 300 7200 600 7200 300 6600 1350 7050 450 6750 600 7200 750 7050 450 6750 600 7200 900 7050 900 7050 750 7050 600 7200 750 6150 1200 7200 1200 6000 1350 6300 1200 7200 750 6750 1200 6600 900 7050 750 7050 450 7050 900 7200 450 7200 1050 6900 900 6300 1200 6750 600 7050 900 7050 450 6900 1200 6750 600 7050 750 6750 1350 7050 600 7050 300 7200 450 7050 600 6900 450 6900 450 7200 600 6600 900 6900 750 5700 1800 6900 750 6300 1050 7050 900 7200 300 7050 450 6600 750 6450 1200 6900 600 7050 1050 7050 450 6600 750 7050 600 6450 900 7050 600 7200 900 6750 900 7200 750 7200 1050 6750 600 6900 600 6900 1050 7050 450 7050 750 6000 1350 6750 900 6900 900 6900 900 7050 1050 6750 600 7050 900 6450 900 7050 300 6600 750 7050 1350 7200 450 7200 750 7200 600 6300 900 7050 750 6450 900 6900 900 6600 600 6600 600 6900 750 7050 600 6150 1050 6750 600 6600 600 7050 900 7050 1650 6750 600 6750 600 6750 450 7050 1050 6900 1350 6600 600 6300 900 6600 600 6300 1050 6750 900 6300 900 7050 1200 6600 1200 6750 750 6900 900 6750 600 6750 600 6150 1200 6450 1050 7050 750 6300 1050 7050 450 6750 600 6750 600 7050 600 7050 900 6900 600 6900 900 6900 600 6450 1200 6600 450 6900 450 6750 600 6750 750 6750 1350 6750 450 6600 750 6600 450 6450 750 6450 600 6750 600 6900 900 6300 750 6450 1200 6000 1500 6900 900 6000 1200 6300 750 6450 600 6900 1050 6600 600 6900 1650 5850 1050 6600 750 6600 450 6300 900 6600 300 6600 600 6750 900 6750 450 6600 750 6600 300 6150 900 6750 600 5850 1050 6750 450 6750 750 6600 900 6150 600 6600 450 6150 750 6600 1350 6600 450 6000 1200 5550 1350 6150 450 6300 450 6450 900 6450 750 6000 1650 5850 750 6000 450 5250 900 5400 1050 5400 600 - │ │ │ │ │ <--- '1992-01-01' ------ '1992-01-13' ------ '1992-01-25' ------ '1992-02-05' ------ '1992-02-18' ------ '1992-02-29' ------ '1992-03-12' ------ '1992-03-23' ------ '1992-04-05' ------ '1992-04-17' ------ '1992-04-30' ------ '1992-05-16' ------ '1992-05-28' ------ '1992-06-09' ------ '1992-06-22' ------ '1992-07-04' ------ '1992-07-15' ------ '1992-07-26' ------ '1992-08-09' ------ '1992-08-19' ------ '1992-09-01' ------ '1992-09-12' ------ '1992-09-23' ------ '1992-10-04' ------ '1992-10-17' ------ '1992-10-27' ------ '1992-11-06' ------ '1992-11-19' ------ '1992-11-30' ------ '1992-12-12' ------ '1992-12-23' ------ '1993-01-06' ------ '1993-01-18' ------ '1993-01-31' ------ '1993-02-08' ------ '1993-02-21' ------ '1993-03-01' ------ '1993-03-16' ------ '1993-03-27' ------ '1993-04-07' ------ '1993-04-21' ------ '1993-05-02' ------ '1993-05-14' ------ '1993-05-28' ------ '1993-06-08' ------ '1993-06-20' ------ '1993-07-02' ------ '1993-07-16' ------ '1993-07-29' ------ '1993-08-12' ------ '1993-08-25' ------ '1993-09-07' ------ '1993-09-22' ------ '1993-10-05' ------ '1993-10-18' ------ '1993-10-31' ------ '1993-11-14' ------ '1993-11-25' ------ '1993-12-06' ------ '1993-12-20' ------ '1994-01-03' ------ '1994-01-15' ------ '1994-01-23' ------ '1994-02-04' ------ '1994-02-15' ------ '1994-02-27' ------ '1994-03-09' ------ '1994-03-19' ------ '1994-04-05' ------ '1994-04-16' ------ '1994-04-29' ------ '1994-05-10' ------ '1994-05-24' ------ '1994-06-04' ------ '1994-06-16' ------ '1994-06-30' ------ '1994-07-16' ------ '1994-07-31' ------ '1994-08-13' ------ '1994-08-27' ------ '1994-09-08' ------ '1994-09-23' ------ '1994-10-06' ------ '1994-10-17' ------ '1994-10-28' ------ '1994-11-11' ------ '1994-11-25' ------ '1994-12-11' ------ '1994-12-22' ------ '1995-01-03' ------ '1995-01-17' ------ '1995-01-30' ------ '1995-02-09' ------ '1995-02-23' ------ '1995-03-10' ------ '1995-03-21' ------ '1995-04-04' ------ '1995-04-15' ------ '1995-04-27' ------ '1995-05-12' ------ '1995-05-26' ------ '1995-06-04' ------ '1995-06-13' ------ '1995-06-26' ------ '1995-07-08' ------ '1995-07-19' ------ '1995-07-31' ------ '1995-08-12' ------ '1995-08-21' ------ '1995-09-04' ------ '1995-09-13' ------ '1995-09-25' ------ '1995-10-06' ------ '1995-10-22' ------ '1995-10-30' ------ '1995-11-11' ------ '1995-11-23' ------ '1995-12-06' ------ '1995-12-19' ------ '1996-01-01' ------ '1996-01-13' ------ '1996-01-23' ------ '1996-02-03' ------ '1996-02-14' ------ '1996-02-24' ------ '1996-03-05' ------ '1996-03-17' ------ '1996-03-26' ------ '1996-04-09' ------ '1996-04-21' ------ '1996-05-03' ------ '1996-05-15' ------ '1996-05-28' ------ '1996-06-06' ------ '1996-06-16' ------ '1996-06-27' ------ '1996-07-11' ------ '1996-07-24' ------ '1996-08-07' ------ '1996-08-20' ------ '1996-09-04' ------ '1996-09-17' ------ '1996-10-05' ------ '1996-10-18' ------ '1996-10-29' ------ '1996-11-07' ------ '1996-11-20' ------ '1996-11-30' ------ '1996-12-15' ------ '1996-12-30' ------ '1997-01-13' ------ '1997-01-25' ------ '1997-02-05' ------ '1997-02-15' ------ '1997-02-24' ------ '1997-03-06' ------ '1997-03-18' ------ '1997-03-30' ------ '1997-04-09' ------ '1997-04-21' ------ '1997-05-01' ------ '1997-05-12' ------ '1997-05-24' ------ '1997-06-04' ------ '1997-06-15' ------ '1997-06-28' ------ '1997-07-10' ------ '1997-07-20' ------ '1997-07-30' ------ '1997-08-13' ------ '1997-08-24' ------ '1997-09-04' ------ '1997-09-16' ------ '1997-09-29' ------ '1997-10-15' ------ '1997-10-30' ------ '1997-11-13' ------ '1997-11-25' ------ '1997-12-06' ------ '1997-12-18' ------ '1997-12-30' ------ '1998-01-10' ------ '1998-01-23' ------ '1998-02-02' ------ '1998-02-15' ------ '1998-02-28' ------ '1998-03-11' ------ '1998-03-24' ------ '1998-04-03' ------ '1998-04-12' ------ '1998-04-24' ------ '1998-05-05' ------ '1998-05-18' ------ '1998-05-31' ------ '1998-06-11' ------ '1998-06-20' ------ '1998-06-30' ------ '1998-07-12' ------ '1998-07-23' ------ '1998-08-02' - │ │ │ │ ├── key: (11) - │ │ │ │ ├── fd: (11)-->(12,14,15) - │ │ │ │ └── ordering: +11 - │ │ │ ├── select - │ │ │ │ ├── save-table-name: q18_select_8 - │ │ │ │ ├── columns: l_orderkey:40(int!null) sum:58(float!null) - │ │ │ │ ├── stats: [rows=509090, distinct(40)=509090, null(40)=0, distinct(58)=509090, null(58)=0] - │ │ │ │ ├── key: (40) - │ │ │ │ ├── fd: (40)-->(58) - │ │ │ │ ├── ordering: +40 - │ │ │ │ ├── group-by (streaming) - │ │ │ │ │ ├── save-table-name: q18_group_by_9 - │ │ │ │ │ ├── columns: l_orderkey:40(int!null) sum:58(float!null) - │ │ │ │ │ ├── grouping columns: l_orderkey:40(int!null) - │ │ │ │ │ ├── stats: [rows=1527270, distinct(40)=1.52727e+06, null(40)=0, distinct(58)=1.52727e+06, null(58)=0] - │ │ │ │ │ ├── key: (40) - │ │ │ │ │ ├── fd: (40)-->(58) - │ │ │ │ │ ├── ordering: +40 - │ │ │ │ │ ├── scan lineitem - │ │ │ │ │ │ ├── save-table-name: q18_scan_10 - │ │ │ │ │ │ ├── columns: l_orderkey:40(int!null) l_quantity:44(float!null) - │ │ │ │ │ │ ├── stats: [rows=6001215, distinct(40)=1.52727e+06, null(40)=0, distinct(44)=50, null(44)=0] - │ │ │ │ │ │ │ histogram(40)= 0 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 28806 1200 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 28806 1200 29406 600 29406 600 29406 600 29406 600 28806 1200 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 - │ │ │ │ │ │ │ <--- 197 ------- 23686 ------- 53253 ------- 90435 ------- 121730 ------- 153280 ------- 175456 ------- 208548 ------- 242209 ------- 273057 ------- 296640 ------- 330307 ------- 360999 ------- 386307 ------- 420225 ------- 450050 ------- 477795 ------- 504711 ------- 533153 ------- 556672 ------- 582243 ------- 613729 ------- 646117 ------- 675840 ------- 706048 ------- 733063 ------- 769282 ------- 793922 ------- 820357 ------- 849536 ------- 875719 ------- 905028 ------- 940643 ------- 968355 ------- 998721 ------- 1023621 ------- 1059424 ------- 1084932 ------- 1115553 ------- 1139363 ------- 1167361 ------- 1194400 ------- 1225984 ------- 1253861 ------- 1281633 ------- 1304999 ------- 1336355 ------- 1370759 ------- 1400832 ------- 1434085 ------- 1458852 ------- 1491427 ------- 1525120 ------- 1555205 ------- 1591300 ------- 1619426 ------- 1651458 ------- 1682950 ------- 1711399 ------- 1747591 ------- 1787205 ------- 1822240 ------- 1856163 ------- 1886915 ------- 1910949 ------- 1947202 ------- 1974311 ------- 2009286 ------- 2044034 ------- 2079104 ------- 2103488 ------- 2134657 ------- 2164293 ------- 2204514 ------- 2230823 ------- 2265253 ------- 2289826 ------- 2329539 ------- 2364455 ------- 2393507 ------- 2414628 ------- 2440228 ------- 2465255 ------- 2489568 ------- 2520900 ------- 2554919 ------- 2583333 ------- 2612966 ------- 2644833 ------- 2667362 ------- 2702784 ------- 2727394 ------- 2759748 ------- 2794531 ------- 2822214 ------- 2846624 ------- 2883748 ------- 2919586 ------- 2951908 ------- 2980068 ------- 3014726 ------- 3050725 ------- 3081028 ------- 3113351 ------- 3150243 ------- 3185669 ------- 3214311 ------- 3241281 ------- 3275748 ------- 3303232 ------- 3339559 ------- 3370627 ------- 3393664 ------- 3435265 ------- 3464581 ------- 3489026 ------- 3516096 ------- 3548480 ------- 3587015 ------- 3611239 ------- 3638724 ------- 3668641 ------- 3695751 ------- 3729636 ------- 3751523 ------- 3784608 ------- 3815715 ------- 3848608 ------- 3881184 ------- 3908738 ------- 3940002 ------- 3966176 ------- 4001984 ------- 4035687 ------- 4065283 ------- 4092834 ------- 4133062 ------- 4160613 ------- 4196421 ------- 4223713 ------- 4254788 ------- 4291040 ------- 4313664 ------- 4342823 ------- 4369952 ------- 4391684 ------- 4419040 ------- 4449921 ------- 4471781 ------- 4506210 ------- 4538176 ------- 4571297 ------- 4601121 ------- 4630887 ------- 4657476 ------- 4684803 ------- 4714566 ------- 4744070 ------- 4776385 ------- 4807777 ------- 4839491 ------- 4873953 ------- 4902245 ------- 4936263 ------- 4970721 ------- 5003140 ------- 5029729 ------- 5059010 ------- 5087521 ------- 5121093 ------- 5150405 ------- 5178375 ------- 5203683 ------- 5234531 ------- 5268195 ------- 5300004 ------- 5331558 ------- 5362178 ------- 5385762 ------- 5418498 ------- 5445762 ------- 5483109 ------- 5514561 ------- 5542052 ------- 5569572 ------- 5596102 ------- 5622401 ------- 5652194 ------- 5671362 ------- 5699591 ------- 5727136 ------- 5753284 ------- 5780742 ------- 5809189 ------- 5836545 ------- 5864454 ------- 5894917 ------- 5933825 ------- 5968933 ------- 5999590 - │ │ │ │ │ │ │ histogram(44)= 0 1.1342e+05 5.766e+06 1.2182e+05 - │ │ │ │ │ │ │ <----- 1.0 ---------------- 50.0 -- - │ │ │ │ │ │ └── ordering: +40 - │ │ │ │ │ └── aggregations - │ │ │ │ │ └── sum [as=sum:58, type=float, outer=(44)] - │ │ │ │ │ └── l_quantity:44 [type=float] - │ │ │ │ └── filters - │ │ │ │ └── sum:58 > 300.0 [type=bool, outer=(58), constraints=(/58: [/300.00000000000006 - ]; tight)] - │ │ │ └── filters (true) - │ │ └── filters (true) - │ ├── scan customer - │ │ ├── save-table-name: q18_scan_11 - │ │ ├── columns: c_custkey:1(int!null) c_name:2(varchar!null) - │ │ ├── stats: [rows=150000, distinct(1)=148813, null(1)=0, distinct(2)=150000, null(2)=0] - │ │ │ histogram(1)= 0 0 0 5 745 5 746 5 711 5 780 5 738 5 835 5 697 5 757 5 704 5 696 5 753 5 678 5 813 5 873 5 736 5 840 5 703 5 745 5 710 5 763 5 742 5 673 5 702 5 793 5 732 5 752 5 707 5 751 5 722 5 814 5 789 5 671 5 643 5 706 5 723 5 757 5 713 5 760 5 766 5 711 5 858 5 702 5 695 5 697 5 823 5 857 5 712 5 808 5 754 5 739 5 694 5 782 5 792 5 751 5 758 5 749 5 798 5 685 5 692 5 792 5 710 5 771 5 724 5 853 5 713 5 823 5 772 5 656 5 763 5 672 5 735 5 810 5 786 5 709 5 731 5 702 5 708 5 669 5 733 5 744 5 758 5 800 5 682 5 716 5 716 5 729 5 778 5 721 5 766 5 820 5 757 5 739 5 799 5 780 5 710 5 749 5 754 5 750 5 699 5 821 5 759 5 818 5 763 5 854 5 779 5 810 5 783 5 686 5 703 5 776 5 675 5 812 5 745 5 759 5 793 5 751 5 761 5 798 5 794 5 729 5 696 5 699 5 831 5 709 5 747 5 722 5 768 5 729 5 702 5 729 5 698 5 767 5 792 5 726 5 737 5 671 5 721 5 842 5 701 5 704 5 708 5 726 5 695 5 665 5 688 5 653 5 690 5 734 5 789 5 659 5 785 5 733 5 740 5 826 5 745 5 929 5 899 5 743 5 790 5 825 5 779 5 677 5 697 5 756 5 693 5 862 5 772 5 783 5 757 5 799 5 778 5 752 5 715 5 709 5 790 5 789 5 865 5 808 5 772 5 743 5 751 5 742 5 676 5 684 5 744 5 709 5 679 5 817 5 755 5 754 5 797 5 709 5 748 5 679 5 751 5 775 5 736 5 790 5 714 5 0 0 - │ │ │ <--- -9223372036854775808 --- 59 ----- 811 ----- 1565 ----- 2252 ----- 3068 ----- 3807 ----- 4720 ----- 5381 ----- 6155 ----- 6829 ----- 7487 ----- 8254 ----- 8876 ----- 9751 ----- 10728 ----- 11463 ----- 12385 ----- 13057 ----- 13810 ----- 14495 ----- 15281 ----- 16028 ----- 16640 ----- 17311 ----- 18151 ----- 18880 ----- 19645 ----- 20325 ----- 21088 ----- 21798 ----- 22674 ----- 23507 ----- 24115 ----- 24661 ----- 25340 ----- 26052 ----- 26827 ----- 27518 ----- 28298 ----- 29089 ----- 29777 ----- 30730 ----- 31401 ----- 32057 ----- 32718 ----- 33611 ----- 34562 ----- 35251 ----- 36117 ----- 36887 ----- 37629 ----- 38283 ----- 39104 ----- 39942 ----- 40705 ----- 41481 ----- 42241 ----- 43089 ----- 43725 ----- 44376 ----- 45214 ----- 45899 ----- 46700 ----- 47413 ----- 48356 ----- 49047 ----- 49939 ----- 50742 ----- 51316 ----- 52101 ----- 52710 ----- 53444 ----- 54313 ----- 55140 ----- 55823 ----- 56549 ----- 57219 ----- 57901 ----- 58503 ----- 59234 ----- 59984 ----- 60760 ----- 61613 ----- 62243 ----- 62941 ----- 63638 ----- 64360 ----- 65173 ----- 65880 ----- 66672 ----- 67560 ----- 68334 ----- 69075 ----- 69925 ----- 70742 ----- 71428 ----- 72189 ----- 72958 ----- 73720 ----- 74385 ----- 75274 ----- 76053 ----- 76936 ----- 77721 ----- 78666 ----- 79480 ----- 80349 ----- 81171 ----- 81810 ----- 82482 ----- 83292 ----- 83907 ----- 84780 ----- 85532 ----- 86310 ----- 87149 ----- 87912 ----- 88694 ----- 89543 ----- 90384 ----- 91106 ----- 91764 ----- 92428 ----- 93335 ----- 94018 ----- 94775 ----- 95484 ----- 96279 ----- 97001 ----- 97672 ----- 98394 ----- 99056 ----- 99850 ----- 100688 ----- 101405 ----- 102143 ----- 102751 ----- 103459 ----- 104384 ----- 105052 ----- 105727 ----- 106409 ----- 107125 ----- 107782 ----- 108377 ----- 109020 ----- 109588 ----- 110235 ----- 110967 ----- 111800 ----- 112382 ----- 113196 ----- 113913 ----- 114643 ----- 115529 ----- 116268 ----- 117329 ----- 118341 ----- 119076 ----- 119898 ----- 120782 ----- 121584 ----- 122186 ----- 122830 ----- 123591 ----- 124227 ----- 125175 ----- 125964 ----- 126773 ----- 127535 ----- 128374 ----- 129175 ----- 129928 ----- 130609 ----- 131279 ----- 132102 ----- 132923 ----- 133877 ----- 134732 ----- 135521 ----- 136257 ----- 137007 ----- 137740 ----- 138341 ----- 138958 ----- 139695 ----- 140364 ----- 140971 ----- 141841 ----- 142600 ----- 143356 ----- 144192 ----- 144861 ----- 145607 ----- 146214 ----- 146965 ----- 147761 ----- 148483 ----- 149306 ----- 149986 --- 9223372036854775807 - │ │ │ histogram(2)= 0 1 1.5e+05 1 - │ │ │ <--- 'Customer#000000059' --------- 'Customer#000149986' - │ │ ├── key: (1) - │ │ └── fd: (1)-->(2) - │ └── filters - │ └── c_custkey:1 = o_custkey:12 [type=bool, outer=(1,12), constraints=(/1: (/NULL - ]; /12: (/NULL - ]), fd=(1)==(12), (12)==(1)] - └── aggregations - ├── sum [as=sum:59, type=float, outer=(26)] - │ └── l_quantity:26 [type=float] - ├── const-agg [as=c_custkey:1, type=int, outer=(1)] - │ └── c_custkey:1 [type=int] - ├── const-agg [as=c_name:2, type=varchar, outer=(2)] - │ └── c_name:2 [type=varchar] - ├── const-agg [as=o_totalprice:14, type=float, outer=(14)] - │ └── o_totalprice:14 [type=float] - └── const-agg [as=o_orderdate:15, type=date, outer=(15)] - └── o_orderdate:15 [type=date] + ├── group-by (partial streaming) + │ ├── save-table-name: q18_group_by_2 + │ ├── columns: c_custkey:1(int!null) c_name:2(varchar!null) o_orderkey:11(int!null) o_totalprice:14(float!null) o_orderdate:15(date!null) sum:59(float!null) + │ ├── grouping columns: o_orderkey:11(int!null) o_totalprice:14(float!null) o_orderdate:15(date!null) + │ ├── internal-ordering: -14,+15 + │ ├── stats: [rows=499392.2, distinct(1)=499392, null(1)=0, distinct(2)=499392, null(2)=0, distinct(11)=499392, null(11)=0, distinct(14)=488044, null(14)=0, distinct(15)=2406, null(15)=0, distinct(59)=499392, null(59)=0, distinct(11,14,15)=499392, null(11,14,15)=0] + │ ├── key: (11) + │ ├── fd: (1)-->(2), (11)-->(1,2,14,15,59) + │ ├── ordering: -14,+15 + │ ├── limit hint: 100.00 + │ ├── inner-join (lookup lineitem) + │ │ ├── save-table-name: q18_lookup_join_3 + │ │ ├── columns: c_custkey:1(int!null) c_name:2(varchar!null) o_orderkey:11(int!null) o_custkey:12(int!null) o_totalprice:14(float!null) o_orderdate:15(date!null) l_orderkey:22(int!null) l_quantity:26(float!null) + │ │ ├── key columns: [11] = [22] + │ │ ├── stats: [rows=2016361, distinct(1)=99649.1, null(1)=0, distinct(2)=150000, null(2)=0, distinct(11)=499392, null(11)=0, distinct(12)=99649.1, null(12)=0, distinct(14)=488044, null(14)=0, distinct(15)=2406, null(15)=0, distinct(22)=499392, null(22)=0, distinct(26)=50, null(26)=0, distinct(11,14,15)=499392, null(11,14,15)=0] + │ │ ├── fd: (1)-->(2), (11)-->(12,14,15), (11)==(22), (22)==(11), (1)==(12), (12)==(1) + │ │ ├── ordering: -14,+15 + │ │ ├── limit hint: 403.76 + │ │ ├── inner-join (lookup customer) + │ │ │ ├── save-table-name: q18_lookup_join_4 + │ │ │ ├── columns: c_custkey:1(int!null) c_name:2(varchar!null) o_orderkey:11(int!null) o_custkey:12(int!null) o_totalprice:14(float!null) o_orderdate:15(date!null) + │ │ │ ├── key columns: [12] = [1] + │ │ │ ├── lookup columns are key + │ │ │ ├── stats: [rows=513150.7, distinct(1)=99649.1, null(1)=0, distinct(2)=145098, null(2)=0, distinct(11)=323295, null(11)=0, distinct(12)=99649.1, null(12)=0, distinct(14)=322560, null(14)=0, distinct(15)=2406, null(15)=0] + │ │ │ ├── key: (11) + │ │ │ ├── fd: (1)-->(2), (11)-->(12,14,15), (1)==(12), (12)==(1) + │ │ │ ├── ordering: -14,+15 + │ │ │ ├── limit hint: 200.00 + │ │ │ ├── sort + │ │ │ │ ├── save-table-name: q18_sort_5 + │ │ │ │ ├── columns: o_orderkey:11(int!null) o_custkey:12(int!null) o_totalprice:14(float!null) o_orderdate:15(date!null) + │ │ │ │ ├── stats: [rows=509090, distinct(11)=509090, null(11)=0, distinct(12)=99649.1, null(12)=0, distinct(14)=506350, null(14)=0, distinct(15)=2406, null(15)=0, distinct(11,14,15)=509090, null(11,14,15)=0] + │ │ │ │ ├── key: (11) + │ │ │ │ ├── fd: (11)-->(12,14,15) + │ │ │ │ ├── ordering: -14,+15 + │ │ │ │ ├── limit hint: 200.00 + │ │ │ │ └── semi-join (merge) + │ │ │ │ ├── save-table-name: q18_merge_join_6 + │ │ │ │ ├── columns: o_orderkey:11(int!null) o_custkey:12(int!null) o_totalprice:14(float!null) o_orderdate:15(date!null) + │ │ │ │ ├── left ordering: +11 + │ │ │ │ ├── right ordering: +40 + │ │ │ │ ├── stats: [rows=509090, distinct(11)=509090, null(11)=0, distinct(12)=99649.1, null(12)=0, distinct(14)=506350, null(14)=0, distinct(15)=2406, null(15)=0, distinct(11,14,15)=509090, null(11,14,15)=0] + │ │ │ │ ├── key: (11) + │ │ │ │ ├── fd: (11)-->(12,14,15) + │ │ │ │ ├── scan orders + │ │ │ │ │ ├── save-table-name: q18_scan_7 + │ │ │ │ │ ├── columns: o_orderkey:11(int!null) o_custkey:12(int!null) o_totalprice:14(float!null) o_orderdate:15(date!null) + │ │ │ │ │ ├── stats: [rows=1500000, distinct(11)=1.5e+06, null(11)=0, distinct(12)=99846, null(12)=0, distinct(14)=1.45917e+06, null(14)=0, distinct(15)=2406, null(15)=0, distinct(11,14,15)=1.5e+06, null(11,14,15)=0] + │ │ │ │ │ │ histogram(11)= 0 0 0 0.99998 7406.9 0.99998 7327.9 0.99998 7748.9 0.99998 7433.9 0.99998 8029.9 0.99998 7265.9 0.99998 7439.9 0.99998 7823.9 0.99998 7526.9 0.99998 7553.9 0.99998 7426.9 0.99998 7490.9 0.99998 7595.9 0.99998 7527.9 0.99998 7640.9 0.99998 7593.9 0.99998 7384.9 0.99998 7713.9 0.99998 7409.9 0.99998 7249.9 0.99998 7518.9 0.99998 7434.9 0.99998 7575.9 0.99998 7471.9 0.99998 7302.9 0.99998 7109.9 0.99998 7646.9 0.99998 7619.9 0.99998 7579.9 0.99998 7489.9 0.99998 7409.9 0.99998 7619.9 0.99998 7805.9 0.99998 7418.9 0.99998 7454.9 0.99998 7651.9 0.99998 7407.9 0.99998 7278.9 0.99998 7402.9 0.99998 7375.9 0.99998 7375.9 0.99998 7517.9 0.99998 7626.9 0.99998 7675.9 0.99998 7470.9 0.99998 7352.9 0.99998 7597.9 0.99998 7649.9 0.99998 7509.9 0.99998 7320.9 0.99998 7287.9 0.99998 7365.9 0.99998 7381.9 0.99998 7478.9 0.99998 7526.9 0.99998 7233.9 0.99998 7676.9 0.99998 7400.9 0.99998 7739.9 0.99998 7638.9 0.99998 7515.9 0.99998 7211.9 0.99998 7231.9 0.99998 7194.9 0.99998 7187.9 0.99998 7885.9 0.99998 7359.9 0.99998 7301.9 0.99998 7493.9 0.99998 7529.9 0.99998 7558.9 0.99998 7148.9 0.99998 7437.9 0.99998 7337.9 0.99998 7299.9 0.99998 7683.9 0.99998 7430.9 0.99998 7252.9 0.99998 7440.9 0.99998 7467.9 0.99998 7694.9 0.99998 7528.9 0.99998 7441.9 0.99998 7694.9 0.99998 7737.9 0.99998 7523.9 0.99998 7400.9 0.99998 7523.9 0.99998 7700.9 0.99998 7156.9 0.99998 7352.9 0.99998 7359.9 0.99998 7334.9 0.99998 7444.9 0.99998 7766.9 0.99998 7675.9 0.99998 7511.9 0.99998 7616.9 0.99998 7308.9 0.99998 7593.9 0.99998 7296.9 0.99998 7557.9 0.99998 7416.9 0.99998 7613.9 0.99998 7421.9 0.99998 7322.9 0.99998 7584.9 0.99998 7726.9 0.99998 7495.9 0.99998 7434.9 0.99998 7337.9 0.99998 7450.9 0.99998 7576.9 0.99998 7245.9 0.99998 7625.9 0.99998 7748.9 0.99998 7417.9 0.99998 7701.9 0.99998 7437.9 0.99998 7345.9 0.99998 7517.9 0.99998 7621.9 0.99998 7359.9 0.99998 7393.9 0.99998 7632.9 0.99998 7715.9 0.99998 7558.9 0.99998 7350.9 0.99998 7557.9 0.99998 7400.9 0.99998 7297.9 0.99998 7875.9 0.99998 7364.9 0.99998 7332.9 0.99998 7458.9 0.99998 7471.9 0.99998 7564.9 0.99998 7523.9 0.99998 7270.9 0.99998 7309.9 0.99998 7418.9 0.99998 7959.9 0.99998 7382.9 0.99998 7507.9 0.99998 7524.9 0.99998 7566.9 0.99998 7705.9 0.99998 7841.9 0.99998 7483.9 0.99998 7685.9 0.99998 7605.9 0.99998 7677.9 0.99998 7647.9 0.99998 7985.9 0.99998 7859.9 0.99998 7673.9 0.99998 7732.9 0.99998 7501.9 0.99998 7498.9 0.99998 7596.9 0.99998 7572.9 0.99998 7848.9 0.99998 7567.9 0.99998 7549.9 0.99998 7493.9 0.99998 7869.9 0.99998 7508.9 0.99998 7626.9 0.99998 7774.9 0.99998 7908.9 0.99998 7501.9 0.99998 7841.9 0.99998 7542.9 0.99998 7623.9 0.99998 7523.9 0.99998 7548.9 0.99998 7977.9 0.99998 7569.9 0.99998 7916.9 0.99998 7613.9 0.99998 7883.9 0.99998 7579.9 0.99998 8076.9 0.99998 7698.9 0.99998 7635.9 0.99998 7530.9 0.99998 7515.9 0.99998 7673.9 0.99998 7781.9 0.99998 7698.9 0.99998 7482.9 0.99998 7805.9 0.99998 7774.9 0.99998 7657.9 0.99998 7655.9 0.99998 7579.9 0.99998 7506.9 0.99998 7736.9 0.99998 7584.9 0.99998 0 0 + │ │ │ │ │ │ <--- -9223372036854775808 --- 1505 --------- 29025 -------- 54400 -------- 91106 -------- 119366 -------- 163554 -------- 187236 -------- 215651 -------- 254373 -------- 285123 -------- 316614 -------- 344678 -------- 374465 -------- 407078 -------- 437861 -------- 471683 -------- 504230 -------- 531168 -------- 566951 -------- 594561 -------- 617825 -------- 648358 -------- 676640 -------- 708706 -------- 737986 -------- 762690 -------- 782081 -------- 816064 -------- 849318 -------- 881511 -------- 911271 -------- 938885 -------- 972135 -------- 1010370 -------- 1038212 -------- 1067041 -------- 1101158 -------- 1128704 -------- 1152742 -------- 1180165 -------- 1206852 -------- 1233537 -------- 1264064 -------- 1297504 -------- 1332260 -------- 1361504 -------- 1387553 -------- 1420224 -------- 1454275 -------- 1484580 -------- 1509766 -------- 1534050 -------- 1560452 -------- 1587299 -------- 1616771 -------- 1647526 -------- 1670343 -------- 1705121 -------- 1732486 -------- 1768967 -------- 1802725 -------- 1833189 -------- 1855398 -------- 1878146 -------- 1899877 -------- 1921414 -------- 1961765 -------- 1988000 -------- 2012672 -------- 2042529 -------- 2073381 -------- 2104999 -------- 2125477 -------- 2153825 -------- 2179462 -------- 2204065 -------- 2239044 -------- 2267205 -------- 2290530 -------- 2318977 -------- 2348134 -------- 2383399 -------- 2414215 -------- 2442695 -------- 2477955 -------- 2514372 -------- 2545062 -------- 2572418 -------- 2603108 -------- 2638534 -------- 2659232 -------- 2685286 -------- 2711527 -------- 2737088 -------- 2765639 -------- 2802818 -------- 2837570 -------- 2867911 -------- 2901088 -------- 2925954 -------- 2958501 -------- 2983042 -------- 3014626 -------- 3042406 -------- 3075489 -------- 3103425 -------- 3128673 -------- 3160994 -------- 3197125 -------- 3227043 -------- 3255328 -------- 3280965 -------- 3309669 -------- 3341767 -------- 3364898 -------- 3398305 -------- 3435008 -------- 3462818 -------- 3498272 -------- 3526631 -------- 3552485 -------- 3583014 -------- 3616322 -------- 3642566 -------- 3669732 -------- 3703330 -------- 3739170 -------- 3770791 -------- 3796804 -------- 3828387 -------- 3855751 -------- 3880321 -------- 3920422 -------- 3946818 -------- 3972322 -------- 4001250 -------- 4030533 -------- 4062306 -------- 4092992 -------- 4116803 -------- 4141697 -------- 4169536 -------- 4211878 -------- 4238753 -------- 4268994 -------- 4299686 -------- 4331525 -------- 4367079 -------- 4406277 -------- 4435878 -------- 4470914 -------- 4500294 -------- 4531617 -------- 4562114 -------- 4601666 -------- 4637856 -------- 4669060 -------- 4701861 -------- 4728416 -------- 4754881 -------- 4784001 -------- 4812482 -------- 4848389 -------- 4876741 -------- 4904612 -------- 4930945 -------- 4967397 -------- 4994146 -------- 5024099 -------- 5058023 -------- 5095527 -------- 5122081 -------- 5157798 -------- 5185472 -------- 5215332 -------- 5242497 -------- 5270338 -------- 5309699 -------- 5338112 -------- 5375843 -------- 5405441 -------- 5442277 -------- 5470945 -------- 5512930 -------- 5544807 -------- 5574980 -------- 5602340 -------- 5629280 -------- 5660482 -------- 5694599 -------- 5726466 -------- 5752519 -------- 5787268 -------- 5821185 -------- 5851973 -------- 5882689 -------- 5911363 -------- 5938052 -------- 5970949 -------- 5999748 --- 9223372036854775807 + │ │ │ │ │ │ histogram(12)= 0 150 7350 150 7350 150 7350 150 7350 150 7200 300 7350 150 7200 450 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7200 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 300 7350 150 7350 150 7350 300 7350 300 7350 150 7350 150 7350 150 7200 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7200 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7200 300 7350 150 7350 150 7350 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7200 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7200 300 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7350 150 7500 150 7500 300 7350 150 7500 300 7350 150 7500 300 7350 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 300 7350 300 7350 300 7350 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 300 7350 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7500 150 7350 300 7500 150 7500 150 + │ │ │ │ │ │ <--- 4 ------ 959 ------ 1858 ------ 2773 ------ 3466 ------ 4333 ------ 5026 ------ 5872 ------ 6571 ------ 7069 ------ 7897 ------ 8611 ------ 9514 ------ 10309 ------ 11038 ------ 11893 ------ 12632 ------ 13450 ------ 14104 ------ 14923 ------ 15719 ------ 16382 ------ 17119 ------ 17882 ------ 18701 ------ 19576 ------ 20314 ------ 20950 ------ 21727 ------ 22261 ------ 23059 ------ 23692 ------ 24488 ------ 25144 ------ 25895 ------ 26747 ------ 27650 ------ 28408 ------ 29140 ------ 29920 ------ 30511 ------ 31261 ------ 31999 ------ 32920 ------ 33688 ------ 34525 ------ 35197 ------ 35876 ------ 36580 ------ 37313 ------ 37924 ------ 38768 ------ 39440 ------ 40127 ------ 41005 ------ 41810 ------ 42422 ------ 43310 ------ 44095 ------ 44644 ------ 45347 ------ 45970 ------ 46634 ------ 47284 ------ 48055 ------ 48850 ------ 49712 ------ 50356 ------ 51268 ------ 52048 ------ 52571 ------ 53125 ------ 54088 ------ 54913 ------ 55771 ------ 56386 ------ 57085 ------ 57877 ------ 58729 ------ 59353 ------ 60133 ------ 60947 ------ 61672 ------ 62411 ------ 63296 ------ 64000 ------ 64586 ------ 65251 ------ 65914 ------ 66403 ------ 66991 ------ 67798 ------ 68494 ------ 69406 ------ 70106 ------ 70921 ------ 71770 ------ 72482 ------ 73256 ------ 74083 ------ 74681 ------ 75412 ------ 76201 ------ 76876 ------ 77684 ------ 78421 ------ 79058 ------ 79909 ------ 80591 ------ 81247 ------ 81964 ------ 82835 ------ 83731 ------ 84467 ------ 85012 ------ 85874 ------ 86647 ------ 87151 ------ 87853 ------ 88543 ------ 89425 ------ 90046 ------ 90640 ------ 91544 ------ 92257 ------ 93107 ------ 93835 ------ 94424 ------ 95383 ------ 96313 ------ 96938 ------ 97808 ------ 98689 ------ 99505 ------ 100144 ------ 100981 ------ 101797 ------ 102556 ------ 103504 ------ 104113 ------ 104980 ------ 105622 ------ 106241 ------ 106988 ------ 107578 ------ 108302 ------ 108905 ------ 109765 ------ 110663 ------ 111409 ------ 112093 ------ 113033 ------ 113683 ------ 114346 ------ 115006 ------ 115798 ------ 116261 ------ 116908 ------ 117610 ------ 118319 ------ 119203 ------ 120058 ------ 120922 ------ 121702 ------ 122486 ------ 123253 ------ 124142 ------ 124795 ------ 125689 ------ 126277 ------ 126904 ------ 127684 ------ 128251 ------ 129032 ------ 129916 ------ 130717 ------ 131554 ------ 132482 ------ 133408 ------ 134272 ------ 135073 ------ 135869 ------ 136963 ------ 137806 ------ 138412 ------ 139103 ------ 139982 ------ 140794 ------ 141455 ------ 142396 ------ 143047 ------ 143788 ------ 144620 ------ 145336 ------ 146170 ------ 147014 ------ 147769 ------ 148508 ------ 149234 ------ 149995 + │ │ │ │ │ │ histogram(14)= 0 150 1.4997e+06 150 + │ │ │ │ │ │ <--- 1094.65 ------------ 477728.86 + │ │ │ │ │ │ histogram(15)= 0 450 6900 600 7350 600 6750 900 7050 1350 7350 1350 6750 900 6600 900 7350 600 7200 600 7350 1050 6900 750 6900 750 7350 450 7350 600 7200 750 7350 450 7200 750 7350 750 6150 1200 7050 300 7200 600 7200 300 6600 1350 7050 450 6750 600 7200 750 7050 450 6750 600 7200 900 7050 900 7050 750 7050 600 7200 750 6150 1200 7200 1200 6000 1350 6300 1200 7200 750 6750 1200 6600 900 7050 750 7050 450 7050 900 7200 450 7200 1050 6900 900 6300 1200 6750 600 7050 900 7050 450 6900 1200 6750 600 7050 750 6750 1350 7050 600 7050 300 7200 450 7050 600 6900 450 6900 450 7200 600 6600 900 6900 750 5700 1800 6900 750 6300 1050 7050 900 7200 300 7050 450 6600 750 6450 1200 6900 600 7050 1050 7050 450 6600 750 7050 600 6450 900 7050 600 7200 900 6750 900 7200 750 7200 1050 6750 600 6900 600 6900 1050 7050 450 7050 750 6000 1350 6750 900 6900 900 6900 900 7050 1050 6750 600 7050 900 6450 900 7050 300 6600 750 7050 1350 7200 450 7200 750 7200 600 6300 900 7050 750 6450 900 6900 900 6600 600 6600 600 6900 750 7050 600 6150 1050 6750 600 6600 600 7050 900 7050 1650 6750 600 6750 600 6750 450 7050 1050 6900 1350 6600 600 6300 900 6600 600 6300 1050 6750 900 6300 900 7050 1200 6600 1200 6750 750 6900 900 6750 600 6750 600 6150 1200 6450 1050 7050 750 6300 1050 7050 450 6750 600 6750 600 7050 600 7050 900 6900 600 6900 900 6900 600 6450 1200 6600 450 6900 450 6750 600 6750 750 6750 1350 6750 450 6600 750 6600 450 6450 750 6450 600 6750 600 6900 900 6300 750 6450 1200 6000 1500 6900 900 6000 1200 6300 750 6450 600 6900 1050 6600 600 6900 1650 5850 1050 6600 750 6600 450 6300 900 6600 300 6600 600 6750 900 6750 450 6600 750 6600 300 6150 900 6750 600 5850 1050 6750 450 6750 750 6600 900 6150 600 6600 450 6150 750 6600 1350 6600 450 6000 1200 5550 1350 6150 450 6300 450 6450 900 6450 750 6000 1650 5850 750 6000 450 5250 900 5400 1050 5400 600 + │ │ │ │ │ │ <--- '1992-01-01' ------ '1992-01-13' ------ '1992-01-25' ------ '1992-02-05' ------ '1992-02-18' ------ '1992-02-29' ------ '1992-03-12' ------ '1992-03-23' ------ '1992-04-05' ------ '1992-04-17' ------ '1992-04-30' ------ '1992-05-16' ------ '1992-05-28' ------ '1992-06-09' ------ '1992-06-22' ------ '1992-07-04' ------ '1992-07-15' ------ '1992-07-26' ------ '1992-08-09' ------ '1992-08-19' ------ '1992-09-01' ------ '1992-09-12' ------ '1992-09-23' ------ '1992-10-04' ------ '1992-10-17' ------ '1992-10-27' ------ '1992-11-06' ------ '1992-11-19' ------ '1992-11-30' ------ '1992-12-12' ------ '1992-12-23' ------ '1993-01-06' ------ '1993-01-18' ------ '1993-01-31' ------ '1993-02-08' ------ '1993-02-21' ------ '1993-03-01' ------ '1993-03-16' ------ '1993-03-27' ------ '1993-04-07' ------ '1993-04-21' ------ '1993-05-02' ------ '1993-05-14' ------ '1993-05-28' ------ '1993-06-08' ------ '1993-06-20' ------ '1993-07-02' ------ '1993-07-16' ------ '1993-07-29' ------ '1993-08-12' ------ '1993-08-25' ------ '1993-09-07' ------ '1993-09-22' ------ '1993-10-05' ------ '1993-10-18' ------ '1993-10-31' ------ '1993-11-14' ------ '1993-11-25' ------ '1993-12-06' ------ '1993-12-20' ------ '1994-01-03' ------ '1994-01-15' ------ '1994-01-23' ------ '1994-02-04' ------ '1994-02-15' ------ '1994-02-27' ------ '1994-03-09' ------ '1994-03-19' ------ '1994-04-05' ------ '1994-04-16' ------ '1994-04-29' ------ '1994-05-10' ------ '1994-05-24' ------ '1994-06-04' ------ '1994-06-16' ------ '1994-06-30' ------ '1994-07-16' ------ '1994-07-31' ------ '1994-08-13' ------ '1994-08-27' ------ '1994-09-08' ------ '1994-09-23' ------ '1994-10-06' ------ '1994-10-17' ------ '1994-10-28' ------ '1994-11-11' ------ '1994-11-25' ------ '1994-12-11' ------ '1994-12-22' ------ '1995-01-03' ------ '1995-01-17' ------ '1995-01-30' ------ '1995-02-09' ------ '1995-02-23' ------ '1995-03-10' ------ '1995-03-21' ------ '1995-04-04' ------ '1995-04-15' ------ '1995-04-27' ------ '1995-05-12' ------ '1995-05-26' ------ '1995-06-04' ------ '1995-06-13' ------ '1995-06-26' ------ '1995-07-08' ------ '1995-07-19' ------ '1995-07-31' ------ '1995-08-12' ------ '1995-08-21' ------ '1995-09-04' ------ '1995-09-13' ------ '1995-09-25' ------ '1995-10-06' ------ '1995-10-22' ------ '1995-10-30' ------ '1995-11-11' ------ '1995-11-23' ------ '1995-12-06' ------ '1995-12-19' ------ '1996-01-01' ------ '1996-01-13' ------ '1996-01-23' ------ '1996-02-03' ------ '1996-02-14' ------ '1996-02-24' ------ '1996-03-05' ------ '1996-03-17' ------ '1996-03-26' ------ '1996-04-09' ------ '1996-04-21' ------ '1996-05-03' ------ '1996-05-15' ------ '1996-05-28' ------ '1996-06-06' ------ '1996-06-16' ------ '1996-06-27' ------ '1996-07-11' ------ '1996-07-24' ------ '1996-08-07' ------ '1996-08-20' ------ '1996-09-04' ------ '1996-09-17' ------ '1996-10-05' ------ '1996-10-18' ------ '1996-10-29' ------ '1996-11-07' ------ '1996-11-20' ------ '1996-11-30' ------ '1996-12-15' ------ '1996-12-30' ------ '1997-01-13' ------ '1997-01-25' ------ '1997-02-05' ------ '1997-02-15' ------ '1997-02-24' ------ '1997-03-06' ------ '1997-03-18' ------ '1997-03-30' ------ '1997-04-09' ------ '1997-04-21' ------ '1997-05-01' ------ '1997-05-12' ------ '1997-05-24' ------ '1997-06-04' ------ '1997-06-15' ------ '1997-06-28' ------ '1997-07-10' ------ '1997-07-20' ------ '1997-07-30' ------ '1997-08-13' ------ '1997-08-24' ------ '1997-09-04' ------ '1997-09-16' ------ '1997-09-29' ------ '1997-10-15' ------ '1997-10-30' ------ '1997-11-13' ------ '1997-11-25' ------ '1997-12-06' ------ '1997-12-18' ------ '1997-12-30' ------ '1998-01-10' ------ '1998-01-23' ------ '1998-02-02' ------ '1998-02-15' ------ '1998-02-28' ------ '1998-03-11' ------ '1998-03-24' ------ '1998-04-03' ------ '1998-04-12' ------ '1998-04-24' ------ '1998-05-05' ------ '1998-05-18' ------ '1998-05-31' ------ '1998-06-11' ------ '1998-06-20' ------ '1998-06-30' ------ '1998-07-12' ------ '1998-07-23' ------ '1998-08-02' + │ │ │ │ │ ├── key: (11) + │ │ │ │ │ ├── fd: (11)-->(12,14,15) + │ │ │ │ │ └── ordering: +11 + │ │ │ │ ├── select + │ │ │ │ │ ├── save-table-name: q18_select_8 + │ │ │ │ │ ├── columns: l_orderkey:40(int!null) sum:58(float!null) + │ │ │ │ │ ├── stats: [rows=509090, distinct(40)=509090, null(40)=0, distinct(58)=509090, null(58)=0] + │ │ │ │ │ ├── key: (40) + │ │ │ │ │ ├── fd: (40)-->(58) + │ │ │ │ │ ├── ordering: +40 + │ │ │ │ │ ├── group-by (streaming) + │ │ │ │ │ │ ├── save-table-name: q18_group_by_9 + │ │ │ │ │ │ ├── columns: l_orderkey:40(int!null) sum:58(float!null) + │ │ │ │ │ │ ├── grouping columns: l_orderkey:40(int!null) + │ │ │ │ │ │ ├── stats: [rows=1527270, distinct(40)=1.52727e+06, null(40)=0, distinct(58)=1.52727e+06, null(58)=0] + │ │ │ │ │ │ ├── key: (40) + │ │ │ │ │ │ ├── fd: (40)-->(58) + │ │ │ │ │ │ ├── ordering: +40 + │ │ │ │ │ │ ├── scan lineitem + │ │ │ │ │ │ │ ├── save-table-name: q18_scan_10 + │ │ │ │ │ │ │ ├── columns: l_orderkey:40(int!null) l_quantity:44(float!null) + │ │ │ │ │ │ │ ├── stats: [rows=6001215, distinct(40)=1.52727e+06, null(40)=0, distinct(44)=50, null(44)=0] + │ │ │ │ │ │ │ │ histogram(40)= 0 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 28806 1200 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 28806 1200 29406 600 29406 600 29406 600 29406 600 28806 1200 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 29406 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 30006 600 + │ │ │ │ │ │ │ │ <--- 197 ------- 23686 ------- 53253 ------- 90435 ------- 121730 ------- 153280 ------- 175456 ------- 208548 ------- 242209 ------- 273057 ------- 296640 ------- 330307 ------- 360999 ------- 386307 ------- 420225 ------- 450050 ------- 477795 ------- 504711 ------- 533153 ------- 556672 ------- 582243 ------- 613729 ------- 646117 ------- 675840 ------- 706048 ------- 733063 ------- 769282 ------- 793922 ------- 820357 ------- 849536 ------- 875719 ------- 905028 ------- 940643 ------- 968355 ------- 998721 ------- 1023621 ------- 1059424 ------- 1084932 ------- 1115553 ------- 1139363 ------- 1167361 ------- 1194400 ------- 1225984 ------- 1253861 ------- 1281633 ------- 1304999 ------- 1336355 ------- 1370759 ------- 1400832 ------- 1434085 ------- 1458852 ------- 1491427 ------- 1525120 ------- 1555205 ------- 1591300 ------- 1619426 ------- 1651458 ------- 1682950 ------- 1711399 ------- 1747591 ------- 1787205 ------- 1822240 ------- 1856163 ------- 1886915 ------- 1910949 ------- 1947202 ------- 1974311 ------- 2009286 ------- 2044034 ------- 2079104 ------- 2103488 ------- 2134657 ------- 2164293 ------- 2204514 ------- 2230823 ------- 2265253 ------- 2289826 ------- 2329539 ------- 2364455 ------- 2393507 ------- 2414628 ------- 2440228 ------- 2465255 ------- 2489568 ------- 2520900 ------- 2554919 ------- 2583333 ------- 2612966 ------- 2644833 ------- 2667362 ------- 2702784 ------- 2727394 ------- 2759748 ------- 2794531 ------- 2822214 ------- 2846624 ------- 2883748 ------- 2919586 ------- 2951908 ------- 2980068 ------- 3014726 ------- 3050725 ------- 3081028 ------- 3113351 ------- 3150243 ------- 3185669 ------- 3214311 ------- 3241281 ------- 3275748 ------- 3303232 ------- 3339559 ------- 3370627 ------- 3393664 ------- 3435265 ------- 3464581 ------- 3489026 ------- 3516096 ------- 3548480 ------- 3587015 ------- 3611239 ------- 3638724 ------- 3668641 ------- 3695751 ------- 3729636 ------- 3751523 ------- 3784608 ------- 3815715 ------- 3848608 ------- 3881184 ------- 3908738 ------- 3940002 ------- 3966176 ------- 4001984 ------- 4035687 ------- 4065283 ------- 4092834 ------- 4133062 ------- 4160613 ------- 4196421 ------- 4223713 ------- 4254788 ------- 4291040 ------- 4313664 ------- 4342823 ------- 4369952 ------- 4391684 ------- 4419040 ------- 4449921 ------- 4471781 ------- 4506210 ------- 4538176 ------- 4571297 ------- 4601121 ------- 4630887 ------- 4657476 ------- 4684803 ------- 4714566 ------- 4744070 ------- 4776385 ------- 4807777 ------- 4839491 ------- 4873953 ------- 4902245 ------- 4936263 ------- 4970721 ------- 5003140 ------- 5029729 ------- 5059010 ------- 5087521 ------- 5121093 ------- 5150405 ------- 5178375 ------- 5203683 ------- 5234531 ------- 5268195 ------- 5300004 ------- 5331558 ------- 5362178 ------- 5385762 ------- 5418498 ------- 5445762 ------- 5483109 ------- 5514561 ------- 5542052 ------- 5569572 ------- 5596102 ------- 5622401 ------- 5652194 ------- 5671362 ------- 5699591 ------- 5727136 ------- 5753284 ------- 5780742 ------- 5809189 ------- 5836545 ------- 5864454 ------- 5894917 ------- 5933825 ------- 5968933 ------- 5999590 + │ │ │ │ │ │ │ │ histogram(44)= 0 1.1342e+05 5.766e+06 1.2182e+05 + │ │ │ │ │ │ │ │ <----- 1.0 ---------------- 50.0 -- + │ │ │ │ │ │ │ └── ordering: +40 + │ │ │ │ │ │ └── aggregations + │ │ │ │ │ │ └── sum [as=sum:58, type=float, outer=(44)] + │ │ │ │ │ │ └── l_quantity:44 [type=float] + │ │ │ │ │ └── filters + │ │ │ │ │ └── sum:58 > 300.0 [type=bool, outer=(58), constraints=(/58: [/300.00000000000006 - ]; tight)] + │ │ │ │ └── filters (true) + │ │ │ └── filters (true) + │ │ └── filters (true) + │ └── aggregations + │ ├── sum [as=sum:59, type=float, outer=(26)] + │ │ └── l_quantity:26 [type=float] + │ ├── const-agg [as=c_custkey:1, type=int, outer=(1)] + │ │ └── c_custkey:1 [type=int] + │ └── const-agg [as=c_name:2, type=varchar, outer=(2)] + │ └── c_name:2 [type=varchar] + └── 100 [type=int] -----Stats for q18_top_k_1---- +----Stats for q18_limit_1---- column_names row_count distinct_count null_count {c_custkey} 57 57 0 {c_name} 57 57 0 @@ -198,12 +189,12 @@ column_names row_count distinct_count null_count column_names row_count_est row_count_err distinct_count_est distinct_count_err null_count_est null_count_err {c_custkey} 499392.00 8761.26 <== 499392.00 8761.26 <== 0.00 1.00 {c_name} 499392.00 8761.26 <== 499392.00 8761.26 <== 0.00 1.00 -{o_orderdate} 499392.00 8761.26 <== 499392.00 8761.26 <== 0.00 1.00 +{o_orderdate} 499392.00 8761.26 <== 2406.00 42.21 <== 0.00 1.00 {o_orderkey} 499392.00 8761.26 <== 499392.00 8761.26 <== 0.00 1.00 -{o_totalprice} 499392.00 8761.26 <== 499392.00 8761.26 <== 0.00 1.00 +{o_totalprice} 499392.00 8761.26 <== 488044.00 8562.18 <== 0.00 1.00 {sum} 499392.00 8761.26 <== 499392.00 27744.00 <== 0.00 1.00 -----Stats for q18_inner_join_3---- +----Stats for q18_lookup_join_3---- column_names row_count distinct_count null_count {c_custkey} 399 57 0 {c_name} 399 57 0 @@ -224,31 +215,35 @@ column_names row_count_est row_count_err distinct_count_est distinct_count {o_orderkey} 2016361.00 5053.54 <== 499392.00 8761.26 <== 0.00 1.00 {o_totalprice} 2016361.00 5053.54 <== 488044.00 8562.18 <== 0.00 1.00 -----Stats for q18_merge_join_4---- +----Stats for q18_lookup_join_4---- column_names row_count distinct_count null_count -{l_orderkey} 399 57 0 -{l_quantity} 399 27 0 -{o_custkey} 399 57 0 -{o_orderdate} 399 57 0 -{o_orderkey} 399 57 0 -{o_totalprice} 399 57 0 +{c_custkey} 57 57 0 +{c_name} 57 57 0 +{o_custkey} 57 57 0 +{o_orderdate} 57 57 0 +{o_orderkey} 57 57 0 +{o_totalprice} 57 57 0 ~~~~ column_names row_count_est row_count_err distinct_count_est distinct_count_err null_count_est null_count_err -{l_orderkey} 2000405.00 5013.55 <== 509090.00 8931.40 <== 0.00 1.00 -{l_quantity} 2000405.00 5013.55 <== 50.00 1.85 0.00 1.00 -{o_custkey} 2000405.00 5013.55 <== 99649.00 1748.23 <== 0.00 1.00 -{o_orderdate} 2000405.00 5013.55 <== 2406.00 42.21 <== 0.00 1.00 -{o_orderkey} 2000405.00 5013.55 <== 509090.00 8931.40 <== 0.00 1.00 -{o_totalprice} 2000405.00 5013.55 <== 496607.00 8712.40 <== 0.00 1.00 +{c_custkey} 513151.00 9002.65 <== 99649.00 1748.23 <== 0.00 1.00 +{c_name} 513151.00 9002.65 <== 145098.00 2545.58 <== 0.00 1.00 +{o_custkey} 513151.00 9002.65 <== 99649.00 1748.23 <== 0.00 1.00 +{o_orderdate} 513151.00 9002.65 <== 2406.00 42.21 <== 0.00 1.00 +{o_orderkey} 513151.00 9002.65 <== 323295.00 5671.84 <== 0.00 1.00 +{o_totalprice} 513151.00 9002.65 <== 322560.00 5658.95 <== 0.00 1.00 -----Stats for q18_scan_5---- -column_names row_count distinct_count null_count -{l_orderkey} 5986300 1523585 0 -{l_quantity} 5986300 50 0 +----Stats for q18_sort_5---- +column_names row_count distinct_count null_count +{o_custkey} 57 57 0 +{o_orderdate} 57 57 0 +{o_orderkey} 57 57 0 +{o_totalprice} 57 57 0 ~~~~ -column_names row_count_est row_count_err distinct_count_est distinct_count_err null_count_est null_count_err -{l_orderkey} 6001215.00 1.00 1527270.00 1.00 0.00 1.00 -{l_quantity} 6001215.00 1.00 50.00 1.00 0.00 1.00 +column_names row_count_est row_count_err distinct_count_est distinct_count_err null_count_est null_count_err +{o_custkey} 509090.00 8931.40 <== 99649.00 1748.23 <== 0.00 1.00 +{o_orderdate} 509090.00 8931.40 <== 2406.00 42.21 <== 0.00 1.00 +{o_orderkey} 509090.00 8931.40 <== 509090.00 8931.40 <== 0.00 1.00 +{o_totalprice} 509090.00 8931.40 <== 506350.00 8883.33 <== 0.00 1.00 ----Stats for q18_merge_join_6---- column_names row_count distinct_count null_count @@ -302,14 +297,5 @@ column_names row_count distinct_count null_count column_names row_count_est row_count_err distinct_count_est distinct_count_err null_count_est null_count_err {l_orderkey} 6001215.00 1.00 1527270.00 1.00 0.00 1.00 {l_quantity} 6001215.00 1.00 50.00 1.00 0.00 1.00 - -----Stats for q18_scan_11---- -column_names row_count distinct_count null_count -{c_custkey} 150000 148813 0 -{c_name} 150000 150000 0 -~~~~ -column_names row_count_est row_count_err distinct_count_est distinct_count_err null_count_est null_count_err -{c_custkey} 150000.00 1.00 148813.00 1.00 0.00 1.00 -{c_name} 150000.00 1.00 150000.00 1.00 0.00 1.00 ---- ---- diff --git a/pkg/sql/opt/norm/factory.go b/pkg/sql/opt/norm/factory.go index 594740a474a6..b4abc0b2d006 100644 --- a/pkg/sql/opt/norm/factory.go +++ b/pkg/sql/opt/norm/factory.go @@ -186,6 +186,28 @@ func (f *Factory) DisableOptimizations() { f.NotifyOnMatchedRule(func(opt.RuleName) bool { return false }) } +// DisableOptimizationRules disables a specific set of transformation rules. +func (f *Factory) DisableOptimizationRules(disabledRules intsets.Fast) { + f.NotifyOnMatchedRule(func(rule opt.RuleName) bool { + if disabledRules.Contains(int(rule)) { + return false + } else { + return true + } + }) +} + +// DisableOptimizationRulesTemporarily disables a specific set transformation +// rules during the execution of the given function fn. A MatchedRuleFunc +// previously set by NotifyOnMatchedRule is not invoked during execution of fn, +// but will be invoked for future rule matches after fn returns. +func (f *Factory) DisableOptimizationRulesTemporarily(disabledRules intsets.Fast, fn func()) { + originalMatchedRule := f.matchedRule + f.DisableOptimizationRules(disabledRules) + fn() + f.matchedRule = originalMatchedRule +} + // DisableOptimizationsTemporarily disables all transformation rules during the // execution of the given function fn. A MatchedRuleFunc previously set by // NotifyOnMatchedRule is not invoked during execution of fn, but will be diff --git a/pkg/sql/opt/testutils/opttester/testfixtures/rewrite_stats.sh b/pkg/sql/opt/testutils/opttester/testfixtures/rewrite_stats.sh index df689113b0c7..83ed5994760b 100755 --- a/pkg/sql/opt/testutils/opttester/testfixtures/rewrite_stats.sh +++ b/pkg/sql/opt/testutils/opttester/testfixtures/rewrite_stats.sh @@ -19,7 +19,7 @@ DATABASE=$2 FILENAME=$3 tables=($($COCKROACH_BINARY sql --insecure --format=tsv \ - -e "USE $DATABASE; SELECT table_name FROM [SHOW TABLES] ORDER BY table_name;")) + -e "USE $DATABASE; SELECT table_name FROM [SHOW TABLES] ORDER BY table_name;" | tail -n +2)) tables=("${tables[@]:1}") echo "Writing statistics to $FILENAME" @@ -38,7 +38,7 @@ do # 4. Remove the double quote at the end of the JSON. # 5. Append '; to the last line. $COCKROACH_BINARY sql --insecure --format=tsv \ - -e "USE $DATABASE; SELECT jsonb_pretty(statistics) FROM [SHOW STATISTICS USING JSON FOR TABLE \"$table\"];" \ + -e "USE $DATABASE; SELECT jsonb_pretty(statistics) FROM [SHOW STATISTICS USING JSON FOR TABLE \"$table\"];" | tail -n +2 \ | sed '1d' | sed 's/""/"/g' | sed 's/^"\[/\[/g' | sed 's/\]"$/\]/g' | sed '$ s/$/'\'';/' >> $FILENAME echo "----" >> $FILENAME echo "" >> $FILENAME diff --git a/pkg/sql/opt/xform/groupby_funcs.go b/pkg/sql/opt/xform/groupby_funcs.go index c506879094a6..61f584dee50c 100644 --- a/pkg/sql/opt/xform/groupby_funcs.go +++ b/pkg/sql/opt/xform/groupby_funcs.go @@ -17,6 +17,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/opt/ordering" "github.com/cockroachdb/cockroach/pkg/sql/opt/props" "github.com/cockroachdb/cockroach/pkg/sql/types" + "github.com/cockroachdb/cockroach/pkg/util/intsets" "github.com/cockroachdb/errors" ) @@ -172,6 +173,129 @@ func (c *CustomFuncs) MakeProjectFromPassthroughAggs( }, grp) } +// GroupingColsClosureOverlappingOrdering determines if the specified `ordering` +// columns overlaps with the closure of the grouping columns in `private` as +// determined by the functional dependencies of the `input` relation to the +// grouped aggregation. If found, this expanded set of `groupingCols` is +// returned, plus the overlapping ordering columns `newOrdering`, along with +// `ok`=true. +func (c *CustomFuncs) GroupingColsClosureOverlappingOrdering( + input memo.RelExpr, private *memo.GroupingPrivate, ordering props.OrderingChoice, +) (groupingCols opt.ColSet, newOrdering props.OrderingChoice, ok bool) { + if ordering.Any() { + // If the limit specifies no ordering, there is no ordering hint for us to + // use. + return opt.ColSet{}, props.OrderingChoice{}, false + } + groupingCols = private.GroupingCols + // If the result requires a specific ordering, use that as the ordering of the + // aggregation if possible. + // Find all columns determined by the grouping columns. + groupingColumnsClosure := input.Relational().FuncDeps.ComputeClosure(groupingCols) + // It is safe to add ordering columns present in the grouping column closure + // as grouping columns because the original grouping columns determine all + // other column values in the closure (within a group there is only one + // combined set of values for the other columns). Doing so allows the required + // ordering to be provided by the streaming group by and possibly remove the + // requirement for a TopK operator. + orderingColsInClosure := groupingColumnsClosure.Intersection(ordering.ColSet()) + if orderingColsInClosure.Empty() { + // If we have no columns to add to the grouping, this rewrite has no effect. + return opt.ColSet{}, props.OrderingChoice{}, false + } + groupingCols = groupingCols.Union(orderingColsInClosure) + newOrdering, fullPrefix, found := getPrefixFromOrdering(ordering.ToOrdering(), private.Ordering, input, + func(id opt.ColumnID) bool { return groupingCols.Contains(id) }) + if !found || !fullPrefix { + return opt.ColSet{}, props.OrderingChoice{}, false + } + return groupingCols, newOrdering, true +} + +// GenerateStreamingGroupByLimitOrderingHint generates a LimitExpr with an input +// which is a GroupBy or DistinctOn expression with an expanded set of +// `groupingCols` which is an overlap of the closure of the original grouping +// columns closure and the ordering in the `limitExpr` as determined by +// `GroupingColsClosureOverlappingOrdering`, which also produces the +// `newOrdering`. Argument `private` is expected to be a canonical group-by. +func (c *CustomFuncs) GenerateStreamingGroupByLimitOrderingHint( + grp memo.RelExpr, + limitExpr *memo.LimitExpr, + aggregation memo.RelExpr, + input memo.RelExpr, + aggs memo.AggregationsExpr, + private *memo.GroupingPrivate, + groupingCols opt.ColSet, + newOrdering props.OrderingChoice, +) { + newPrivate := *private + newPrivate.Ordering = newOrdering + newPrivate.GroupingCols = groupingCols + + // Remove constant column aggregate expressions if they've been added to + // the grouping columns. The column should appear in one place or the other, + // but not both. + newAggs := make(memo.AggregationsExpr, 0, len(aggs)) + for _, agg := range aggs { + if !groupingCols.Contains(agg.Col) { + newAggs = append(newAggs, agg) + continue + } + constAggExpr, ok := agg.Agg.(*memo.ConstAggExpr) + if !ok { + newAggs = append(newAggs, agg) + continue + } + variableExpr, ok := constAggExpr.Input.(*memo.VariableExpr) + if !ok { + newAggs = append(newAggs, agg) + continue + } + if variableExpr.Col != agg.Col { + // Column IDs expected to match to safely remove this aggregation. + return + } + } + // Output columns are the union of grouping columns with columns from the + // aggregate projection list. Verify this is built correctly. + outputCols := groupingCols.Copy() + for i := range newAggs { + outputCols.Add(newAggs[i].Col) + } + if !aggregation.Relational().OutputCols.Equals(outputCols) { + // If the output columns in the new aggregation don't match those in the + // original aggregation, give up on this optimization. + return + } + + var newAggregation memo.RelExpr + constructAggregation := func() { + newAggregation = + c.e.f.DynamicConstruct( + aggregation.Op(), + input, + &newAggs, + &newPrivate, + ).(memo.RelExpr) + } + var disabledRules intsets.Fast + // The ReduceGroupingCols rule must be disabled to prevent the ordering + // columns from being removed from the grouping columns during operation + // construction. This rule already reduced the grouping columns on the initial + // construction. We are just adding back in any ordering columns which overlap + // with grouping columns in order to generate a better plan. + disabledRules.Add(int(opt.ReduceGroupingCols)) + + c.e.f.DisableOptimizationRulesTemporarily(disabledRules, constructAggregation) + newLimitExpr := + &memo.LimitExpr{ + Input: newAggregation, + Limit: limitExpr.Limit, + Ordering: limitExpr.Ordering, + } + grp.Memo().AddLimitToGroup(newLimitExpr, grp) +} + // GenerateStreamingGroupBy generates variants of a GroupBy, DistinctOn, // EnsureDistinctOn, UpsertDistinctOn, or EnsureUpsertDistinctOn expression // with more specific orderings on the grouping columns, using the interesting diff --git a/pkg/sql/opt/xform/rules/limit.opt b/pkg/sql/opt/xform/rules/limit.opt index 00005ff921e2..80752a5b2c84 100644 --- a/pkg/sql/opt/xform/rules/limit.opt +++ b/pkg/sql/opt/xform/rules/limit.opt @@ -184,3 +184,39 @@ (TopK $input:* $private:*) => (GeneratePartialOrderTopK $input $private) + +# GenerateStreamingGroupByLimitOrderingHint generates streaming group-by and +# distinct-on aggregations with an ordering matching the ordering specified in +# the Limit Op. The goal is to eliminate the need for a TopK operation. +[GenerateStreamingGroupByLimitOrderingHint, Explore] +(Limit + $aggregation:(GroupBy | DistinctOn + $input:* + $aggs:* + $private:* & (IsCanonicalGroupBy $private) + ) + (Const $limit:* & (IsPositiveInt $limit)) + $ordering:* & + (Let + ( + $groupingCols + $newOrdering + $ok + ):(GroupingColsClosureOverlappingOrdering + $input + $private + $ordering + ) + $ok + ) +) +=> +(GenerateStreamingGroupByLimitOrderingHint + (Root) + $aggregation + $input + $aggs + $private + $groupingCols + $newOrdering +) diff --git a/pkg/sql/opt/xform/testdata/external/tpch b/pkg/sql/opt/xform/testdata/external/tpch index c0b45bd72e33..393c6d7a0ec9 100644 --- a/pkg/sql/opt/xform/testdata/external/tpch +++ b/pkg/sql/opt/xform/testdata/external/tpch @@ -1911,81 +1911,82 @@ ORDER BY o_orderdate LIMIT 100; ---- -top-k +limit ├── columns: c_name:2!null c_custkey:1!null o_orderkey:11!null o_orderdate:15!null o_totalprice:14!null sum:59!null ├── internal-ordering: -14,+15 - ├── k: 100 ├── cardinality: [0 - 100] ├── key: (11) ├── fd: (1)-->(2), (11)-->(1,2,14,15,59) ├── ordering: -14,+15 - └── group-by (hash) - ├── columns: c_custkey:1!null c_name:2!null o_orderkey:11!null o_totalprice:14!null o_orderdate:15!null sum:59!null - ├── grouping columns: o_orderkey:11!null - ├── key: (11) - ├── fd: (1)-->(2), (11)-->(1,2,14,15,59) - ├── inner-join (hash) - │ ├── columns: c_custkey:1!null c_name:2!null o_orderkey:11!null o_custkey:12!null o_totalprice:14!null o_orderdate:15!null l_orderkey:22!null l_quantity:26!null - │ ├── multiplicity: left-rows(exactly-one), right-rows(zero-or-more) - │ ├── fd: (1)-->(2), (11)-->(12,14,15), (11)==(22), (22)==(11), (1)==(12), (12)==(1) - │ ├── inner-join (merge) - │ │ ├── columns: o_orderkey:11!null o_custkey:12!null o_totalprice:14!null o_orderdate:15!null l_orderkey:22!null l_quantity:26!null - │ │ ├── left ordering: +22 - │ │ ├── right ordering: +11 - │ │ ├── fd: (11)-->(12,14,15), (11)==(22), (22)==(11) - │ │ ├── scan lineitem - │ │ │ ├── columns: l_orderkey:22!null l_quantity:26!null - │ │ │ └── ordering: +22 - │ │ ├── semi-join (merge) - │ │ │ ├── columns: o_orderkey:11!null o_custkey:12!null o_totalprice:14!null o_orderdate:15!null - │ │ │ ├── left ordering: +11 - │ │ │ ├── right ordering: +40 - │ │ │ ├── key: (11) - │ │ │ ├── fd: (11)-->(12,14,15) - │ │ │ ├── ordering: +11 - │ │ │ ├── scan orders - │ │ │ │ ├── columns: o_orderkey:11!null o_custkey:12!null o_totalprice:14!null o_orderdate:15!null - │ │ │ │ ├── key: (11) - │ │ │ │ ├── fd: (11)-->(12,14,15) - │ │ │ │ └── ordering: +11 - │ │ │ ├── select - │ │ │ │ ├── columns: l_orderkey:40!null sum:58!null - │ │ │ │ ├── key: (40) - │ │ │ │ ├── fd: (40)-->(58) - │ │ │ │ ├── ordering: +40 - │ │ │ │ ├── group-by (streaming) - │ │ │ │ │ ├── columns: l_orderkey:40!null sum:58!null - │ │ │ │ │ ├── grouping columns: l_orderkey:40!null - │ │ │ │ │ ├── key: (40) - │ │ │ │ │ ├── fd: (40)-->(58) - │ │ │ │ │ ├── ordering: +40 - │ │ │ │ │ ├── scan lineitem - │ │ │ │ │ │ ├── columns: l_orderkey:40!null l_quantity:44!null - │ │ │ │ │ │ └── ordering: +40 - │ │ │ │ │ └── aggregations - │ │ │ │ │ └── sum [as=sum:58, outer=(44)] - │ │ │ │ │ └── l_quantity:44 - │ │ │ │ └── filters - │ │ │ │ └── sum:58 > 300.0 [outer=(58), constraints=(/58: [/300.00000000000006 - ]; tight)] - │ │ │ └── filters (true) - │ │ └── filters (true) - │ ├── scan customer - │ │ ├── columns: c_custkey:1!null c_name:2!null - │ │ ├── key: (1) - │ │ └── fd: (1)-->(2) - │ └── filters - │ └── c_custkey:1 = o_custkey:12 [outer=(1,12), constraints=(/1: (/NULL - ]; /12: (/NULL - ]), fd=(1)==(12), (12)==(1)] - └── aggregations - ├── sum [as=sum:59, outer=(26)] - │ └── l_quantity:26 - ├── const-agg [as=c_custkey:1, outer=(1)] - │ └── c_custkey:1 - ├── const-agg [as=c_name:2, outer=(2)] - │ └── c_name:2 - ├── const-agg [as=o_totalprice:14, outer=(14)] - │ └── o_totalprice:14 - └── const-agg [as=o_orderdate:15, outer=(15)] - └── o_orderdate:15 + ├── group-by (partial streaming) + │ ├── columns: c_custkey:1!null c_name:2!null o_orderkey:11!null o_totalprice:14!null o_orderdate:15!null sum:59!null + │ ├── grouping columns: o_orderkey:11!null o_totalprice:14!null o_orderdate:15!null + │ ├── internal-ordering: -14,+15 + │ ├── key: (11) + │ ├── fd: (1)-->(2), (11)-->(1,2,14,15,59) + │ ├── ordering: -14,+15 + │ ├── limit hint: 100.00 + │ ├── inner-join (lookup lineitem) + │ │ ├── columns: c_custkey:1!null c_name:2!null o_orderkey:11!null o_custkey:12!null o_totalprice:14!null o_orderdate:15!null l_orderkey:22!null l_quantity:26!null + │ │ ├── key columns: [11] = [22] + │ │ ├── fd: (1)-->(2), (11)-->(12,14,15), (11)==(22), (22)==(11), (1)==(12), (12)==(1) + │ │ ├── ordering: -14,+15 + │ │ ├── limit hint: 403.76 + │ │ ├── inner-join (lookup customer) + │ │ │ ├── columns: c_custkey:1!null c_name:2!null o_orderkey:11!null o_custkey:12!null o_totalprice:14!null o_orderdate:15!null + │ │ │ ├── key columns: [12] = [1] + │ │ │ ├── lookup columns are key + │ │ │ ├── key: (11) + │ │ │ ├── fd: (1)-->(2), (11)-->(12,14,15), (1)==(12), (12)==(1) + │ │ │ ├── ordering: -14,+15 + │ │ │ ├── limit hint: 200.00 + │ │ │ ├── sort + │ │ │ │ ├── columns: o_orderkey:11!null o_custkey:12!null o_totalprice:14!null o_orderdate:15!null + │ │ │ │ ├── key: (11) + │ │ │ │ ├── fd: (11)-->(12,14,15) + │ │ │ │ ├── ordering: -14,+15 + │ │ │ │ ├── limit hint: 200.00 + │ │ │ │ └── semi-join (merge) + │ │ │ │ ├── columns: o_orderkey:11!null o_custkey:12!null o_totalprice:14!null o_orderdate:15!null + │ │ │ │ ├── left ordering: +11 + │ │ │ │ ├── right ordering: +40 + │ │ │ │ ├── key: (11) + │ │ │ │ ├── fd: (11)-->(12,14,15) + │ │ │ │ ├── scan orders + │ │ │ │ │ ├── columns: o_orderkey:11!null o_custkey:12!null o_totalprice:14!null o_orderdate:15!null + │ │ │ │ │ ├── key: (11) + │ │ │ │ │ ├── fd: (11)-->(12,14,15) + │ │ │ │ │ └── ordering: +11 + │ │ │ │ ├── select + │ │ │ │ │ ├── columns: l_orderkey:40!null sum:58!null + │ │ │ │ │ ├── key: (40) + │ │ │ │ │ ├── fd: (40)-->(58) + │ │ │ │ │ ├── ordering: +40 + │ │ │ │ │ ├── group-by (streaming) + │ │ │ │ │ │ ├── columns: l_orderkey:40!null sum:58!null + │ │ │ │ │ │ ├── grouping columns: l_orderkey:40!null + │ │ │ │ │ │ ├── key: (40) + │ │ │ │ │ │ ├── fd: (40)-->(58) + │ │ │ │ │ │ ├── ordering: +40 + │ │ │ │ │ │ ├── scan lineitem + │ │ │ │ │ │ │ ├── columns: l_orderkey:40!null l_quantity:44!null + │ │ │ │ │ │ │ └── ordering: +40 + │ │ │ │ │ │ └── aggregations + │ │ │ │ │ │ └── sum [as=sum:58, outer=(44)] + │ │ │ │ │ │ └── l_quantity:44 + │ │ │ │ │ └── filters + │ │ │ │ │ └── sum:58 > 300.0 [outer=(58), constraints=(/58: [/300.00000000000006 - ]; tight)] + │ │ │ │ └── filters (true) + │ │ │ └── filters (true) + │ │ └── filters (true) + │ └── aggregations + │ ├── sum [as=sum:59, outer=(26)] + │ │ └── l_quantity:26 + │ ├── const-agg [as=c_custkey:1, outer=(1)] + │ │ └── c_custkey:1 + │ └── const-agg [as=c_name:2, outer=(2)] + │ └── c_name:2 + └── 100 # -------------------------------------------------- # Q19 diff --git a/pkg/sql/opt/xform/testdata/external/trading b/pkg/sql/opt/xform/testdata/external/trading index b798cad13040..0135cf18ed53 100644 --- a/pkg/sql/opt/xform/testdata/external/trading +++ b/pkg/sql/opt/xform/testdata/external/trading @@ -802,109 +802,112 @@ project ├── key: (17,31) ├── fd: (1)-->(2-6,11-17), (2,4,5)~~>(1,3,6), (17)-->(1-6,11-16) ├── ordering: +2,+4,+5 - ├── top-k + ├── limit │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null sum:30 │ ├── internal-ordering: +2,+4,+5 - │ ├── k: 50 │ ├── cardinality: [0 - 50] │ ├── immutable │ ├── stats: [rows=50] │ ├── key: (10) │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(1-6,11-17,30), (17)-->(10-16), (1)==(10), (10)==(1) │ ├── ordering: +2,+4,+5 - │ └── group-by (streaming) - │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null sum:30 - │ ├── grouping columns: cardsinfo.cardid:10!null - │ ├── internal-ordering: +(1|10) opt(9) - │ ├── immutable - │ ├── stats: [rows=19000, distinct(10)=19000, null(10)=0] - │ ├── key: (10) - │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(1-6,11-17,30), (17)-->(10-16), (1)==(10), (10)==(1) - │ ├── inner-join (merge) - │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.dealerid:9!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null transactiondetails.dealerid:20 isbuy:21 transactiondate:22 transactiondetails.cardid:23 quantity:24 - │ │ ├── left ordering: +1 - │ │ ├── right ordering: +10 - │ │ ├── immutable - │ │ ├── stats: [rows=659920.1, distinct(10)=19000, null(10)=0, distinct(23)=19000, null(23)=0] - │ │ ├── key: (10,22-24) - │ │ ├── fd: ()-->(9), (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(11-17), (17)-->(10-16), (1)==(10), (10)==(1), (10,22-24)-->(20,21) - │ │ ├── ordering: +(1|10) opt(9) [actual: +1] - │ │ ├── left-join (lookup transactiondetails@detailscardidindex) - │ │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null transactiondetails.dealerid:20 isbuy:21 transactiondate:22 transactiondetails.cardid:23 quantity:24 - │ │ │ ├── lookup expression - │ │ │ │ └── filters - │ │ │ │ ├── "lookup_join_const_col_@20":42 = transactiondetails.dealerid:20 [outer=(20,42), constraints=(/20: (/NULL - ]; /42: (/NULL - ]), fd=(20)==(42), (42)==(20)] - │ │ │ │ ├── "lookup_join_const_col_@21":43 = isbuy:21 [outer=(21,43), constraints=(/21: (/NULL - ]; /43: (/NULL - ]), fd=(21)==(43), (43)==(21)] - │ │ │ │ ├── id:1 = transactiondetails.cardid:23 [outer=(1,23), constraints=(/1: (/NULL - ]; /23: (/NULL - ]), fd=(1)==(23), (23)==(1)] - │ │ │ │ └── (transactiondate:22 >= '2020-02-28 00:00:00+00:00') AND (transactiondate:22 <= '2020-03-01 00:00:00+00:00') [outer=(22), constraints=(/22: [/'2020-02-28 00:00:00+00:00' - /'2020-03-01 00:00:00+00:00']; tight)] - │ │ │ ├── immutable - │ │ │ ├── stats: [rows=423333.3, distinct(1)=19000, null(1)=0, distinct(2)=13000, null(2)=0, distinct(5)=829, null(5)=0, distinct(6)=5601.15, null(6)=0, distinct(23)=19000, null(23)=0] - │ │ │ ├── key: (1,22-24) - │ │ │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6), (1,22-24)-->(20,21) - │ │ │ ├── ordering: +1 - │ │ │ ├── project - │ │ │ │ ├── columns: "lookup_join_const_col_@20":42!null "lookup_join_const_col_@21":43!null id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null - │ │ │ │ ├── immutable - │ │ │ │ ├── stats: [rows=19000] - │ │ │ │ ├── key: (1) - │ │ │ │ ├── fd: ()-->(42,43), (1)-->(2-6), (2,4,5)~~>(1,3,6) - │ │ │ │ ├── ordering: +1 opt(42,43) [actual: +1] - │ │ │ │ ├── select - │ │ │ │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null - │ │ │ │ │ ├── immutable - │ │ │ │ │ ├── stats: [rows=19000, distinct(1)=19000, null(1)=0, distinct(2)=13000, null(2)=0, distinct(5)=829, null(5)=0, distinct(6)=5601.15, null(6)=0] - │ │ │ │ │ ├── key: (1) - │ │ │ │ │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6) - │ │ │ │ │ ├── ordering: +1 - │ │ │ │ │ ├── scan cards - │ │ │ │ │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null - │ │ │ │ │ │ ├── stats: [rows=57000, distinct(1)=57000, null(1)=0, distinct(2)=39000, null(2)=0, distinct(5)=829, null(5)=0, distinct(6)=5700, null(6)=0] - │ │ │ │ │ │ ├── key: (1) - │ │ │ │ │ │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6) - │ │ │ │ │ │ └── ordering: +1 - │ │ │ │ │ └── filters - │ │ │ │ │ └── (name:2, setname:4, number:5) > ('Shock', '7E', 248) [outer=(2,4,5), immutable, constraints=(/2/4/5: [/'Shock'/'7E'/249 - ]; tight)] - │ │ │ │ └── projections - │ │ │ │ ├── 1 [as="lookup_join_const_col_@20":42] - │ │ │ │ └── false [as="lookup_join_const_col_@21":43] - │ │ │ └── filters (true) - │ │ ├── scan cardsinfo - │ │ │ ├── columns: cardsinfo.dealerid:9!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null - │ │ │ ├── constraint: /9/10: [/1 - /1] - │ │ │ ├── stats: [rows=58333.33, distinct(9)=1, null(9)=0, distinct(10)=37420.4, null(10)=0, distinct(11)=40676.7, null(11)=0, distinct(12)=40676.7, null(12)=0, distinct(13)=40676.7, null(13)=0, distinct(14)=40676.7, null(14)=0, distinct(15)=40676.7, null(15)=0, distinct(16)=40676.7, null(16)=0, distinct(17)=58333.3, null(17)=0] - │ │ │ ├── key: (10) - │ │ │ ├── fd: ()-->(9), (10)-->(11-17), (17)-->(10-16) - │ │ │ └── ordering: +10 opt(9) [actual: +10] - │ │ └── filters (true) - │ └── aggregations - │ ├── sum [as=sum:30, outer=(24)] - │ │ └── quantity:24 - │ ├── const-agg [as=id:1, outer=(1)] - │ │ └── id:1 - │ ├── const-agg [as=name:2, outer=(2)] - │ │ └── name:2 - │ ├── const-agg [as=rarity:3, outer=(3)] - │ │ └── rarity:3 - │ ├── const-agg [as=setname:4, outer=(4)] - │ │ └── setname:4 - │ ├── const-agg [as=number:5, outer=(5)] - │ │ └── number:5 - │ ├── const-agg [as=isfoil:6, outer=(6)] - │ │ └── isfoil:6 - │ ├── const-agg [as=cardsinfo.buyprice:11, outer=(11)] - │ │ └── cardsinfo.buyprice:11 - │ ├── const-agg [as=cardsinfo.sellprice:12, outer=(12)] - │ │ └── cardsinfo.sellprice:12 - │ ├── const-agg [as=discount:13, outer=(13)] - │ │ └── discount:13 - │ ├── const-agg [as=desiredinventory:14, outer=(14)] - │ │ └── desiredinventory:14 - │ ├── const-agg [as=actualinventory:15, outer=(15)] - │ │ └── actualinventory:15 - │ ├── const-agg [as=maxinventory:16, outer=(16)] - │ │ └── maxinventory:16 - │ └── const-agg [as=cardsinfo.version:17, outer=(17)] - │ └── cardsinfo.version:17 + │ ├── group-by (partial streaming) + │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null sum:30 + │ │ ├── grouping columns: name:2!null setname:4 number:5!null cardsinfo.cardid:10!null + │ │ ├── internal-ordering: +2,+4,+5 opt(9) + │ │ ├── immutable + │ │ ├── stats: [rows=29618.46, distinct(2,4,5,10)=29618.5, null(2,4,5,10)=0] + │ │ ├── key: (10) + │ │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(1-6,11-17,30), (17)-->(10-16), (1)==(10), (10)==(1) + │ │ ├── ordering: +2,+4,+5 + │ │ ├── limit hint: 50.00 + │ │ ├── left-join (lookup transactiondetails@detailscardidindex) + │ │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.dealerid:9!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null transactiondetails.dealerid:20 isbuy:21 transactiondate:22 transactiondetails.cardid:23 quantity:24 + │ │ │ ├── lookup expression + │ │ │ │ └── filters + │ │ │ │ ├── "lookup_join_const_col_@20":38 = transactiondetails.dealerid:20 [outer=(20,38), constraints=(/20: (/NULL - ]; /38: (/NULL - ]), fd=(20)==(38), (38)==(20)] + │ │ │ │ ├── "lookup_join_const_col_@21":39 = isbuy:21 [outer=(21,39), constraints=(/21: (/NULL - ]; /39: (/NULL - ]), fd=(21)==(39), (39)==(21)] + │ │ │ │ ├── id:1 = transactiondetails.cardid:23 [outer=(1,23), constraints=(/1: (/NULL - ]; /23: (/NULL - ]), fd=(1)==(23), (23)==(1)] + │ │ │ │ └── (transactiondate:22 >= '2020-02-28 00:00:00+00:00') AND (transactiondate:22 <= '2020-03-01 00:00:00+00:00') [outer=(22), constraints=(/22: [/'2020-02-28 00:00:00+00:00' - /'2020-03-01 00:00:00+00:00']; tight)] + │ │ │ ├── immutable + │ │ │ ├── stats: [rows=659920.1, distinct(10)=19000, null(10)=0, distinct(23)=19000, null(23)=0, distinct(2,4,5,10)=29618.5, null(2,4,5,10)=0] + │ │ │ ├── key: (10,22-24) + │ │ │ ├── fd: ()-->(9), (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(11-17), (17)-->(10-16), (1)==(10), (10)==(1), (10,22-24)-->(20,21) + │ │ │ ├── ordering: +2,+4,+5 opt(9) [actual: +2,+4,+5] + │ │ │ ├── limit hint: 1114.04 + │ │ │ ├── project + │ │ │ │ ├── columns: "lookup_join_const_col_@20":38!null "lookup_join_const_col_@21":39!null id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.dealerid:9!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null + │ │ │ │ ├── immutable + │ │ │ │ ├── stats: [rows=29618.46] + │ │ │ │ ├── key: (10) + │ │ │ │ ├── fd: ()-->(9,38,39), (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(11-17), (17)-->(10-16), (1)==(10), (10)==(1) + │ │ │ │ ├── ordering: +2,+4,+5 opt(9,38,39) [actual: +2,+4,+5] + │ │ │ │ ├── limit hint: 100.00 + │ │ │ │ ├── inner-join (lookup cardsinfo) + │ │ │ │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.dealerid:9!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null + │ │ │ │ │ ├── key columns: [32 1] = [9 10] + │ │ │ │ │ ├── lookup columns are key + │ │ │ │ │ ├── immutable + │ │ │ │ │ ├── stats: [rows=29618.46, distinct(1)=19000, null(1)=0, distinct(2)=11668.1, null(2)=0, distinct(5)=829, null(5)=0, distinct(6)=5572.86, null(6)=0, distinct(9)=1, null(9)=0, distinct(10)=19000, null(10)=0, distinct(11)=21038, null(11)=0, distinct(12)=21038, null(12)=0, distinct(13)=21038, null(13)=0, distinct(14)=21038, null(14)=0, distinct(15)=21038, null(15)=0, distinct(16)=21038, null(16)=0, distinct(17)=23225.6, null(17)=0, distinct(2,4,5,10)=29618.5, null(2,4,5,10)=0] + │ │ │ │ │ ├── key: (10) + │ │ │ │ │ ├── fd: ()-->(9), (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(11-17), (17)-->(10-16), (1)==(10), (10)==(1) + │ │ │ │ │ ├── ordering: +2,+4,+5 opt(9) [actual: +2,+4,+5] + │ │ │ │ │ ├── limit hint: 100.00 + │ │ │ │ │ ├── project + │ │ │ │ │ │ ├── columns: "lookup_join_const_col_@9":32!null id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null + │ │ │ │ │ │ ├── immutable + │ │ │ │ │ │ ├── stats: [rows=19000] + │ │ │ │ │ │ ├── key: (1) + │ │ │ │ │ │ ├── fd: ()-->(32), (1)-->(2-6), (2,4,5)~~>(1,3,6) + │ │ │ │ │ │ ├── ordering: +2,+4,+5 opt(32) [actual: +2,+4,+5] + │ │ │ │ │ │ ├── limit hint: 100.00 + │ │ │ │ │ │ ├── index-join cards + │ │ │ │ │ │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null + │ │ │ │ │ │ │ ├── immutable + │ │ │ │ │ │ │ ├── stats: [rows=19000, distinct(1)=19000, null(1)=0, distinct(2)=13000, null(2)=0, distinct(5)=829, null(5)=0, distinct(6)=5601.15, null(6)=0, distinct(2,4,5)=19000, null(2,4,5)=0] + │ │ │ │ │ │ │ ├── key: (1) + │ │ │ │ │ │ │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6) + │ │ │ │ │ │ │ ├── ordering: +2,+4,+5 + │ │ │ │ │ │ │ ├── limit hint: 100.00 + │ │ │ │ │ │ │ └── scan cards@cardsnamesetnumber + │ │ │ │ │ │ │ ├── columns: id:1!null name:2!null setname:4 number:5!null + │ │ │ │ │ │ │ ├── constraint: /2/4/5: [/'Shock'/'7E'/249 - ] + │ │ │ │ │ │ │ ├── stats: [rows=19000, distinct(1)=19000, null(1)=0, distinct(2)=13000, null(2)=0, distinct(5)=829, null(5)=0] + │ │ │ │ │ │ │ ├── key: (1) + │ │ │ │ │ │ │ ├── fd: (1)-->(2,4,5), (2,4,5)~~>(1) + │ │ │ │ │ │ │ ├── ordering: +2,+4,+5 + │ │ │ │ │ │ │ └── limit hint: 100.00 + │ │ │ │ │ │ └── projections + │ │ │ │ │ │ └── 1 [as="lookup_join_const_col_@9":32] + │ │ │ │ │ └── filters (true) + │ │ │ │ └── projections + │ │ │ │ ├── 1 [as="lookup_join_const_col_@20":38] + │ │ │ │ └── false [as="lookup_join_const_col_@21":39] + │ │ │ └── filters (true) + │ │ └── aggregations + │ │ ├── sum [as=sum:30, outer=(24)] + │ │ │ └── quantity:24 + │ │ ├── const-agg [as=id:1, outer=(1)] + │ │ │ └── id:1 + │ │ ├── const-agg [as=rarity:3, outer=(3)] + │ │ │ └── rarity:3 + │ │ ├── const-agg [as=isfoil:6, outer=(6)] + │ │ │ └── isfoil:6 + │ │ ├── const-agg [as=cardsinfo.buyprice:11, outer=(11)] + │ │ │ └── cardsinfo.buyprice:11 + │ │ ├── const-agg [as=cardsinfo.sellprice:12, outer=(12)] + │ │ │ └── cardsinfo.sellprice:12 + │ │ ├── const-agg [as=discount:13, outer=(13)] + │ │ │ └── discount:13 + │ │ ├── const-agg [as=desiredinventory:14, outer=(14)] + │ │ │ └── desiredinventory:14 + │ │ ├── const-agg [as=actualinventory:15, outer=(15)] + │ │ │ └── actualinventory:15 + │ │ ├── const-agg [as=maxinventory:16, outer=(16)] + │ │ │ └── maxinventory:16 + │ │ └── const-agg [as=cardsinfo.version:17, outer=(17)] + │ │ └── cardsinfo.version:17 + │ └── 50 └── projections └── COALESCE(sum:30, 0) [as=value:31, outer=(30)] diff --git a/pkg/sql/opt/xform/testdata/external/trading-mutation b/pkg/sql/opt/xform/testdata/external/trading-mutation index b67faac7d009..69b3b00a6a2e 100644 --- a/pkg/sql/opt/xform/testdata/external/trading-mutation +++ b/pkg/sql/opt/xform/testdata/external/trading-mutation @@ -806,109 +806,112 @@ project ├── key: (17,37) ├── fd: (1)-->(2-6,11-17), (2,4,5)~~>(1,3,6), (17)-->(1-6,11-16) ├── ordering: +2,+4,+5 - ├── top-k + ├── limit │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null cardsinfo.discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null sum:36 │ ├── internal-ordering: +2,+4,+5 - │ ├── k: 50 │ ├── cardinality: [0 - 50] │ ├── immutable │ ├── stats: [rows=50] │ ├── key: (10) │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(1-6,11-17,36), (17)-->(10-16), (1)==(10), (10)==(1) │ ├── ordering: +2,+4,+5 - │ └── group-by (streaming) - │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null cardsinfo.discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null sum:36 - │ ├── grouping columns: cardsinfo.cardid:10!null - │ ├── internal-ordering: +(1|10) opt(9) - │ ├── immutable - │ ├── stats: [rows=19000, distinct(10)=19000, null(10)=0] - │ ├── key: (10) - │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(1-6,11-17,36), (17)-->(10-16), (1)==(10), (10)==(1) - │ ├── inner-join (merge) - │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.dealerid:9!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null cardsinfo.discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null transactiondetails.dealerid:24 isbuy:25 transactiondate:26 transactiondetails.cardid:27 quantity:28 - │ │ ├── left ordering: +1 - │ │ ├── right ordering: +10 - │ │ ├── immutable - │ │ ├── stats: [rows=659920.1, distinct(10)=19000, null(10)=0, distinct(27)=19000, null(27)=0] - │ │ ├── key: (10,26-28) - │ │ ├── fd: ()-->(9), (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(11-17), (17)-->(10-16), (1)==(10), (10)==(1), (10,26-28)-->(24,25) - │ │ ├── ordering: +(1|10) opt(9) [actual: +1] - │ │ ├── left-join (lookup transactiondetails@detailscardidindex) - │ │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null transactiondetails.dealerid:24 isbuy:25 transactiondate:26 transactiondetails.cardid:27 quantity:28 - │ │ │ ├── lookup expression - │ │ │ │ └── filters - │ │ │ │ ├── "lookup_join_const_col_@24":48 = transactiondetails.dealerid:24 [outer=(24,48), constraints=(/24: (/NULL - ]; /48: (/NULL - ]), fd=(24)==(48), (48)==(24)] - │ │ │ │ ├── "lookup_join_const_col_@25":49 = isbuy:25 [outer=(25,49), constraints=(/25: (/NULL - ]; /49: (/NULL - ]), fd=(25)==(49), (49)==(25)] - │ │ │ │ ├── id:1 = transactiondetails.cardid:27 [outer=(1,27), constraints=(/1: (/NULL - ]; /27: (/NULL - ]), fd=(1)==(27), (27)==(1)] - │ │ │ │ └── (transactiondate:26 >= '2020-02-28 00:00:00+00:00') AND (transactiondate:26 <= '2020-03-01 00:00:00+00:00') [outer=(26), constraints=(/26: [/'2020-02-28 00:00:00+00:00' - /'2020-03-01 00:00:00+00:00']; tight)] - │ │ │ ├── immutable - │ │ │ ├── stats: [rows=423333.3, distinct(1)=19000, null(1)=0, distinct(2)=13000, null(2)=0, distinct(5)=829, null(5)=0, distinct(6)=5601.15, null(6)=0, distinct(27)=19000, null(27)=0] - │ │ │ ├── key: (1,26-28) - │ │ │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6), (1,26-28)-->(24,25) - │ │ │ ├── ordering: +1 - │ │ │ ├── project - │ │ │ │ ├── columns: "lookup_join_const_col_@24":48!null "lookup_join_const_col_@25":49!null id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null - │ │ │ │ ├── immutable - │ │ │ │ ├── stats: [rows=19000] - │ │ │ │ ├── key: (1) - │ │ │ │ ├── fd: ()-->(48,49), (1)-->(2-6), (2,4,5)~~>(1,3,6) - │ │ │ │ ├── ordering: +1 opt(48,49) [actual: +1] - │ │ │ │ ├── select - │ │ │ │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null - │ │ │ │ │ ├── immutable - │ │ │ │ │ ├── stats: [rows=19000, distinct(1)=19000, null(1)=0, distinct(2)=13000, null(2)=0, distinct(5)=829, null(5)=0, distinct(6)=5601.15, null(6)=0] - │ │ │ │ │ ├── key: (1) - │ │ │ │ │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6) - │ │ │ │ │ ├── ordering: +1 - │ │ │ │ │ ├── scan cards - │ │ │ │ │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null - │ │ │ │ │ │ ├── stats: [rows=57000, distinct(1)=57000, null(1)=0, distinct(2)=39000, null(2)=0, distinct(5)=829, null(5)=0, distinct(6)=5700, null(6)=0] - │ │ │ │ │ │ ├── key: (1) - │ │ │ │ │ │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6) - │ │ │ │ │ │ └── ordering: +1 - │ │ │ │ │ └── filters - │ │ │ │ │ └── (name:2, setname:4, number:5) > ('Shock', '7E', 248) [outer=(2,4,5), immutable, constraints=(/2/4/5: [/'Shock'/'7E'/249 - ]; tight)] - │ │ │ │ └── projections - │ │ │ │ ├── 1 [as="lookup_join_const_col_@24":48] - │ │ │ │ └── false [as="lookup_join_const_col_@25":49] - │ │ │ └── filters (true) - │ │ ├── scan cardsinfo - │ │ │ ├── columns: cardsinfo.dealerid:9!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null cardsinfo.discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null - │ │ │ ├── constraint: /9/10: [/1 - /1] - │ │ │ ├── stats: [rows=58333.33, distinct(9)=1, null(9)=0, distinct(10)=37420.4, null(10)=0, distinct(11)=40676.7, null(11)=0, distinct(12)=40676.7, null(12)=0, distinct(13)=40676.7, null(13)=0, distinct(14)=40676.7, null(14)=0, distinct(15)=40676.7, null(15)=0, distinct(16)=40676.7, null(16)=0, distinct(17)=58333.3, null(17)=0] - │ │ │ ├── key: (10) - │ │ │ ├── fd: ()-->(9), (10)-->(11-17), (17)-->(10-16) - │ │ │ └── ordering: +10 opt(9) [actual: +10] - │ │ └── filters (true) - │ └── aggregations - │ ├── sum [as=sum:36, outer=(28)] - │ │ └── quantity:28 - │ ├── const-agg [as=id:1, outer=(1)] - │ │ └── id:1 - │ ├── const-agg [as=name:2, outer=(2)] - │ │ └── name:2 - │ ├── const-agg [as=rarity:3, outer=(3)] - │ │ └── rarity:3 - │ ├── const-agg [as=setname:4, outer=(4)] - │ │ └── setname:4 - │ ├── const-agg [as=number:5, outer=(5)] - │ │ └── number:5 - │ ├── const-agg [as=isfoil:6, outer=(6)] - │ │ └── isfoil:6 - │ ├── const-agg [as=cardsinfo.buyprice:11, outer=(11)] - │ │ └── cardsinfo.buyprice:11 - │ ├── const-agg [as=cardsinfo.sellprice:12, outer=(12)] - │ │ └── cardsinfo.sellprice:12 - │ ├── const-agg [as=cardsinfo.discount:13, outer=(13)] - │ │ └── cardsinfo.discount:13 - │ ├── const-agg [as=desiredinventory:14, outer=(14)] - │ │ └── desiredinventory:14 - │ ├── const-agg [as=actualinventory:15, outer=(15)] - │ │ └── actualinventory:15 - │ ├── const-agg [as=maxinventory:16, outer=(16)] - │ │ └── maxinventory:16 - │ └── const-agg [as=cardsinfo.version:17, outer=(17)] - │ └── cardsinfo.version:17 + │ ├── group-by (partial streaming) + │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null cardsinfo.discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null sum:36 + │ │ ├── grouping columns: name:2!null setname:4 number:5!null cardsinfo.cardid:10!null + │ │ ├── internal-ordering: +2,+4,+5 opt(9) + │ │ ├── immutable + │ │ ├── stats: [rows=29618.46, distinct(2,4,5,10)=29618.5, null(2,4,5,10)=0] + │ │ ├── key: (10) + │ │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(1-6,11-17,36), (17)-->(10-16), (1)==(10), (10)==(1) + │ │ ├── ordering: +2,+4,+5 + │ │ ├── limit hint: 50.00 + │ │ ├── left-join (lookup transactiondetails@detailscardidindex) + │ │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.dealerid:9!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null cardsinfo.discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null transactiondetails.dealerid:24 isbuy:25 transactiondate:26 transactiondetails.cardid:27 quantity:28 + │ │ │ ├── lookup expression + │ │ │ │ └── filters + │ │ │ │ ├── "lookup_join_const_col_@24":44 = transactiondetails.dealerid:24 [outer=(24,44), constraints=(/24: (/NULL - ]; /44: (/NULL - ]), fd=(24)==(44), (44)==(24)] + │ │ │ │ ├── "lookup_join_const_col_@25":45 = isbuy:25 [outer=(25,45), constraints=(/25: (/NULL - ]; /45: (/NULL - ]), fd=(25)==(45), (45)==(25)] + │ │ │ │ ├── id:1 = transactiondetails.cardid:27 [outer=(1,27), constraints=(/1: (/NULL - ]; /27: (/NULL - ]), fd=(1)==(27), (27)==(1)] + │ │ │ │ └── (transactiondate:26 >= '2020-02-28 00:00:00+00:00') AND (transactiondate:26 <= '2020-03-01 00:00:00+00:00') [outer=(26), constraints=(/26: [/'2020-02-28 00:00:00+00:00' - /'2020-03-01 00:00:00+00:00']; tight)] + │ │ │ ├── immutable + │ │ │ ├── stats: [rows=659920.1, distinct(10)=19000, null(10)=0, distinct(27)=19000, null(27)=0, distinct(2,4,5,10)=29618.5, null(2,4,5,10)=0] + │ │ │ ├── key: (10,26-28) + │ │ │ ├── fd: ()-->(9), (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(11-17), (17)-->(10-16), (1)==(10), (10)==(1), (10,26-28)-->(24,25) + │ │ │ ├── ordering: +2,+4,+5 opt(9) [actual: +2,+4,+5] + │ │ │ ├── limit hint: 1114.04 + │ │ │ ├── project + │ │ │ │ ├── columns: "lookup_join_const_col_@24":44!null "lookup_join_const_col_@25":45!null id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.dealerid:9!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null cardsinfo.discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null + │ │ │ │ ├── immutable + │ │ │ │ ├── stats: [rows=29618.46] + │ │ │ │ ├── key: (10) + │ │ │ │ ├── fd: ()-->(9,44,45), (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(11-17), (17)-->(10-16), (1)==(10), (10)==(1) + │ │ │ │ ├── ordering: +2,+4,+5 opt(9,44,45) [actual: +2,+4,+5] + │ │ │ │ ├── limit hint: 100.00 + │ │ │ │ ├── inner-join (lookup cardsinfo) + │ │ │ │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null cardsinfo.dealerid:9!null cardsinfo.cardid:10!null cardsinfo.buyprice:11!null cardsinfo.sellprice:12!null cardsinfo.discount:13!null desiredinventory:14!null actualinventory:15!null maxinventory:16!null cardsinfo.version:17!null + │ │ │ │ │ ├── key columns: [38 1] = [9 10] + │ │ │ │ │ ├── lookup columns are key + │ │ │ │ │ ├── immutable + │ │ │ │ │ ├── stats: [rows=29618.46, distinct(1)=19000, null(1)=0, distinct(2)=11668.1, null(2)=0, distinct(5)=829, null(5)=0, distinct(6)=5572.86, null(6)=0, distinct(9)=1, null(9)=0, distinct(10)=19000, null(10)=0, distinct(11)=21038, null(11)=0, distinct(12)=21038, null(12)=0, distinct(13)=21038, null(13)=0, distinct(14)=21038, null(14)=0, distinct(15)=21038, null(15)=0, distinct(16)=21038, null(16)=0, distinct(17)=23225.6, null(17)=0, distinct(2,4,5,10)=29618.5, null(2,4,5,10)=0] + │ │ │ │ │ ├── key: (10) + │ │ │ │ │ ├── fd: ()-->(9), (1)-->(2-6), (2,4,5)~~>(1,3,6), (10)-->(11-17), (17)-->(10-16), (1)==(10), (10)==(1) + │ │ │ │ │ ├── ordering: +2,+4,+5 opt(9) [actual: +2,+4,+5] + │ │ │ │ │ ├── limit hint: 100.00 + │ │ │ │ │ ├── project + │ │ │ │ │ │ ├── columns: "lookup_join_const_col_@9":38!null id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null + │ │ │ │ │ │ ├── immutable + │ │ │ │ │ │ ├── stats: [rows=19000] + │ │ │ │ │ │ ├── key: (1) + │ │ │ │ │ │ ├── fd: ()-->(38), (1)-->(2-6), (2,4,5)~~>(1,3,6) + │ │ │ │ │ │ ├── ordering: +2,+4,+5 opt(38) [actual: +2,+4,+5] + │ │ │ │ │ │ ├── limit hint: 100.00 + │ │ │ │ │ │ ├── index-join cards + │ │ │ │ │ │ │ ├── columns: id:1!null name:2!null rarity:3 setname:4 number:5!null isfoil:6!null + │ │ │ │ │ │ │ ├── immutable + │ │ │ │ │ │ │ ├── stats: [rows=19000, distinct(1)=19000, null(1)=0, distinct(2)=13000, null(2)=0, distinct(5)=829, null(5)=0, distinct(6)=5601.15, null(6)=0, distinct(2,4,5)=19000, null(2,4,5)=0] + │ │ │ │ │ │ │ ├── key: (1) + │ │ │ │ │ │ │ ├── fd: (1)-->(2-6), (2,4,5)~~>(1,3,6) + │ │ │ │ │ │ │ ├── ordering: +2,+4,+5 + │ │ │ │ │ │ │ ├── limit hint: 100.00 + │ │ │ │ │ │ │ └── scan cards@cardsnamesetnumber + │ │ │ │ │ │ │ ├── columns: id:1!null name:2!null setname:4 number:5!null + │ │ │ │ │ │ │ ├── constraint: /2/4/5: [/'Shock'/'7E'/249 - ] + │ │ │ │ │ │ │ ├── stats: [rows=19000, distinct(1)=19000, null(1)=0, distinct(2)=13000, null(2)=0, distinct(5)=829, null(5)=0] + │ │ │ │ │ │ │ ├── key: (1) + │ │ │ │ │ │ │ ├── fd: (1)-->(2,4,5), (2,4,5)~~>(1) + │ │ │ │ │ │ │ ├── ordering: +2,+4,+5 + │ │ │ │ │ │ │ └── limit hint: 100.00 + │ │ │ │ │ │ └── projections + │ │ │ │ │ │ └── 1 [as="lookup_join_const_col_@9":38] + │ │ │ │ │ └── filters (true) + │ │ │ │ └── projections + │ │ │ │ ├── 1 [as="lookup_join_const_col_@24":44] + │ │ │ │ └── false [as="lookup_join_const_col_@25":45] + │ │ │ └── filters (true) + │ │ └── aggregations + │ │ ├── sum [as=sum:36, outer=(28)] + │ │ │ └── quantity:28 + │ │ ├── const-agg [as=id:1, outer=(1)] + │ │ │ └── id:1 + │ │ ├── const-agg [as=rarity:3, outer=(3)] + │ │ │ └── rarity:3 + │ │ ├── const-agg [as=isfoil:6, outer=(6)] + │ │ │ └── isfoil:6 + │ │ ├── const-agg [as=cardsinfo.buyprice:11, outer=(11)] + │ │ │ └── cardsinfo.buyprice:11 + │ │ ├── const-agg [as=cardsinfo.sellprice:12, outer=(12)] + │ │ │ └── cardsinfo.sellprice:12 + │ │ ├── const-agg [as=cardsinfo.discount:13, outer=(13)] + │ │ │ └── cardsinfo.discount:13 + │ │ ├── const-agg [as=desiredinventory:14, outer=(14)] + │ │ │ └── desiredinventory:14 + │ │ ├── const-agg [as=actualinventory:15, outer=(15)] + │ │ │ └── actualinventory:15 + │ │ ├── const-agg [as=maxinventory:16, outer=(16)] + │ │ │ └── maxinventory:16 + │ │ └── const-agg [as=cardsinfo.version:17, outer=(17)] + │ │ └── cardsinfo.version:17 + │ └── 50 └── projections └── COALESCE(sum:36, 0) [as=value:37, outer=(36)] diff --git a/pkg/sql/opt/xform/testdata/rules/limit b/pkg/sql/opt/xform/testdata/rules/limit index ac4ebd938043..9749e3a562dc 100644 --- a/pkg/sql/opt/xform/testdata/rules/limit +++ b/pkg/sql/opt/xform/testdata/rules/limit @@ -2578,3 +2578,469 @@ scalar-group-by └── aggregations └── const-agg [as=min:7, outer=(1)] └── a:1 + +# Regression Test for #93410 +exec-ddl +CREATE TABLE t93410 ( + col1 INT NOT NULL, + col2 INT NOT NULL, + col3 INT NOT NULL, + col4 INT NOT NULL, + col5 INT NOT NULL, + col6 INT NOT NULL, + col7 INT NOT NULL, + col8 INT NOT NULL, + col9 INT NOT NULL, + col10 INT NOT NULL, + col11 INT NOT NULL, + col12 INT NULL, + col13 INT NULL, + col14 INT NOT NULL, + col15 INT NULL, + col16 INT, + CONSTRAINT "primary" PRIMARY KEY (col1 ASC, col2 ASC, col3 ASC, col4 ASC, col5 ASC), + CONSTRAINT fk_col1_ref_t93410 FOREIGN KEY (col1, col2, col3, col4, col12) REFERENCES t93410(col1, col2, col3, col4, col5) ON DELETE CASCADE, + UNIQUE INDEX t93410_col1_col2_col3_col5_key (col1 ASC, col2 ASC, col3 ASC, col5 ASC), + INDEX t93410_col13_idx (col13 ASC), + INDEX t93410_col1_col2_col13_col15_idx (col1 ASC, col2 ASC, col13 ASC, col15 ASC), + UNIQUE INDEX t93410_col1_col2_col5_col9_key (col1 ASC, col2 ASC, col5 ASC, col9 ASC), + UNIQUE INDEX t93410_col1_col2_col5_key (col1 ASC, col2 ASC, col5 ASC) +) +---- + +exec-ddl +CREATE TABLE t93410_2 ( + col1 INT NOT NULL, + col2 INT NOT NULL, + col3 INT NOT NULL, + col4 INT NOT NULL, + col5 INT NOT NULL, + col6 INT NOT NULL, + CONSTRAINT "primary" PRIMARY KEY (col1 ASC, col2 ASC, col3 ASC, col5 ASC, col6 ASC), + CONSTRAINT fk_col1_ref_t93410 FOREIGN KEY (col1, col2, col3, col4, col5) REFERENCES t93410(col1, col2, col3, col4, col5) ON DELETE CASCADE, + INDEX t93410_2_col1_col2_col3_col4_col5_idx (col1 ASC, col2 ASC, col3 ASC, col4 ASC, col5 ASC) +) +---- + +exec-ddl +ALTER TABLE t93410 INJECT STATISTICS '[ + { + "avg_size": 2, + "columns": [ + "col1" + ], + "created_at": "2022-12-15 19:58:40.9211", + "distinct_count": 100000, + "histo_buckets": [ + { + "distinct_range": 0, + "num_eq": 300002, + "num_range": 0, + "upper_bound": "1" + }, + { + "distinct_range": 100000, + "num_eq": 0, + "num_range": 100000, + "upper_bound": "100000" + } + ], + "histo_col_type": "INT8", + "histo_version": 2, + "null_count": 0, + "row_count": 400001 + }, + { + "avg_size": 2, + "columns": [ + "col2" + ], + "created_at": "2022-12-15 19:58:40.9211", + "distinct_count": 100000, + "histo_buckets": [ + { + "distinct_range": 0, + "num_eq": 300002, + "num_range": 0, + "upper_bound": "1" + }, + { + "distinct_range": 100000, + "num_eq": 0, + "num_range": 100000, + "upper_bound": "100000" + } + ], + "histo_col_type": "INT8", + "histo_version": 2, + "null_count": 0, + "row_count": 400001 + } +]'; +---- + +exec-ddl +ALTER TABLE t93410_2 INJECT STATISTICS '[ + { + "avg_size": 2, + "columns": [ + "col1" + ], + "created_at": "2022-12-15 19:58:40.9211", + "distinct_count": 100000, + "histo_buckets": [ + { + "distinct_range": 0, + "num_eq": 300002, + "num_range": 0, + "upper_bound": "1" + }, + { + "distinct_range": 100000, + "num_eq": 0, + "num_range": 100000, + "upper_bound": "100000" + } + ], + "histo_col_type": "INT8", + "histo_version": 2, + "null_count": 0, + "row_count": 400001 + }, + { + "avg_size": 2, + "columns": [ + "col2" + ], + "created_at": "2022-12-15 19:58:40.9211", + "distinct_count": 100000, + "histo_buckets": [ + { + "distinct_range": 0, + "num_eq": 300002, + "num_range": 0, + "upper_bound": "1" + }, + { + "distinct_range": 100000, + "num_eq": 0, + "num_range": 100000, + "upper_bound": "100000" + } + ], + "histo_col_type": "INT8", + "histo_version": 2, + "null_count": 0, + "row_count": 400001 + } +]'; +---- + +# A streaming group-by with no TopK operation should be generated. +opt expect=GenerateStreamingGroupByLimitOrderingHint +SELECT + DISTINCT + t1.col1, + t1.col2, + t1.col3, + t1.col4, + t1.col5, + t1.col6, + t1.col7, + t1.col8, + t1.col9, + t1.col10, + t1.col11, + t1.col12, + t1.col13, + t1.col14, + t1.col15, + t1.col16, + array_remove(array_agg(t2.col6), NULL) AS col6s +FROM + t93410 AS t1 + LEFT OUTER JOIN t93410_2 + AS t2 USING (col1, col2, col3, col4, col5) +WHERE + t1.col2 = 1 + AND t1.col1 = 1 +GROUP BY + t1.col1, + t1.col2, + t1.col3, + t1.col4, + t1.col5 +ORDER BY + col9 DESC, t1.col5 DESC +LIMIT 20 +---- +project + ├── columns: col1:1!null col2:2!null col3:3!null col4:4!null col5:5!null col6:6!null col7:7!null col8:8!null col9:9!null col10:10!null col11:11!null col12:12 col13:13 col14:14!null col15:15 col16:16 col6s:28 + ├── cardinality: [0 - 20] + ├── immutable + ├── key: (5) + ├── fd: ()-->(1,2), (5)-->(3,4,6-16,28) + ├── ordering: -9,-5 opt(1,2) [actual: -9,-5] + ├── limit + │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null t1.col5:5!null t1.col6:6!null col7:7!null col8:8!null col9:9!null col10:10!null col11:11!null col12:12 col13:13 col14:14!null col15:15 col16:16 array_agg:27 + │ ├── internal-ordering: -9,-5 opt(1,2) + │ ├── cardinality: [0 - 20] + │ ├── key: (5) + │ ├── fd: ()-->(1,2), (5)-->(1-4,6-16,27) + │ ├── ordering: -9,-5 opt(1,2) [actual: -9,-5] + │ ├── group-by (streaming) + │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null t1.col5:5!null t1.col6:6!null col7:7!null col8:8!null col9:9!null col10:10!null col11:11!null col12:12 col13:13 col14:14!null col15:15 col16:16 array_agg:27 + │ │ ├── grouping columns: t1.col5:5!null col9:9!null + │ │ ├── internal-ordering: -9,-5 opt(1,2) + │ │ ├── key: (5) + │ │ ├── fd: ()-->(1,2), (5)-->(1-4,6-16,27) + │ │ ├── ordering: -9,-5 opt(1,2) [actual: -9,-5] + │ │ ├── limit hint: 20.00 + │ │ ├── left-join (lookup t93410_2@t93410_2_col1_col2_col3_col4_col5_idx [as=t2]) + │ │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null t1.col5:5!null t1.col6:6!null col7:7!null col8:8!null col9:9!null col10:10!null col11:11!null col12:12 col13:13 col14:14!null col15:15 col16:16 t2.col1:19 t2.col2:20 t2.col3:21 t2.col4:22 t2.col5:23 t2.col6:24 + │ │ │ ├── key columns: [1 2 3 4 5] = [19 20 21 22 23] + │ │ │ ├── key: (5,21,23,24) + │ │ │ ├── fd: ()-->(1,2), (5)-->(3,4,6-16), (21,23,24)-->(22), (5,21,23,24)-->(19,20) + │ │ │ ├── ordering: -9,-5 opt(1,2) [actual: -9,-5] + │ │ │ ├── limit hint: 20.00 + │ │ │ ├── index-join t93410 + │ │ │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null t1.col5:5!null t1.col6:6!null col7:7!null col8:8!null col9:9!null col10:10!null col11:11!null col12:12 col13:13 col14:14!null col15:15 col16:16 + │ │ │ │ ├── key: (5) + │ │ │ │ ├── fd: ()-->(1,2), (5)-->(3,4,6-16) + │ │ │ │ ├── ordering: -9,-5 opt(1,2) [actual: -9,-5] + │ │ │ │ ├── limit hint: 100.00 + │ │ │ │ └── sort + │ │ │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null t1.col5:5!null col9:9!null + │ │ │ │ ├── key: (5) + │ │ │ │ ├── fd: ()-->(1,2), (5)-->(3,4,9) + │ │ │ │ ├── ordering: -9,-5 opt(1,2) [actual: -9,-5] + │ │ │ │ ├── limit hint: 100.00 + │ │ │ │ └── scan t93410@t93410_col1_col2_col5_col9_key [as=t1] + │ │ │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null t1.col5:5!null col9:9!null + │ │ │ │ ├── constraint: /1/2/5/9: [/1/1 - /1/1] + │ │ │ │ ├── key: (5) + │ │ │ │ └── fd: ()-->(1,2), (5)-->(3,4,9) + │ │ │ └── filters + │ │ │ ├── t2.col2:20 = 1 [outer=(20), constraints=(/20: [/1 - /1]; tight), fd=()-->(20)] + │ │ │ └── t2.col1:19 = 1 [outer=(19), constraints=(/19: [/1 - /1]; tight), fd=()-->(19)] + │ │ └── aggregations + │ │ ├── array-agg [as=array_agg:27, outer=(24)] + │ │ │ └── t2.col6:24 + │ │ ├── const-agg [as=t1.col1:1, outer=(1)] + │ │ │ └── t1.col1:1 + │ │ ├── const-agg [as=t1.col2:2, outer=(2)] + │ │ │ └── t1.col2:2 + │ │ ├── const-agg [as=t1.col3:3, outer=(3)] + │ │ │ └── t1.col3:3 + │ │ ├── const-agg [as=t1.col4:4, outer=(4)] + │ │ │ └── t1.col4:4 + │ │ ├── const-agg [as=t1.col6:6, outer=(6)] + │ │ │ └── t1.col6:6 + │ │ ├── const-agg [as=col7:7, outer=(7)] + │ │ │ └── col7:7 + │ │ ├── const-agg [as=col8:8, outer=(8)] + │ │ │ └── col8:8 + │ │ ├── const-agg [as=col10:10, outer=(10)] + │ │ │ └── col10:10 + │ │ ├── const-agg [as=col11:11, outer=(11)] + │ │ │ └── col11:11 + │ │ ├── const-agg [as=col12:12, outer=(12)] + │ │ │ └── col12:12 + │ │ ├── const-agg [as=col13:13, outer=(13)] + │ │ │ └── col13:13 + │ │ ├── const-agg [as=col14:14, outer=(14)] + │ │ │ └── col14:14 + │ │ ├── const-agg [as=col15:15, outer=(15)] + │ │ │ └── col15:15 + │ │ └── const-agg [as=col16:16, outer=(16)] + │ │ └── col16:16 + │ └── 20 + └── projections + └── array_remove(array_agg:27, NULL) [as=col6s:28, outer=(27), immutable] + +# GenerateStreamingGroupByLimitOrderingHint should not fire if there is no +# overlap between the grouping columns and order-by columns. +opt expect-not=GenerateStreamingGroupByLimitOrderingHint +SELECT + DISTINCT + t2.col1, + t2.col2, + t2.col3, + t2.col4, + t2.col5, + array_remove(array_agg(t1.col6), NULL) AS col6s +FROM + t93410 AS t1 + LEFT OUTER JOIN t93410_2 + AS t2 USING (col1, col2, col3, col4, col5) +WHERE + t1.col2 = 1 + AND t1.col1 = 1 +GROUP BY + t2.col1, + t2.col2, + t2.col3, + t2.col4, + t2.col5 +ORDER BY + col6s DESC +LIMIT 20 +---- +top-k + ├── columns: col1:19 col2:20 col3:21 col4:22 col5:23 col6s:28 + ├── internal-ordering: -28 + ├── k: 20 + ├── cardinality: [0 - 20] + ├── immutable + ├── key: (19-23) + ├── fd: (19-23)-->(28) + ├── ordering: -28 + └── project + ├── columns: col6s:28 t2.col1:19 t2.col2:20 t2.col3:21 t2.col4:22 t2.col5:23 + ├── immutable + ├── key: (19-23) + ├── fd: (19-23)-->(28) + ├── group-by (hash) + │ ├── columns: t2.col1:19 t2.col2:20 t2.col3:21 t2.col4:22 t2.col5:23 array_agg:27!null + │ ├── grouping columns: t2.col1:19 t2.col2:20 t2.col3:21 t2.col4:22 t2.col5:23 + │ ├── key: (19-23) + │ ├── fd: (19-23)-->(27) + │ ├── left-join (merge) + │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null t1.col5:5!null t1.col6:6!null t2.col1:19 t2.col2:20 t2.col3:21 t2.col4:22 t2.col5:23 + │ │ ├── left ordering: +3,+4,+5,+1,+2 + │ │ ├── right ordering: +21,+22,+23,+19,+20 + │ │ ├── fd: ()-->(1,2), (5)-->(3,4,6) + │ │ ├── scan t93410 [as=t1] + │ │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null t1.col5:5!null t1.col6:6!null + │ │ │ ├── constraint: /1/2/3/4/5: [/1/1 - /1/1] + │ │ │ ├── key: (5) + │ │ │ ├── fd: ()-->(1,2), (5)-->(3,4,6) + │ │ │ └── ordering: +3,+4,+5 opt(1,2) [actual: +3,+4,+5] + │ │ ├── scan t93410_2@t93410_2_col1_col2_col3_col4_col5_idx [as=t2] + │ │ │ ├── columns: t2.col1:19!null t2.col2:20!null t2.col3:21!null t2.col4:22!null t2.col5:23!null + │ │ │ ├── constraint: /19/20/21/22/23/24: [/1/1 - /1/1] + │ │ │ ├── fd: ()-->(19,20) + │ │ │ └── ordering: +21,+22,+23 opt(19,20) [actual: +21,+22,+23] + │ │ └── filters (true) + │ └── aggregations + │ └── array-agg [as=array_agg:27, outer=(6)] + │ └── t1.col6:6 + └── projections + └── array_remove(array_agg:27, NULL) [as=col6s:28, outer=(27), immutable] + +# A distinct-on which satisfies the required ordering should be used. +opt expect=GenerateStreamingGroupByLimitOrderingHint +SELECT + DISTINCT ON (t1.col5, t1.col9) t2.col2 +FROM + t93410 AS t1 + LEFT OUTER JOIN t93410_2 + AS t2 USING (col1, col2, col3, col4, col5) +WHERE + t1.col2 = 1 + AND t1.col1 = 1 +ORDER BY + col9 ASC, t1.col5 DESC +LIMIT 20 +---- +limit + ├── columns: col2:20 [hidden: t1.col5:5!null col9:9!null] + ├── internal-ordering: +9,-5 + ├── cardinality: [0 - 20] + ├── key: (5) + ├── fd: (5)-->(9,20) + ├── ordering: +9,-5 + ├── distinct-on + │ ├── columns: t1.col5:5!null col9:9!null t2.col2:20 + │ ├── grouping columns: t1.col5:5!null col9:9!null + │ ├── internal-ordering: +9,-5 opt(1,2) + │ ├── key: (5) + │ ├── fd: (5)-->(9,20) + │ ├── ordering: +9,-5 + │ ├── limit hint: 20.00 + │ ├── left-join (lookup t93410_2@t93410_2_col1_col2_col3_col4_col5_idx [as=t2]) + │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null t1.col5:5!null col9:9!null t2.col1:19 t2.col2:20 t2.col3:21 t2.col4:22 t2.col5:23 + │ │ ├── key columns: [1 2 3 4 5] = [19 20 21 22 23] + │ │ ├── fd: ()-->(1,2), (5)-->(3,4,9) + │ │ ├── ordering: +9,-5 opt(1,2) [actual: +9,-5] + │ │ ├── limit hint: 24.00 + │ │ ├── sort + │ │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null t1.col5:5!null col9:9!null + │ │ │ ├── key: (5) + │ │ │ ├── fd: ()-->(1,2), (5)-->(3,4,9) + │ │ │ ├── ordering: +9,-5 opt(1,2) [actual: +9,-5] + │ │ │ ├── limit hint: 100.00 + │ │ │ └── scan t93410@t93410_col1_col2_col5_col9_key [as=t1] + │ │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null t1.col5:5!null col9:9!null + │ │ │ ├── constraint: /1/2/5/9: [/1/1 - /1/1] + │ │ │ ├── key: (5) + │ │ │ └── fd: ()-->(1,2), (5)-->(3,4,9) + │ │ └── filters + │ │ ├── t2.col2:20 = 1 [outer=(20), constraints=(/20: [/1 - /1]; tight), fd=()-->(20)] + │ │ └── t2.col1:19 = 1 [outer=(19), constraints=(/19: [/1 - /1]; tight), fd=()-->(19)] + │ └── aggregations + │ └── first-agg [as=t2.col2:20, outer=(20)] + │ └── t2.col2:20 + └── 20 + +# This should generate a partial streaming aggregation. +opt expect=GenerateStreamingGroupByLimitOrderingHint +SELECT + count(*) +FROM + t93410 AS t1 + LEFT OUTER JOIN t93410_2 + AS t2 USING (col1, col2, col3, col4) +WHERE + t1.col2 = 1 +GROUP BY + t1.col2, + t1.col3, + t1.col4 +ORDER BY + t1.col4 DESC +LIMIT 20 +---- +project + ├── columns: count:27!null [hidden: t1.col4:4!null] + ├── cardinality: [0 - 20] + ├── ordering: -4 + └── limit + ├── columns: t1.col3:3!null t1.col4:4!null count_rows:27!null + ├── internal-ordering: -4 + ├── cardinality: [0 - 20] + ├── key: (3,4) + ├── fd: (3,4)-->(27) + ├── ordering: -4 + ├── group-by (partial streaming) + │ ├── columns: t1.col3:3!null t1.col4:4!null count_rows:27!null + │ ├── grouping columns: t1.col3:3!null t1.col4:4!null + │ ├── key: (3,4) + │ ├── fd: (3,4)-->(27) + │ ├── ordering: -4 + │ ├── limit hint: 20.00 + │ ├── left-join (lookup t93410_2@t93410_2_col1_col2_col3_col4_col5_idx [as=t2]) + │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null t2.col1:19 t2.col2:20 t2.col3:21 t2.col4:22 + │ │ ├── key columns: [1 2 3 4] = [19 20 21 22] + │ │ ├── fd: ()-->(2) + │ │ ├── ordering: -4 opt(2) [actual: -4] + │ │ ├── limit hint: 20.00 + │ │ ├── sort + │ │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null + │ │ │ ├── fd: ()-->(2) + │ │ │ ├── ordering: -4 opt(2) [actual: -4] + │ │ │ ├── limit hint: 100.00 + │ │ │ └── select + │ │ │ ├── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null + │ │ │ ├── fd: ()-->(2) + │ │ │ ├── scan t93410@t93410_col1_col2_col3_col5_key [as=t1] + │ │ │ │ └── columns: t1.col1:1!null t1.col2:2!null t1.col3:3!null t1.col4:4!null + │ │ │ └── filters + │ │ │ └── t1.col2:2 = 1 [outer=(2), constraints=(/2: [/1 - /1]; tight), fd=()-->(2)] + │ │ └── filters + │ │ └── t2.col2:20 = 1 [outer=(20), constraints=(/20: [/1 - /1]; tight), fd=()-->(20)] + │ └── aggregations + │ └── count-rows [as=count_rows:27] + └── 20 + +# End Regression Test for #93410