From 4e67be88efe636bb65bb55d59d5ab1a0cba99081 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Thu, 22 Aug 2019 16:47:46 +0800 Subject: [PATCH] planner: pick some codes from #8929 (#11829) --- cmd/explaintest/r/explain_complex.result | 6 +- .../r/explain_complex_stats.result | 6 +- cmd/explaintest/r/explain_easy.result | 13 +- cmd/explaintest/r/explain_easy_stats.result | 27 +- cmd/explaintest/r/index_join.result | 4 +- cmd/explaintest/r/topn_push_down.result | 18 +- cmd/explaintest/r/tpch.result | 246 +++++++++--------- planner/core/cbo_test.go | 2 +- planner/core/find_best_task.go | 1 + planner/core/physical_plan_test.go | 4 +- planner/core/rule_column_pruning.go | 6 + planner/core/task.go | 13 +- 12 files changed, 184 insertions(+), 162 deletions(-) diff --git a/cmd/explaintest/r/explain_complex.result b/cmd/explaintest/r/explain_complex.result index cc5b0e389daa9..5c1a435fa3e00 100644 --- a/cmd/explaintest/r/explain_complex.result +++ b/cmd/explaintest/r/explain_complex.result @@ -153,9 +153,9 @@ id count task operator info Projection_9 0.00 root test.dt.id, test.dt.aid, test.dt.pt, test.dt.dic, test.dt.cm, test.rr.gid, test.rr.acd, test.rr.t, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5 └─Limit_12 0.00 root offset:0, count:2000 └─IndexJoin_18 0.00 root inner join, inner:IndexLookUp_17, outer key:test.dt.aid, test.dt.dic, inner key:test.rr.aid, test.rr.dic - ├─TableReader_38 0.00 root data:Selection_37 - │ └─Selection_37 0.00 cop eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592) - │ └─TableScan_36 10000.00 cop table:dt, range:[0,+inf], keep order:false, stats:pseudo + ├─TableReader_40 0.00 root data:Selection_39 + │ └─Selection_39 0.00 cop eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592) + │ └─TableScan_38 10000.00 cop table:dt, range:[0,+inf], keep order:false, stats:pseudo └─IndexLookUp_17 0.00 root ├─IndexScan_14 10.00 cop table:rr, index:aid, dic, range: decided by [test.dt.aid test.dt.dic], keep order:false, stats:pseudo └─Selection_16 0.00 cop eq(test.rr.pt, "ios"), gt(test.rr.t, 1478185592) diff --git a/cmd/explaintest/r/explain_complex_stats.result b/cmd/explaintest/r/explain_complex_stats.result index 5449129ff6744..f9423e2f4f7a0 100644 --- a/cmd/explaintest/r/explain_complex_stats.result +++ b/cmd/explaintest/r/explain_complex_stats.result @@ -161,9 +161,9 @@ id count task operator info Projection_9 428.32 root test.dt.id, test.dt.aid, test.dt.pt, test.dt.dic, test.dt.cm, test.rr.gid, test.rr.acd, test.rr.t, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5 └─Limit_12 428.32 root offset:0, count:2000 └─IndexJoin_18 428.32 root inner join, inner:IndexLookUp_17, outer key:test.dt.aid, test.dt.dic, inner key:test.rr.aid, test.rr.dic - ├─TableReader_38 428.32 root data:Selection_37 - │ └─Selection_37 428.32 cop eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592) - │ └─TableScan_36 2000.00 cop table:dt, range:[0,+inf], keep order:false + ├─TableReader_40 428.32 root data:Selection_39 + │ └─Selection_39 428.32 cop eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592) + │ └─TableScan_38 2000.00 cop table:dt, range:[0,+inf], keep order:false └─IndexLookUp_17 0.48 root ├─IndexScan_14 1.00 cop table:rr, index:aid, dic, range: decided by [test.dt.aid test.dt.dic], keep order:false └─Selection_16 0.48 cop eq(test.rr.pt, "ios"), gt(test.rr.t, 1478185592) diff --git a/cmd/explaintest/r/explain_easy.result b/cmd/explaintest/r/explain_easy.result index 7f3e55d88e919..fb09439cdfaa2 100644 --- a/cmd/explaintest/r/explain_easy.result +++ b/cmd/explaintest/r/explain_easy.result @@ -43,8 +43,8 @@ IndexReader_6 10.00 root index:IndexScan_5 explain select * from t1 left join t2 on t1.c2 = t2.c1 where t1.c1 > 1; id count task operator info IndexJoin_11 4166.67 root left outer join, inner:IndexLookUp_10, outer key:test.t1.c2, inner key:test.t2.c1 -├─TableReader_23 3333.33 root data:TableScan_22 -│ └─TableScan_22 3333.33 cop table:t1, range:(1,+inf], keep order:false, stats:pseudo +├─TableReader_25 3333.33 root data:TableScan_24 +│ └─TableScan_24 3333.33 cop table:t1, range:(1,+inf], keep order:false, stats:pseudo └─IndexLookUp_10 10.00 root ├─IndexScan_8 10.00 cop table:t2, index:c1, range: decided by [test.t1.c2], keep order:false, stats:pseudo └─TableScan_9 10.00 cop table:t2, keep order:false, stats:pseudo @@ -115,10 +115,11 @@ Projection_12 10000.00 root eq(test.t1.c2, test.t2.c2) ├─TableReader_16 10000.00 root data:TableScan_15 │ └─TableScan_15 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo └─Limit_21 1.00 root offset:0, count:1 - └─IndexLookUp_43 1.00 root - ├─Limit_42 1.00 cop offset:0, count:1 - │ └─IndexScan_40 1.25 cop table:t2, index:c1, range: decided by [eq(test.t1.c1, test.t2.c1)], keep order:true, stats:pseudo - └─TableScan_41 1.00 cop table:t2, keep order:false, stats:pseudo + └─Projection_44 1.00 root test.t2.c1, test.t2.c2 + └─IndexLookUp_43 1.00 root + ├─Limit_42 1.00 cop offset:0, count:1 + │ └─IndexScan_40 1.25 cop table:t2, index:c1, range: decided by [eq(test.t1.c1, test.t2.c1)], keep order:true, stats:pseudo + └─TableScan_41 1.00 cop table:t2, keep order:false, stats:pseudo explain select * from t1 order by c1 desc limit 1; id count task operator info Limit_10 1.00 root offset:0, count:1 diff --git a/cmd/explaintest/r/explain_easy_stats.result b/cmd/explaintest/r/explain_easy_stats.result index e8f1b7ea26957..5b90c4757e316 100644 --- a/cmd/explaintest/r/explain_easy_stats.result +++ b/cmd/explaintest/r/explain_easy_stats.result @@ -45,15 +45,15 @@ IndexReader_6 0.00 root index:IndexScan_5 └─IndexScan_5 0.00 cop table:t1, index:c2, range:[1,1], keep order:false explain select * from t1 left join t2 on t1.c2 = t2.c1 where t1.c1 > 1; id count task operator info -Projection_6 2481.25 root test.t1.c1, test.t1.c2, test.t1.c3, test.t2.c1, test.t2.c2 -└─MergeJoin_7 2481.25 root left outer join, left key:test.t1.c2, right key:test.t2.c1 - ├─IndexLookUp_17 1998.00 root - │ ├─Selection_16 1998.00 cop gt(test.t1.c1, 1) - │ │ └─IndexScan_14 1999.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:true - │ └─TableScan_15 1998.00 cop table:t1, keep order:false, stats:pseudo - └─IndexLookUp_21 1985.00 root - ├─IndexScan_19 1985.00 cop table:t2, index:c1, range:[NULL,+inf], keep order:true - └─TableScan_20 1985.00 cop table:t2, keep order:false +MergeJoin_7 2481.25 root left outer join, left key:test.t1.c2, right key:test.t2.c1 +├─IndexLookUp_17 1998.00 root +│ ├─Selection_16 1998.00 cop gt(test.t1.c1, 1) +│ │ └─IndexScan_14 1999.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:true +│ └─TableScan_15 1998.00 cop table:t1, keep order:false, stats:pseudo +└─Projection_23 1985.00 root test.t2.c1, test.t2.c2 + └─IndexLookUp_22 1985.00 root + ├─IndexScan_20 1985.00 cop table:t2, index:c1, range:[NULL,+inf], keep order:true + └─TableScan_21 1985.00 cop table:t2, keep order:false explain update t1 set t1.c2 = 2 where t1.c1 = 1; id count task operator info Point_Get_1 1.00 root table:t1, handle:1 @@ -103,10 +103,11 @@ Projection_12 1999.00 root eq(test.t1.c2, test.t2.c2) ├─TableReader_16 1999.00 root data:TableScan_15 │ └─TableScan_15 1999.00 cop table:t1, range:[-inf,+inf], keep order:false └─Limit_21 1.00 root offset:0, count:1 - └─IndexLookUp_43 1.00 root - ├─Limit_42 1.00 cop offset:0, count:1 - │ └─IndexScan_40 1.25 cop table:t2, index:c1, range: decided by [eq(test.t1.c1, test.t2.c1)], keep order:true - └─TableScan_41 1.00 cop table:t2, keep order:false, stats:pseudo + └─Projection_44 1.00 root test.t2.c1, test.t2.c2 + └─IndexLookUp_43 1.00 root + ├─Limit_42 1.00 cop offset:0, count:1 + │ └─IndexScan_40 1.25 cop table:t2, index:c1, range: decided by [eq(test.t1.c1, test.t2.c1)], keep order:true + └─TableScan_41 1.00 cop table:t2, keep order:false, stats:pseudo explain select * from t1 order by c1 desc limit 1; id count task operator info Limit_10 1.00 root offset:0, count:1 diff --git a/cmd/explaintest/r/index_join.result b/cmd/explaintest/r/index_join.result index 3b63a480b0bda..3171d1f4cfe5b 100644 --- a/cmd/explaintest/r/index_join.result +++ b/cmd/explaintest/r/index_join.result @@ -18,5 +18,5 @@ IndexJoin_14 5.00 root inner join, inner:IndexLookUp_13, outer key:test.t2.a, in ├─IndexLookUp_13 5.00 root │ ├─IndexScan_11 5.00 cop table:t1, index:a, range: decided by [test.t2.a], keep order:false │ └─TableScan_12 5.00 cop table:t1, keep order:false -└─TableReader_26 1.00 root data:TableScan_25 - └─TableScan_25 1.00 cop table:t2, range:[-inf,+inf], keep order:false +└─TableReader_28 1.00 root data:TableScan_27 + └─TableScan_27 1.00 cop table:t2, range:[-inf,+inf], keep order:false diff --git a/cmd/explaintest/r/topn_push_down.result b/cmd/explaintest/r/topn_push_down.result index d470301baa01f..9f6dcbfdfdaa0 100644 --- a/cmd/explaintest/r/topn_push_down.result +++ b/cmd/explaintest/r/topn_push_down.result @@ -169,20 +169,20 @@ LIMIT 0, 5; id count task operator info Projection_13 0.00 root test.te.expected_time └─Limit_19 0.00 root offset:0, count:5 - └─IndexJoin_91 0.00 root left outer join, inner:IndexReader_90, outer key:test.tr.id, inner key:test.p.relate_id - ├─TopN_94 0.00 root test.te.expect_time:asc, offset:0, count:5 + └─IndexJoin_92 0.00 root left outer join, inner:IndexReader_91, outer key:test.tr.id, inner key:test.p.relate_id + ├─TopN_95 0.00 root test.te.expect_time:asc, offset:0, count:5 │ └─IndexJoin_35 0.00 root inner join, inner:IndexLookUp_34, outer key:test.tr.id, inner key:test.te.trade_id - │ ├─IndexLookUp_73 0.00 root - │ │ ├─Selection_71 0.00 cop eq(test.tr.business_type, 18), in(test.tr.trade_type, 1) - │ │ │ └─IndexScan_69 10.00 cop table:tr, index:shop_identy, trade_status, business_type, trade_pay_status, trade_type, delivery_type, source, biz_date, range:[810094178,810094178], keep order:false, stats:pseudo - │ │ └─Selection_72 0.00 cop eq(test.tr.brand_identy, 32314), eq(test.tr.domain_type, 2) - │ │ └─TableScan_70 0.00 cop table:tr, keep order:false, stats:pseudo + │ ├─IndexLookUp_74 0.00 root + │ │ ├─Selection_72 0.00 cop eq(test.tr.business_type, 18), in(test.tr.trade_type, 1) + │ │ │ └─IndexScan_70 10.00 cop table:tr, index:shop_identy, trade_status, business_type, trade_pay_status, trade_type, delivery_type, source, biz_date, range:[810094178,810094178], keep order:false, stats:pseudo + │ │ └─Selection_73 0.00 cop eq(test.tr.brand_identy, 32314), eq(test.tr.domain_type, 2) + │ │ └─TableScan_71 0.00 cop table:tr, keep order:false, stats:pseudo │ └─IndexLookUp_34 0.25 root │ ├─IndexScan_31 10.00 cop table:te, index:trade_id, range: decided by [test.tr.id], keep order:false, stats:pseudo │ └─Selection_33 0.25 cop ge(test.te.expect_time, 2018-04-23 00:00:00.000000), le(test.te.expect_time, 2018-04-23 23:59:59.000000) │ └─TableScan_32 10.00 cop table:te, keep order:false, stats:pseudo - └─IndexReader_90 10.00 root index:IndexScan_89 - └─IndexScan_89 10.00 cop table:p, index:relate_id, range: decided by [test.tr.id], keep order:false, stats:pseudo + └─IndexReader_91 10.00 root index:IndexScan_90 + └─IndexScan_90 10.00 cop table:p, index:relate_id, range: decided by [test.tr.id], keep order:false, stats:pseudo desc select 1 as a from dual order by a limit 1; id count task operator info Projection_6 1.00 root 1 diff --git a/cmd/explaintest/r/tpch.result b/cmd/explaintest/r/tpch.result index b18857c42c6de..a66f1028d083f 100644 --- a/cmd/explaintest/r/tpch.result +++ b/cmd/explaintest/r/tpch.result @@ -185,36 +185,36 @@ id count task operator info Projection_34 100.00 root tpch.supplier.s_acctbal, tpch.supplier.s_name, tpch.nation.n_name, tpch.part.p_partkey, tpch.part.p_mfgr, tpch.supplier.s_address, tpch.supplier.s_phone, tpch.supplier.s_comment └─TopN_37 100.00 root tpch.supplier.s_acctbal:desc, tpch.nation.n_name:asc, tpch.supplier.s_name:asc, tpch.part.p_partkey:asc, offset:0, count:100 └─HashRightJoin_39 125109.42 root inner join, inner:HashLeftJoin_44, equal:[eq(tpch.part.p_partkey, tpch.partsupp.ps_partkey) eq(tpch.partsupp.ps_supplycost, min(ps_supplycost))] - ├─HashLeftJoin_44 125109.42 root inner join, inner:TableReader_85, equal:[eq(tpch.nation.n_regionkey, tpch.region.r_regionkey)] - │ ├─HashLeftJoin_49 625547.12 root inner join, inner:TableReader_82, equal:[eq(tpch.supplier.s_nationkey, tpch.nation.n_nationkey)] + ├─HashLeftJoin_44 125109.42 root inner join, inner:TableReader_86, equal:[eq(tpch.nation.n_regionkey, tpch.region.r_regionkey)] + │ ├─HashLeftJoin_49 625547.12 root inner join, inner:TableReader_83, equal:[eq(tpch.supplier.s_nationkey, tpch.nation.n_nationkey)] │ │ ├─IndexJoin_53 625547.12 root inner join, inner:TableReader_52, outer key:tpch.partsupp.ps_suppkey, inner key:tpch.supplier.s_suppkey │ │ │ ├─IndexJoin_60 625547.12 root inner join, inner:IndexLookUp_59, outer key:tpch.part.p_partkey, inner key:tpch.partsupp.ps_partkey - │ │ │ │ ├─TableReader_76 155496.00 root data:Selection_75 - │ │ │ │ │ └─Selection_75 155496.00 cop eq(tpch.part.p_size, 30), like(tpch.part.p_type, "%STEEL", 92) - │ │ │ │ │ └─TableScan_74 10000000.00 cop table:part, range:[-inf,+inf], keep order:false + │ │ │ │ ├─TableReader_77 155496.00 root data:Selection_76 + │ │ │ │ │ └─Selection_76 155496.00 cop eq(tpch.part.p_size, 30), like(tpch.part.p_type, "%STEEL", 92) + │ │ │ │ │ └─TableScan_75 10000000.00 cop table:part, range:[-inf,+inf], keep order:false │ │ │ │ └─IndexLookUp_59 1.00 root │ │ │ │ ├─IndexScan_57 1.00 cop table:partsupp, index:PS_PARTKEY, PS_SUPPKEY, range: decided by [tpch.part.p_partkey], keep order:false │ │ │ │ └─TableScan_58 1.00 cop table:partsupp, keep order:false │ │ │ └─TableReader_52 1.00 root data:TableScan_51 │ │ │ └─TableScan_51 1.00 cop table:supplier, range: decided by [tpch.partsupp.ps_suppkey], keep order:false - │ │ └─TableReader_82 25.00 root data:TableScan_81 - │ │ └─TableScan_81 25.00 cop table:nation, range:[-inf,+inf], keep order:false - │ └─TableReader_85 1.00 root data:Selection_84 - │ └─Selection_84 1.00 cop eq(tpch.region.r_name, "ASIA") - │ └─TableScan_83 5.00 cop table:region, range:[-inf,+inf], keep order:false - └─HashAgg_88 8155010.44 root group by:tpch.partsupp.ps_partkey, funcs:min(tpch.partsupp.ps_supplycost), firstrow(tpch.partsupp.ps_partkey) - └─HashRightJoin_92 8155010.44 root inner join, inner:HashRightJoin_94, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] - ├─HashRightJoin_94 100000.00 root inner join, inner:HashRightJoin_100, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] - │ ├─HashRightJoin_100 5.00 root inner join, inner:TableReader_105, equal:[eq(tpch.region.r_regionkey, tpch.nation.n_regionkey)] - │ │ ├─TableReader_105 1.00 root data:Selection_104 - │ │ │ └─Selection_104 1.00 cop eq(tpch.region.r_name, "ASIA") - │ │ │ └─TableScan_103 5.00 cop table:region, range:[-inf,+inf], keep order:false - │ │ └─TableReader_102 25.00 root data:TableScan_101 - │ │ └─TableScan_101 25.00 cop table:nation, range:[-inf,+inf], keep order:false - │ └─TableReader_107 500000.00 root data:TableScan_106 - │ └─TableScan_106 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false - └─TableReader_109 40000000.00 root data:TableScan_108 - └─TableScan_108 40000000.00 cop table:partsupp, range:[-inf,+inf], keep order:false + │ │ └─TableReader_83 25.00 root data:TableScan_82 + │ │ └─TableScan_82 25.00 cop table:nation, range:[-inf,+inf], keep order:false + │ └─TableReader_86 1.00 root data:Selection_85 + │ └─Selection_85 1.00 cop eq(tpch.region.r_name, "ASIA") + │ └─TableScan_84 5.00 cop table:region, range:[-inf,+inf], keep order:false + └─HashAgg_89 8155010.44 root group by:tpch.partsupp.ps_partkey, funcs:min(tpch.partsupp.ps_supplycost), firstrow(tpch.partsupp.ps_partkey) + └─HashRightJoin_93 8155010.44 root inner join, inner:HashRightJoin_95, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] + ├─HashRightJoin_95 100000.00 root inner join, inner:HashRightJoin_101, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] + │ ├─HashRightJoin_101 5.00 root inner join, inner:TableReader_106, equal:[eq(tpch.region.r_regionkey, tpch.nation.n_regionkey)] + │ │ ├─TableReader_106 1.00 root data:Selection_105 + │ │ │ └─Selection_105 1.00 cop eq(tpch.region.r_name, "ASIA") + │ │ │ └─TableScan_104 5.00 cop table:region, range:[-inf,+inf], keep order:false + │ │ └─TableReader_103 25.00 root data:TableScan_102 + │ │ └─TableScan_102 25.00 cop table:nation, range:[-inf,+inf], keep order:false + │ └─TableReader_108 500000.00 root data:TableScan_107 + │ └─TableScan_107 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false + └─TableReader_110 40000000.00 root data:TableScan_109 + └─TableScan_109 40000000.00 cop table:partsupp, range:[-inf,+inf], keep order:false /* Q3 Shipping Priority Query This query retrieves the 10 unshipped orders with the highest value. @@ -252,15 +252,15 @@ id count task operator info Projection_14 10.00 root tpch.lineitem.l_orderkey, 7_col_0, tpch.orders.o_orderdate, tpch.orders.o_shippriority └─TopN_17 10.00 root 7_col_0:desc, tpch.orders.o_orderdate:asc, offset:0, count:10 └─HashAgg_20 40252367.98 root group by:col_4, col_5, col_6, funcs:sum(col_0), firstrow(col_1), firstrow(col_2), firstrow(col_3) - └─Projection_56 91515927.49 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), tpch.orders.o_orderdate, tpch.orders.o_shippriority, tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey, tpch.orders.o_orderdate, tpch.orders.o_shippriority + └─Projection_57 91515927.49 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), tpch.orders.o_orderdate, tpch.orders.o_shippriority, tpch.lineitem.l_orderkey, tpch.lineitem.l_orderkey, tpch.orders.o_orderdate, tpch.orders.o_shippriority └─IndexJoin_26 91515927.49 root inner join, inner:IndexLookUp_25, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey - ├─HashRightJoin_46 22592975.51 root inner join, inner:TableReader_52, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] - │ ├─TableReader_52 1498236.00 root data:Selection_51 - │ │ └─Selection_51 1498236.00 cop eq(tpch.customer.c_mktsegment, "AUTOMOBILE") - │ │ └─TableScan_50 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false - │ └─TableReader_49 36870000.00 root data:Selection_48 - │ └─Selection_48 36870000.00 cop lt(tpch.orders.o_orderdate, 1995-03-13 00:00:00.000000) - │ └─TableScan_47 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false + ├─HashRightJoin_47 22592975.51 root inner join, inner:TableReader_53, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] + │ ├─TableReader_53 1498236.00 root data:Selection_52 + │ │ └─Selection_52 1498236.00 cop eq(tpch.customer.c_mktsegment, "AUTOMOBILE") + │ │ └─TableScan_51 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false + │ └─TableReader_50 36870000.00 root data:Selection_49 + │ └─Selection_49 36870000.00 cop lt(tpch.orders.o_orderdate, 1995-03-13 00:00:00.000000) + │ └─TableScan_48 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false └─IndexLookUp_25 0.54 root ├─IndexScan_22 1.00 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.orders.o_orderkey], keep order:false └─Selection_24 0.54 cop gt(tpch.lineitem.l_shipdate, 1995-03-13 00:00:00.000000) @@ -299,9 +299,9 @@ Sort_10 1.00 root tpch.orders.o_orderpriority:asc └─Projection_12 1.00 root tpch.orders.o_orderpriority, 7_col_0 └─HashAgg_15 1.00 root group by:tpch.orders.o_orderpriority, funcs:count(1), firstrow(tpch.orders.o_orderpriority) └─IndexJoin_21 2340750.00 root semi join, inner:IndexLookUp_20, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey - ├─TableReader_33 2925937.50 root data:Selection_32 - │ └─Selection_32 2925937.50 cop ge(tpch.orders.o_orderdate, 1995-01-01 00:00:00.000000), lt(tpch.orders.o_orderdate, 1995-04-01) - │ └─TableScan_31 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false + ├─TableReader_34 2925937.50 root data:Selection_33 + │ └─Selection_33 2925937.50 cop ge(tpch.orders.o_orderdate, 1995-01-01 00:00:00.000000), lt(tpch.orders.o_orderdate, 1995-04-01) + │ └─TableScan_32 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false └─IndexLookUp_20 0.80 root ├─IndexScan_17 1.00 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.orders.o_orderkey], keep order:false └─Selection_19 0.80 cop lt(tpch.lineitem.l_commitdate, tpch.lineitem.l_receiptdate) @@ -448,26 +448,26 @@ Sort_22 769.96 root tpch.shipping.supp_nation:asc, tpch.shipping.cust_nation:asc └─Projection_24 769.96 root tpch.shipping.supp_nation, tpch.shipping.cust_nation, shipping.l_year, 14_col_0 └─HashAgg_27 769.96 root group by:shipping.l_year, tpch.shipping.cust_nation, tpch.shipping.supp_nation, funcs:sum(shipping.volume), firstrow(tpch.shipping.supp_nation), firstrow(tpch.shipping.cust_nation), firstrow(shipping.l_year) └─Projection_28 585255.87 root tpch.n1.n_name, tpch.n2.n_name, extract("YEAR", tpch.lineitem.l_shipdate), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)) - └─HashLeftJoin_33 585255.87 root inner join, inner:TableReader_85, equal:[eq(tpch.customer.c_nationkey, tpch.n2.n_nationkey)], other cond:or(and(eq(tpch.n1.n_name, "JAPAN"), eq(tpch.n2.n_name, "INDIA")), and(eq(tpch.n1.n_name, "INDIA"), eq(tpch.n2.n_name, "JAPAN"))) + └─HashLeftJoin_33 585255.87 root inner join, inner:TableReader_86, equal:[eq(tpch.customer.c_nationkey, tpch.n2.n_nationkey)], other cond:or(and(eq(tpch.n1.n_name, "JAPAN"), eq(tpch.n2.n_name, "INDIA")), and(eq(tpch.n1.n_name, "INDIA"), eq(tpch.n2.n_name, "JAPAN"))) ├─IndexJoin_37 7315698.42 root inner join, inner:TableReader_36, outer key:tpch.orders.o_custkey, inner key:tpch.customer.c_custkey │ ├─IndexJoin_43 7315698.42 root inner join, inner:TableReader_42, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey - │ │ ├─HashLeftJoin_64 7315698.42 root inner join, inner:TableReader_78, equal:[eq(tpch.supplier.s_nationkey, tpch.n1.n_nationkey)] - │ │ │ ├─HashLeftJoin_69 91446230.29 root inner join, inner:TableReader_75, equal:[eq(tpch.lineitem.l_suppkey, tpch.supplier.s_suppkey)] - │ │ │ │ ├─TableReader_73 91446230.29 root data:Selection_72 - │ │ │ │ │ └─Selection_72 91446230.29 cop ge(tpch.lineitem.l_shipdate, 1995-01-01 00:00:00.000000), le(tpch.lineitem.l_shipdate, 1996-12-31 00:00:00.000000) - │ │ │ │ │ └─TableScan_71 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false - │ │ │ │ └─TableReader_75 500000.00 root data:TableScan_74 - │ │ │ │ └─TableScan_74 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false - │ │ │ └─TableReader_78 2.00 root data:Selection_77 - │ │ │ └─Selection_77 2.00 cop or(eq(tpch.n1.n_name, "JAPAN"), eq(tpch.n1.n_name, "INDIA")) - │ │ │ └─TableScan_76 25.00 cop table:n1, range:[-inf,+inf], keep order:false + │ │ ├─HashLeftJoin_65 7315698.42 root inner join, inner:TableReader_79, equal:[eq(tpch.supplier.s_nationkey, tpch.n1.n_nationkey)] + │ │ │ ├─HashLeftJoin_70 91446230.29 root inner join, inner:TableReader_76, equal:[eq(tpch.lineitem.l_suppkey, tpch.supplier.s_suppkey)] + │ │ │ │ ├─TableReader_74 91446230.29 root data:Selection_73 + │ │ │ │ │ └─Selection_73 91446230.29 cop ge(tpch.lineitem.l_shipdate, 1995-01-01 00:00:00.000000), le(tpch.lineitem.l_shipdate, 1996-12-31 00:00:00.000000) + │ │ │ │ │ └─TableScan_72 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + │ │ │ │ └─TableReader_76 500000.00 root data:TableScan_75 + │ │ │ │ └─TableScan_75 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false + │ │ │ └─TableReader_79 2.00 root data:Selection_78 + │ │ │ └─Selection_78 2.00 cop or(eq(tpch.n1.n_name, "JAPAN"), eq(tpch.n1.n_name, "INDIA")) + │ │ │ └─TableScan_77 25.00 cop table:n1, range:[-inf,+inf], keep order:false │ │ └─TableReader_42 1.00 root data:TableScan_41 │ │ └─TableScan_41 1.00 cop table:orders, range: decided by [tpch.lineitem.l_orderkey], keep order:false │ └─TableReader_36 1.00 root data:TableScan_35 │ └─TableScan_35 1.00 cop table:customer, range: decided by [tpch.orders.o_custkey], keep order:false - └─TableReader_85 2.00 root data:Selection_84 - └─Selection_84 2.00 cop or(eq(tpch.n2.n_name, "INDIA"), eq(tpch.n2.n_name, "JAPAN")) - └─TableScan_83 25.00 cop table:n2, range:[-inf,+inf], keep order:false + └─TableReader_86 2.00 root data:Selection_85 + └─Selection_85 2.00 cop or(eq(tpch.n2.n_name, "INDIA"), eq(tpch.n2.n_name, "JAPAN")) + └─TableScan_84 25.00 cop table:n2, range:[-inf,+inf], keep order:false /* Q8 National Market Share Query This query determines how the market share of a given nation within a given region has changed over two years for @@ -519,35 +519,35 @@ id count task operator info Sort_28 719.02 root all_nations.o_year:asc └─Projection_30 719.02 root all_nations.o_year, div(18_col_0, 18_col_1) └─HashAgg_33 719.02 root group by:col_3, funcs:sum(col_0), sum(col_1), firstrow(col_2) - └─Projection_105 112627.20 root case(eq(tpch.all_nations.nation, "INDIA"), all_nations.volume, 0), all_nations.volume, all_nations.o_year, all_nations.o_year + └─Projection_106 112627.20 root case(eq(tpch.all_nations.nation, "INDIA"), all_nations.volume, 0), all_nations.volume, all_nations.o_year, all_nations.o_year └─Projection_34 112627.20 root extract("YEAR", tpch.orders.o_orderdate), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), tpch.n2.n_name - └─HashLeftJoin_39 112627.20 root inner join, inner:TableReader_103, equal:[eq(tpch.n1.n_regionkey, tpch.region.r_regionkey)] - ├─HashLeftJoin_44 563136.02 root inner join, inner:TableReader_100, equal:[eq(tpch.customer.c_nationkey, tpch.n1.n_nationkey)] + └─HashLeftJoin_39 112627.20 root inner join, inner:TableReader_104, equal:[eq(tpch.n1.n_regionkey, tpch.region.r_regionkey)] + ├─HashLeftJoin_44 563136.02 root inner join, inner:TableReader_101, equal:[eq(tpch.customer.c_nationkey, tpch.n1.n_nationkey)] │ ├─IndexJoin_48 563136.02 root inner join, inner:TableReader_47, outer key:tpch.orders.o_custkey, inner key:tpch.customer.c_custkey - │ │ ├─HashLeftJoin_54 563136.02 root inner join, inner:TableReader_96, equal:[eq(tpch.supplier.s_nationkey, tpch.n2.n_nationkey)] + │ │ ├─HashLeftJoin_54 563136.02 root inner join, inner:TableReader_97, equal:[eq(tpch.supplier.s_nationkey, tpch.n2.n_nationkey)] │ │ │ ├─IndexJoin_58 563136.02 root inner join, inner:TableReader_57, outer key:tpch.lineitem.l_suppkey, inner key:tpch.supplier.s_suppkey - │ │ │ │ ├─HashLeftJoin_65 563136.02 root inner join, inner:TableReader_92, equal:[eq(tpch.lineitem.l_partkey, tpch.part.p_partkey)] + │ │ │ │ ├─HashLeftJoin_65 563136.02 root inner join, inner:TableReader_93, equal:[eq(tpch.lineitem.l_partkey, tpch.part.p_partkey)] │ │ │ │ │ ├─IndexJoin_71 90788402.51 root inner join, inner:IndexLookUp_70, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey - │ │ │ │ │ │ ├─TableReader_87 22413367.93 root data:Selection_86 - │ │ │ │ │ │ │ └─Selection_86 22413367.93 cop ge(tpch.orders.o_orderdate, 1995-01-01 00:00:00.000000), le(tpch.orders.o_orderdate, 1996-12-31 00:00:00.000000) - │ │ │ │ │ │ │ └─TableScan_85 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false + │ │ │ │ │ │ ├─TableReader_88 22413367.93 root data:Selection_87 + │ │ │ │ │ │ │ └─Selection_87 22413367.93 cop ge(tpch.orders.o_orderdate, 1995-01-01 00:00:00.000000), le(tpch.orders.o_orderdate, 1996-12-31 00:00:00.000000) + │ │ │ │ │ │ │ └─TableScan_86 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false │ │ │ │ │ │ └─IndexLookUp_70 1.00 root │ │ │ │ │ │ ├─IndexScan_68 1.00 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.orders.o_orderkey], keep order:false │ │ │ │ │ │ └─TableScan_69 1.00 cop table:lineitem, keep order:false - │ │ │ │ │ └─TableReader_92 61674.00 root data:Selection_91 - │ │ │ │ │ └─Selection_91 61674.00 cop eq(tpch.part.p_type, "SMALL PLATED COPPER") - │ │ │ │ │ └─TableScan_90 10000000.00 cop table:part, range:[-inf,+inf], keep order:false + │ │ │ │ │ └─TableReader_93 61674.00 root data:Selection_92 + │ │ │ │ │ └─Selection_92 61674.00 cop eq(tpch.part.p_type, "SMALL PLATED COPPER") + │ │ │ │ │ └─TableScan_91 10000000.00 cop table:part, range:[-inf,+inf], keep order:false │ │ │ │ └─TableReader_57 1.00 root data:TableScan_56 │ │ │ │ └─TableScan_56 1.00 cop table:supplier, range: decided by [tpch.lineitem.l_suppkey], keep order:false - │ │ │ └─TableReader_96 25.00 root data:TableScan_95 - │ │ │ └─TableScan_95 25.00 cop table:n2, range:[-inf,+inf], keep order:false + │ │ │ └─TableReader_97 25.00 root data:TableScan_96 + │ │ │ └─TableScan_96 25.00 cop table:n2, range:[-inf,+inf], keep order:false │ │ └─TableReader_47 1.00 root data:TableScan_46 │ │ └─TableScan_46 1.00 cop table:customer, range: decided by [tpch.orders.o_custkey], keep order:false - │ └─TableReader_100 25.00 root data:TableScan_99 - │ └─TableScan_99 25.00 cop table:n1, range:[-inf,+inf], keep order:false - └─TableReader_103 1.00 root data:Selection_102 - └─Selection_102 1.00 cop eq(tpch.region.r_name, "ASIA") - └─TableScan_101 5.00 cop table:region, range:[-inf,+inf], keep order:false + │ └─TableReader_101 25.00 root data:TableScan_100 + │ └─TableScan_100 25.00 cop table:n1, range:[-inf,+inf], keep order:false + └─TableReader_104 1.00 root data:Selection_103 + └─Selection_103 1.00 cop eq(tpch.region.r_name, "ASIA") + └─TableScan_102 5.00 cop table:region, range:[-inf,+inf], keep order:false /* Q9 Product Type Profit Measure Query This query determines how much profit is made on a given line of parts, broken out by supplier nation and year. @@ -604,9 +604,10 @@ Sort_22 2406.00 root tpch.profit.nation:asc, profit.o_year:desc │ │ │ │ ├─TableReader_46 0.80 root data:Selection_45 │ │ │ │ │ └─Selection_45 0.80 cop like(tpch.part.p_name, "%dim%", 92) │ │ │ │ │ └─TableScan_44 1.00 cop table:part, range: decided by [tpch.lineitem.l_partkey], keep order:false - │ │ │ │ └─IndexLookUp_51 300005811.00 root - │ │ │ │ ├─IndexScan_49 300005811.00 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range:[NULL,+inf], keep order:true - │ │ │ │ └─TableScan_50 300005811.00 cop table:lineitem, keep order:false + │ │ │ │ └─Projection_52 300005811.00 root tpch.lineitem.l_orderkey, tpch.lineitem.l_partkey, tpch.lineitem.l_suppkey, tpch.lineitem.l_quantity, tpch.lineitem.l_extendedprice, tpch.lineitem.l_discount + │ │ │ │ └─IndexLookUp_51 300005811.00 root + │ │ │ │ ├─IndexScan_49 300005811.00 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range:[NULL,+inf], keep order:true + │ │ │ │ └─TableScan_50 300005811.00 cop table:lineitem, keep order:false │ │ │ └─TableReader_42 1.00 root data:TableScan_41 │ │ │ └─TableScan_41 1.00 cop table:supplier, range: decided by [tpch.lineitem.l_suppkey], keep order:false │ │ └─TableReader_39 1.00 root data:TableScan_38 @@ -614,8 +615,8 @@ Sort_22 2406.00 root tpch.profit.nation:asc, profit.o_year:desc │ └─IndexLookUp_36 1.00 root │ ├─IndexScan_34 1.00 cop table:partsupp, index:PS_PARTKEY, PS_SUPPKEY, range: decided by [tpch.lineitem.l_suppkey tpch.lineitem.l_partkey], keep order:false │ └─TableScan_35 1.00 cop table:partsupp, keep order:false - └─TableReader_53 75000000.00 root data:TableScan_52 - └─TableScan_52 75000000.00 cop table:orders, range:[-inf,+inf], keep order:true + └─TableReader_54 75000000.00 root data:TableScan_53 + └─TableScan_53 75000000.00 cop table:orders, range:[-inf,+inf], keep order:true /* Q10 Returned Item Reporting Query The query identifies customers who might be having problems with the parts that are shipped to them. @@ -663,21 +664,21 @@ id count task operator info Projection_17 20.00 root tpch.customer.c_custkey, tpch.customer.c_name, 9_col_0, tpch.customer.c_acctbal, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_comment └─TopN_20 20.00 root 9_col_0:desc, offset:0, count:20 └─HashAgg_26 7500000.00 root group by:col_10, col_11, col_12, col_13, col_14, col_8, col_9, funcs:sum(col_0), firstrow(col_1), firstrow(col_2), firstrow(col_3), firstrow(col_4), firstrow(col_5), firstrow(col_6), firstrow(col_7) - └─Projection_67 12222016.17 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_acctbal, tpch.customer.c_comment, tpch.nation.n_name, tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_acctbal, tpch.customer.c_phone, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_comment - └─HashLeftJoin_30 12222016.17 root inner join, inner:TableReader_66, equal:[eq(tpch.customer.c_nationkey, tpch.nation.n_nationkey)] + └─Projection_68 12222016.17 root mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_address, tpch.customer.c_phone, tpch.customer.c_acctbal, tpch.customer.c_comment, tpch.nation.n_name, tpch.customer.c_custkey, tpch.customer.c_name, tpch.customer.c_acctbal, tpch.customer.c_phone, tpch.nation.n_name, tpch.customer.c_address, tpch.customer.c_comment + └─HashLeftJoin_30 12222016.17 root inner join, inner:TableReader_67, equal:[eq(tpch.customer.c_nationkey, tpch.nation.n_nationkey)] ├─IndexJoin_34 12222016.17 root inner join, inner:TableReader_33, outer key:tpch.orders.o_custkey, inner key:tpch.customer.c_custkey │ ├─IndexJoin_42 12222016.17 root inner join, inner:IndexLookUp_41, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey - │ │ ├─TableReader_59 3017307.69 root data:Selection_58 - │ │ │ └─Selection_58 3017307.69 cop ge(tpch.orders.o_orderdate, 1993-08-01 00:00:00.000000), lt(tpch.orders.o_orderdate, 1993-11-01) - │ │ │ └─TableScan_57 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false + │ │ ├─TableReader_60 3017307.69 root data:Selection_59 + │ │ │ └─Selection_59 3017307.69 cop ge(tpch.orders.o_orderdate, 1993-08-01 00:00:00.000000), lt(tpch.orders.o_orderdate, 1993-11-01) + │ │ │ └─TableScan_58 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false │ │ └─IndexLookUp_41 0.25 root │ │ ├─IndexScan_38 1.00 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.orders.o_orderkey], keep order:false │ │ └─Selection_40 0.25 cop eq(tpch.lineitem.l_returnflag, "R") │ │ └─TableScan_39 1.00 cop table:lineitem, keep order:false │ └─TableReader_33 1.00 root data:TableScan_32 │ └─TableScan_32 1.00 cop table:customer, range: decided by [tpch.orders.o_custkey], keep order:false - └─TableReader_66 25.00 root data:TableScan_65 - └─TableScan_65 25.00 cop table:nation, range:[-inf,+inf], keep order:false + └─TableReader_67 25.00 root data:TableScan_66 + └─TableScan_66 25.00 cop table:nation, range:[-inf,+inf], keep order:false /* Q11 Important Stock Identification Query This query finds the most important subset of suppliers' stock in a given nation. @@ -771,11 +772,11 @@ id count task operator info Sort_9 1.00 root tpch.lineitem.l_shipmode:asc └─Projection_11 1.00 root tpch.lineitem.l_shipmode, 5_col_0, 5_col_1 └─HashAgg_14 1.00 root group by:col_3, funcs:sum(col_0), sum(col_1), firstrow(col_2) - └─Projection_39 10023369.01 root cast(case(or(eq(tpch.orders.o_orderpriority, "1-URGENT"), eq(tpch.orders.o_orderpriority, "2-HIGH")), 1, 0)), cast(case(and(ne(tpch.orders.o_orderpriority, "1-URGENT"), ne(tpch.orders.o_orderpriority, "2-HIGH")), 1, 0)), tpch.lineitem.l_shipmode, tpch.lineitem.l_shipmode + └─Projection_40 10023369.01 root cast(case(or(eq(tpch.orders.o_orderpriority, "1-URGENT"), eq(tpch.orders.o_orderpriority, "2-HIGH")), 1, 0)), cast(case(and(ne(tpch.orders.o_orderpriority, "1-URGENT"), ne(tpch.orders.o_orderpriority, "2-HIGH")), 1, 0)), tpch.lineitem.l_shipmode, tpch.lineitem.l_shipmode └─IndexJoin_18 10023369.01 root inner join, inner:TableReader_17, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey - ├─TableReader_35 10023369.01 root data:Selection_34 - │ └─Selection_34 10023369.01 cop ge(tpch.lineitem.l_receiptdate, 1997-01-01 00:00:00.000000), in(tpch.lineitem.l_shipmode, "RAIL", "FOB"), lt(tpch.lineitem.l_commitdate, tpch.lineitem.l_receiptdate), lt(tpch.lineitem.l_receiptdate, 1998-01-01), lt(tpch.lineitem.l_shipdate, tpch.lineitem.l_commitdate) - │ └─TableScan_33 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + ├─TableReader_36 10023369.01 root data:Selection_35 + │ └─Selection_35 10023369.01 cop ge(tpch.lineitem.l_receiptdate, 1997-01-01 00:00:00.000000), in(tpch.lineitem.l_shipmode, "RAIL", "FOB"), lt(tpch.lineitem.l_commitdate, tpch.lineitem.l_receiptdate), lt(tpch.lineitem.l_receiptdate, 1998-01-01), lt(tpch.lineitem.l_shipdate, tpch.lineitem.l_commitdate) + │ └─TableScan_34 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false └─TableReader_17 1.00 root data:TableScan_16 └─TableScan_16 1.00 cop table:orders, range: decided by [tpch.lineitem.l_orderkey], keep order:false /* @@ -1031,21 +1032,21 @@ id count task operator info Projection_20 100.00 root tpch.customer.c_name, tpch.customer.c_custkey, tpch.orders.o_orderkey, tpch.orders.o_orderdate, tpch.orders.o_totalprice, 13_col_0 └─TopN_23 100.00 root tpch.orders.o_totalprice:desc, tpch.orders.o_orderdate:asc, offset:0, count:100 └─HashAgg_26 60000000.00 root group by:tpch.customer.c_custkey, tpch.customer.c_name, tpch.orders.o_orderdate, tpch.orders.o_orderkey, tpch.orders.o_totalprice, funcs:sum(tpch.lineitem.l_quantity), firstrow(tpch.customer.c_custkey), firstrow(tpch.customer.c_name), firstrow(tpch.orders.o_orderkey), firstrow(tpch.orders.o_totalprice), firstrow(tpch.orders.o_orderdate) - └─HashLeftJoin_27 240004648.80 root semi join, inner:Selection_55, equal:[eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)] + └─HashLeftJoin_27 240004648.80 root semi join, inner:Selection_56, equal:[eq(tpch.orders.o_orderkey, tpch.lineitem.l_orderkey)] ├─IndexJoin_32 300005811.00 root inner join, inner:IndexLookUp_31, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey - │ ├─HashRightJoin_48 75000000.00 root inner join, inner:TableReader_52, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] - │ │ ├─TableReader_52 7500000.00 root data:TableScan_51 - │ │ │ └─TableScan_51 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false - │ │ └─TableReader_50 75000000.00 root data:TableScan_49 - │ │ └─TableScan_49 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false + │ ├─HashRightJoin_49 75000000.00 root inner join, inner:TableReader_53, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] + │ │ ├─TableReader_53 7500000.00 root data:TableScan_52 + │ │ │ └─TableScan_52 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false + │ │ └─TableReader_51 75000000.00 root data:TableScan_50 + │ │ └─TableScan_50 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false │ └─IndexLookUp_31 1.00 root │ ├─IndexScan_29 1.00 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.orders.o_orderkey], keep order:false │ └─TableScan_30 1.00 cop table:lineitem, keep order:false - └─Selection_55 59251097.60 root gt(sel_agg_2, 314) - └─HashAgg_62 74063872.00 root group by:col_2, funcs:sum(col_0), firstrow(col_1) - └─TableReader_63 74063872.00 root data:HashAgg_56 - └─HashAgg_56 74063872.00 cop group by:tpch.lineitem.l_orderkey, funcs:sum(tpch.lineitem.l_quantity), firstrow(tpch.lineitem.l_orderkey) - └─TableScan_61 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + └─Selection_56 59251097.60 root gt(sel_agg_2, 314) + └─HashAgg_63 74063872.00 root group by:col_2, funcs:sum(col_0), firstrow(col_1) + └─TableReader_64 74063872.00 root data:HashAgg_57 + └─HashAgg_57 74063872.00 cop group by:tpch.lineitem.l_orderkey, funcs:sum(tpch.lineitem.l_quantity), firstrow(tpch.lineitem.l_orderkey) + └─TableScan_62 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false /* Q19 Discounted Revenue Query The Discounted Revenue Query reports the gross discounted revenue attributed to the sale of selected parts handled @@ -1160,17 +1161,18 @@ Sort_23 16000.00 root tpch.supplier.s_name:asc └─Projection_38 6363545.60 root tpch.partsupp.ps_partkey, tpch.partsupp.ps_suppkey, tpch.partsupp.ps_availqty, mul(0.5, 13_col_0) └─Selection_39 6363545.60 root gt(cast(tpch.partsupp.ps_availqty), mul(0.5, 13_col_0)) └─HashAgg_42 7954432.00 root group by:tpch.partsupp.ps_partkey, tpch.partsupp.ps_suppkey, funcs:firstrow(tpch.partsupp.ps_partkey), firstrow(tpch.partsupp.ps_suppkey), firstrow(tpch.partsupp.ps_availqty), sum(tpch.lineitem.l_quantity) - └─HashLeftJoin_45 177770004.55 root left outer join, inner:TableReader_66, equal:[eq(tpch.partsupp.ps_partkey, tpch.lineitem.l_partkey) eq(tpch.partsupp.ps_suppkey, tpch.lineitem.l_suppkey)] + └─HashLeftJoin_45 177770004.55 root left outer join, inner:TableReader_67, equal:[eq(tpch.partsupp.ps_partkey, tpch.lineitem.l_partkey) eq(tpch.partsupp.ps_suppkey, tpch.lineitem.l_suppkey)] ├─MergeJoin_46 32000000.00 root semi join, left key:tpch.partsupp.ps_partkey, right key:tpch.part.p_partkey - │ ├─IndexLookUp_55 40000000.00 root - │ │ ├─IndexScan_53 40000000.00 cop table:partsupp, index:PS_PARTKEY, PS_SUPPKEY, range:[NULL,+inf], keep order:true - │ │ └─TableScan_54 40000000.00 cop table:partsupp, keep order:false - │ └─TableReader_58 80007.93 root data:Selection_57 - │ └─Selection_57 80007.93 cop like(tpch.part.p_name, "green%", 92) - │ └─TableScan_56 10000000.00 cop table:part, range:[-inf,+inf], keep order:true - └─TableReader_66 44189356.65 root data:Selection_65 - └─Selection_65 44189356.65 cop ge(tpch.lineitem.l_shipdate, 1993-01-01 00:00:00.000000), lt(tpch.lineitem.l_shipdate, 1994-01-01) - └─TableScan_64 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + │ ├─Projection_56 40000000.00 root tpch.partsupp.ps_partkey, tpch.partsupp.ps_suppkey, tpch.partsupp.ps_availqty + │ │ └─IndexLookUp_55 40000000.00 root + │ │ ├─IndexScan_53 40000000.00 cop table:partsupp, index:PS_PARTKEY, PS_SUPPKEY, range:[NULL,+inf], keep order:true + │ │ └─TableScan_54 40000000.00 cop table:partsupp, keep order:false + │ └─TableReader_59 80007.93 root data:Selection_58 + │ └─Selection_58 80007.93 cop like(tpch.part.p_name, "green%", 92) + │ └─TableScan_57 10000000.00 cop table:part, range:[-inf,+inf], keep order:true + └─TableReader_67 44189356.65 root data:Selection_66 + └─Selection_66 44189356.65 cop ge(tpch.lineitem.l_shipdate, 1993-01-01 00:00:00.000000), lt(tpch.lineitem.l_shipdate, 1994-01-01) + └─TableScan_65 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false /* Q21 Suppliers Who Kept Orders Waiting Query This query identifies certain suppliers who were not able to ship required parts in a timely manner. @@ -1224,25 +1226,25 @@ Projection_25 100.00 root tpch.supplier.s_name, 17_col_0 └─TopN_28 100.00 root 17_col_0:desc, tpch.supplier.s_name:asc, offset:0, count:100 └─HashAgg_31 320000.00 root group by:tpch.supplier.s_name, funcs:count(1), firstrow(tpch.supplier.s_name) └─IndexJoin_37 3786715.90 root anti semi join, inner:IndexLookUp_36, outer key:tpch.l1.l_orderkey, inner key:tpch.l3.l_orderkey, other cond:ne(tpch.l3.l_suppkey, tpch.l1.l_suppkey), ne(tpch.l3.l_suppkey, tpch.supplier.s_suppkey) - ├─IndexJoin_81 4733394.87 root semi join, inner:IndexLookUp_80, outer key:tpch.l1.l_orderkey, inner key:tpch.l2.l_orderkey, other cond:ne(tpch.l2.l_suppkey, tpch.l1.l_suppkey), ne(tpch.l2.l_suppkey, tpch.supplier.s_suppkey) - │ ├─HashLeftJoin_87 5916743.59 root inner join, inner:TableReader_116, equal:[eq(tpch.supplier.s_nationkey, tpch.nation.n_nationkey)] - │ │ ├─HashLeftJoin_92 147918589.81 root inner join, inner:TableReader_113, equal:[eq(tpch.l1.l_suppkey, tpch.supplier.s_suppkey)] - │ │ │ ├─IndexJoin_99 147918589.81 root inner join, inner:IndexLookUp_98, outer key:tpch.orders.o_orderkey, inner key:tpch.l1.l_orderkey - │ │ │ │ ├─TableReader_108 36517371.00 root data:Selection_107 - │ │ │ │ │ └─Selection_107 36517371.00 cop eq(tpch.orders.o_orderstatus, "F") - │ │ │ │ │ └─TableScan_106 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false - │ │ │ │ └─IndexLookUp_98 0.80 root - │ │ │ │ ├─IndexScan_95 1.00 cop table:l1, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.orders.o_orderkey], keep order:false - │ │ │ │ └─Selection_97 0.80 cop gt(tpch.l1.l_receiptdate, tpch.l1.l_commitdate) - │ │ │ │ └─TableScan_96 1.00 cop table:lineitem, keep order:false - │ │ │ └─TableReader_113 500000.00 root data:TableScan_112 - │ │ │ └─TableScan_112 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false - │ │ └─TableReader_116 1.00 root data:Selection_115 - │ │ └─Selection_115 1.00 cop eq(tpch.nation.n_name, "EGYPT") - │ │ └─TableScan_114 25.00 cop table:nation, range:[-inf,+inf], keep order:false - │ └─IndexLookUp_80 1.00 root - │ ├─IndexScan_78 1.00 cop table:l2, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.l1.l_orderkey], keep order:false - │ └─TableScan_79 1.00 cop table:lineitem, keep order:false + ├─IndexJoin_84 4733394.87 root semi join, inner:IndexLookUp_83, outer key:tpch.l1.l_orderkey, inner key:tpch.l2.l_orderkey, other cond:ne(tpch.l2.l_suppkey, tpch.l1.l_suppkey), ne(tpch.l2.l_suppkey, tpch.supplier.s_suppkey) + │ ├─HashLeftJoin_90 5916743.59 root inner join, inner:TableReader_119, equal:[eq(tpch.supplier.s_nationkey, tpch.nation.n_nationkey)] + │ │ ├─HashLeftJoin_95 147918589.81 root inner join, inner:TableReader_116, equal:[eq(tpch.l1.l_suppkey, tpch.supplier.s_suppkey)] + │ │ │ ├─IndexJoin_102 147918589.81 root inner join, inner:IndexLookUp_101, outer key:tpch.orders.o_orderkey, inner key:tpch.l1.l_orderkey + │ │ │ │ ├─TableReader_111 36517371.00 root data:Selection_110 + │ │ │ │ │ └─Selection_110 36517371.00 cop eq(tpch.orders.o_orderstatus, "F") + │ │ │ │ │ └─TableScan_109 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false + │ │ │ │ └─IndexLookUp_101 0.80 root + │ │ │ │ ├─IndexScan_98 1.00 cop table:l1, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.orders.o_orderkey], keep order:false + │ │ │ │ └─Selection_100 0.80 cop gt(tpch.l1.l_receiptdate, tpch.l1.l_commitdate) + │ │ │ │ └─TableScan_99 1.00 cop table:lineitem, keep order:false + │ │ │ └─TableReader_116 500000.00 root data:TableScan_115 + │ │ │ └─TableScan_115 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false + │ │ └─TableReader_119 1.00 root data:Selection_118 + │ │ └─Selection_118 1.00 cop eq(tpch.nation.n_name, "EGYPT") + │ │ └─TableScan_117 25.00 cop table:nation, range:[-inf,+inf], keep order:false + │ └─IndexLookUp_83 1.00 root + │ ├─IndexScan_81 1.00 cop table:l2, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.l1.l_orderkey], keep order:false + │ └─TableScan_82 1.00 cop table:lineitem, keep order:false └─IndexLookUp_36 0.80 root ├─IndexScan_33 1.00 cop table:l3, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.l1.l_orderkey], keep order:false └─Selection_35 0.80 cop gt(tpch.l3.l_receiptdate, tpch.l3.l_commitdate) diff --git a/planner/core/cbo_test.go b/planner/core/cbo_test.go index 64003eae89bea..5862ca1f68c15 100644 --- a/planner/core/cbo_test.go +++ b/planner/core/cbo_test.go @@ -341,7 +341,7 @@ func (s *testAnalyzeSuite) TestIndexRead(c *C) { }, { sql: "select sum(a) from t1 use index(idx) where a = 3 and b = 100000 group by a limit 1", - best: "IndexLookUp(Index(t1.idx)[[3,3]], Table(t1)->Sel([eq(test.t1.b, 100000)]))->Projection->StreamAgg->Limit", + best: "IndexLookUp(Index(t1.idx)[[3,3]], Table(t1)->Sel([eq(test.t1.b, 100000)]))->Projection->Projection->StreamAgg->Limit", }, } for _, tt := range tests { diff --git a/planner/core/find_best_task.go b/planner/core/find_best_task.go index f1397ee36233c..a24e8c0d9a672 100644 --- a/planner/core/find_best_task.go +++ b/planner/core/find_best_task.go @@ -523,6 +523,7 @@ func (ds *DataSource) convertToIndexScan(prop *property.PhysicalProperty, candid } if cop.tablePlan != nil { cop.tablePlan.(*PhysicalTableScan).appendExtraHandleCol(ds) + cop.doubleReadNeedProj = true } cop.keepOrder = true is.KeepOrder = true diff --git a/planner/core/physical_plan_test.go b/planner/core/physical_plan_test.go index 3e69977e21754..c7f94e5d2f9e3 100644 --- a/planner/core/physical_plan_test.go +++ b/planner/core/physical_plan_test.go @@ -848,7 +848,7 @@ func (s *testPlanSuite) TestDAGPlanBuilderAgg(c *C) { // Test stream agg + index double. { sql: "select sum(e), avg(b + c) from t where c = 1 and b = 1 group by c", - best: "IndexLookUp(Index(t.c_d_e)[[1,1]], Table(t)->Sel([eq(test.t.b, 1)]))->Projection->StreamAgg", + best: "IndexLookUp(Index(t.c_d_e)[[1,1]], Table(t)->Sel([eq(test.t.b, 1)]))->Projection->Projection->StreamAgg", }, // Test hash agg + order. { @@ -858,7 +858,7 @@ func (s *testPlanSuite) TestDAGPlanBuilderAgg(c *C) { // Test stream agg + order. { sql: "select sum(e) as k, avg(b + c) from t where c = 1 and b = 1 and e = 1 group by c order by k", - best: "IndexLookUp(Index(t.c_d_e)[[1,1]]->Sel([eq(test.t.e, 1)]), Table(t)->Sel([eq(test.t.b, 1)]))->Projection->StreamAgg->Sort", + best: "IndexLookUp(Index(t.c_d_e)[[1,1]]->Sel([eq(test.t.e, 1)]), Table(t)->Sel([eq(test.t.b, 1)]))->Projection->Projection->StreamAgg->Sort", }, // Test agg can't push down. { diff --git a/planner/core/rule_column_pruning.go b/planner/core/rule_column_pruning.go index b7e6a72a4e64a..42528440d4965 100644 --- a/planner/core/rule_column_pruning.go +++ b/planner/core/rule_column_pruning.go @@ -73,6 +73,12 @@ func (p *LogicalProjection) PruneColumns(parentUsedCols []*expression.Column) { p.Exprs = append(p.Exprs[:i], p.Exprs[i+1:]...) } } + // Prune TblID2Handle since that handle column may be pruned. + for k, cols := range p.schema.TblID2Handle { + if p.schema.ColumnIndex(cols[0]) == -1 { + delete(p.schema.TblID2Handle, k) + } + } selfUsedCols := make([]*expression.Column, 0, len(p.Exprs)) selfUsedCols = expression.ExtractColumnsFromExpressions(selfUsedCols, p.Exprs, nil) child.PruneColumns(selfUsedCols) diff --git a/planner/core/task.go b/planner/core/task.go index 17f2568c465cb..1bbbff3cfd145 100644 --- a/planner/core/task.go +++ b/planner/core/task.go @@ -47,6 +47,9 @@ type copTask struct { indexPlanFinished bool // keepOrder indicates if the plan scans data by order. keepOrder bool + // In double read case, it may output one more column for handle(row id). + // We need to prune it, so we add a project do this. + doubleReadNeedProj bool } func (t *copTask) invalid() bool { @@ -210,7 +213,15 @@ func finishCopTask(ctx sessionctx.Context, task task) task { if t.indexPlan != nil && t.tablePlan != nil { p := PhysicalIndexLookUpReader{tablePlan: t.tablePlan, indexPlan: t.indexPlan}.init(ctx) p.stats = t.tablePlan.statsInfo() - newTask.p = p + if t.doubleReadNeedProj { + schema := p.IndexPlans[0].(*PhysicalIndexScan).dataSourceSchema + proj := PhysicalProjection{Exprs: expression.Column2Exprs(schema.Columns)}.init(ctx, p.stats, nil) + proj.SetSchema(schema) + proj.SetChildren(p) + newTask.p = proj + } else { + newTask.p = p + } } else if t.indexPlan != nil { p := PhysicalIndexReader{indexPlan: t.indexPlan}.init(ctx) p.stats = t.indexPlan.statsInfo()