From cc202d05952f697a3307730c09bcbb2c36827ab2 Mon Sep 17 00:00:00 2001 From: xuhuaiyu <391585975@qq.com> Date: Mon, 23 Sep 2019 14:46:37 +0800 Subject: [PATCH 1/7] *: introduce an individual physical plan for IndexHashJoin --- cmd/explaintest/r/explain_complex.result | 38 +- .../r/explain_complex_stats.result | 28 +- cmd/explaintest/r/explain_easy.result | 118 ++-- cmd/explaintest/r/explain_easy_stats.result | 40 +- cmd/explaintest/r/generated_columns.result | 30 +- cmd/explaintest/r/index_join.result | 48 +- cmd/explaintest/r/subquery.result | 10 +- cmd/explaintest/r/topn_push_down.result | 70 +-- cmd/explaintest/r/tpch.result | 502 +++++++++--------- executor/builder.go | 25 +- executor/joiner.go | 53 ++ planner/core/exhaust_physical_plans.go | 35 +- planner/core/initialize.go | 13 +- planner/core/physical_plans.go | 11 +- planner/core/stringer.go | 12 + planner/core/task.go | 66 +++ planner/core/testdata/analyze_suite_out.json | 14 +- planner/core/testdata/plan_suite_out.json | 52 +- util/ranger/testdata/ranger_suite_out.json | 10 +- 19 files changed, 679 insertions(+), 496 deletions(-) diff --git a/cmd/explaintest/r/explain_complex.result b/cmd/explaintest/r/explain_complex.result index 1e3f938afd012..5be5f623f3cd5 100644 --- a/cmd/explaintest/r/explain_complex.result +++ b/cmd/explaintest/r/explain_complex.result @@ -123,19 +123,19 @@ Projection_13 1.00 root Column#1, Column#20, Column#3, Column#4, Column#23, Colu │ ├─IndexScan_25 0.00 cop table:dd, index:aid, dic, range: decided by [eq(Column#21, Column#3)], keep order:true, stats:pseudo │ └─Selection_27 0.00 cop eq(Column#22, "android"), eq(Column#28, 0), gt(Column#27, 1478143908), not(isnull(Column#26)), not(isnull(Column#27)) │ └─TableScan_26 0.00 cop table:dd, keep order:false, stats:pseudo - └─IndexLookUp_39 3.33 root - ├─IndexScan_36 3333.33 cop table:gad, index:t, range:(1478143908,+inf], keep order:false, stats:pseudo - └─Selection_38 3.33 cop eq(Column#2, "android"), not(isnull(Column#5)) - └─TableScan_37 3333.33 cop table:gad, keep order:false, stats:pseudo + └─IndexLookUp_41 3.33 root + ├─IndexScan_38 3333.33 cop table:gad, index:t, range:(1478143908,+inf], keep order:false, stats:pseudo + └─Selection_40 3.33 cop eq(Column#2, "android"), not(isnull(Column#5)) + └─TableScan_39 3333.33 cop table:gad, keep order:false, stats:pseudo explain select gad.id as gid,sdk.id as sid,gad.aid as aid,gad.cm as cm,sdk.dic as dic,sdk.ip as ip, sdk.t as t, gad.p1 as p1, gad.p2 as p2, gad.p3 as p3, gad.p4 as p4, gad.p5 as p5, gad.p6_md5 as p6, gad.p7_md5 as p7, gad.ext as ext from st gad join dd sdk on gad.aid = sdk.aid and gad.dic = sdk.mac and gad.t < sdk.t where gad.t > 1477971479 and gad.bm = 0 and gad.pt = 'ios' and gad.dit = 'mac' and sdk.t > 1477971479 and sdk.bm = 0 and sdk.pt = 'ios' limit 3000; id count task operator info Projection_10 0.00 root Column#1, Column#20, Column#3, Column#4, Column#23, Column#26, Column#27, Column#8, Column#9, Column#10, Column#11, Column#12, Column#13, Column#14, Column#15 └─Limit_13 0.00 root offset:0, count:3000 └─IndexMergeJoin_24 0.00 root inner join, inner:IndexLookUp_22, outer key:Column#3, inner key:Column#21, other cond:eq(Column#6, Column#25), lt(Column#19, Column#27) - ├─IndexLookUp_33 0.00 root - │ ├─IndexScan_30 3333.33 cop table:gad, index:t, range:(1477971479,+inf], keep order:false, stats:pseudo - │ └─Selection_32 0.00 cop eq(Column#16, 0), eq(Column#2, "ios"), eq(Column#7, "mac"), not(isnull(Column#6)) - │ └─TableScan_31 3333.33 cop table:gad, keep order:false, stats:pseudo + ├─IndexLookUp_35 0.00 root + │ ├─IndexScan_32 3333.33 cop table:gad, index:t, range:(1477971479,+inf], keep order:false, stats:pseudo + │ └─Selection_34 0.00 cop eq(Column#16, 0), eq(Column#2, "ios"), eq(Column#7, "mac"), not(isnull(Column#6)) + │ └─TableScan_33 3333.33 cop table:gad, keep order:false, stats:pseudo └─IndexLookUp_22 0.00 root ├─IndexScan_19 0.00 cop table:sdk, index:aid, dic, range: decided by [eq(Column#21, Column#3)], keep order:true, stats:pseudo └─Selection_21 0.00 cop eq(Column#22, "ios"), eq(Column#28, 0), gt(Column#27, 1477971479), not(isnull(Column#25)), not(isnull(Column#27)) @@ -153,9 +153,9 @@ id count task operator info Projection_10 0.00 root Column#1, Column#2, Column#4, Column#5, Column#3, Column#24, Column#25, Column#26, Column#11, Column#12, Column#13, Column#14, Column#15, Column#16, Column#17 └─Limit_13 0.00 root offset:0, count:2000 └─IndexMergeJoin_25 0.00 root inner join, inner:IndexLookUp_23, outer key:Column#2, Column#5, inner key:Column#21, Column#23 - ├─TableReader_40 0.00 root data:Selection_39 - │ └─Selection_39 0.00 cop eq(Column#18, 0), eq(Column#4, "ios"), gt(Column#9, 1478185592), not(isnull(Column#5)) - │ └─TableScan_38 10000.00 cop table:dt, range:[0,+inf], keep order:false, stats:pseudo + ├─TableReader_42 0.00 root data:Selection_41 + │ └─Selection_41 0.00 cop eq(Column#18, 0), eq(Column#4, "ios"), gt(Column#9, 1478185592), not(isnull(Column#5)) + │ └─TableScan_40 10000.00 cop table:dt, range:[0,+inf], keep order:false, stats:pseudo └─IndexLookUp_23 0.00 root ├─IndexScan_20 1.25 cop table:rr, index:aid, dic, range: decided by [eq(Column#21, Column#2) eq(Column#23, Column#5)], keep order:true, stats:pseudo └─Selection_22 0.00 cop eq(Column#22, "ios"), gt(Column#26, 1478185592) @@ -245,17 +245,17 @@ id count task operator info Sort_10 1.00 root Column#31:asc └─HashAgg_15 1.00 root group by:Column#1, funcs:firstrow(Column#1), firstrow(Column#2), firstrow(Column#3), firstrow(Column#4), firstrow(Column#5), firstrow(Column#6), firstrow(Column#7), firstrow(Column#8), firstrow(Column#9), firstrow(Column#10) └─Selection_22 0.01 root or(eq(Column#22, 62), or(eq(Column#1, 20), eq(Column#1, 20))) - └─HashLeftJoin_23 0.02 root left outer join, inner:TableReader_68, equal:[eq(Column#11, Column#23)] + └─HashLeftJoin_23 0.02 root left outer join, inner:TableReader_70, equal:[eq(Column#11, Column#23)] ├─IndexMergeJoin_39 0.01 root left outer join, inner:IndexLookUp_37, outer key:Column#1, inner key:Column#17 - │ ├─IndexLookUp_58 0.01 root - │ │ ├─IndexScan_55 10.00 cop table:d, index:ctx, range:[1,1], keep order:false, stats:pseudo - │ │ └─Selection_57 0.01 cop eq(Column#8, 1000) - │ │ └─TableScan_56 10.00 cop table:d, keep order:false, stats:pseudo + │ ├─IndexLookUp_60 0.01 root + │ │ ├─IndexScan_57 10.00 cop table:d, index:ctx, range:[1,1], keep order:false, stats:pseudo + │ │ └─Selection_59 0.01 cop eq(Column#8, 1000) + │ │ └─TableScan_58 10.00 cop table:d, keep order:false, stats:pseudo │ └─IndexLookUp_37 0.00 root │ ├─Selection_35 1.25 cop not(isnull(Column#17)) │ │ └─IndexScan_33 1.25 cop table:p, index:department_id, range: decided by [eq(Column#17, Column#1)], keep order:true, stats:pseudo │ └─Selection_36 0.00 cop eq(Column#18, 1000) │ └─TableScan_34 1.25 cop table:p, keep order:false, stats:pseudo - └─TableReader_68 9.99 root data:Selection_67 - └─Selection_67 9.99 cop eq(Column#24, 1000), not(isnull(Column#23)) - └─TableScan_66 10000.00 cop table:ep, range:[-inf,+inf], keep order:false, stats:pseudo + └─TableReader_70 9.99 root data:Selection_69 + └─Selection_69 9.99 cop eq(Column#24, 1000), not(isnull(Column#23)) + └─TableScan_68 10000.00 cop table:ep, range:[-inf,+inf], keep order:false, stats:pseudo diff --git a/cmd/explaintest/r/explain_complex_stats.result b/cmd/explaintest/r/explain_complex_stats.result index a2fc0af9e74d9..12bea9e5ebf8d 100644 --- a/cmd/explaintest/r/explain_complex_stats.result +++ b/cmd/explaintest/r/explain_complex_stats.result @@ -129,9 +129,9 @@ Projection_13 424.00 root Column#1, Column#20, Column#3, Column#4, Column#23, Co └─Limit_16 424.00 root offset:0, count:2500 └─HashAgg_19 424.00 root group by:Column#23, Column#3, funcs:firstrow(Column#1), firstrow(Column#3), firstrow(Column#4), firstrow(Column#8), firstrow(Column#9), firstrow(Column#10), firstrow(Column#11), firstrow(Column#12), firstrow(Column#13), firstrow(Column#14), firstrow(Column#15), firstrow(Column#19), firstrow(Column#20), firstrow(Column#23), firstrow(Column#26), firstrow(Column#27) └─IndexMergeJoin_30 424.00 root inner join, inner:IndexLookUp_28, outer key:Column#3, inner key:Column#21, other cond:eq(Column#5, Column#26), gt(Column#27, Column#19) - ├─TableReader_35 424.00 root data:Selection_34 - │ └─Selection_34 424.00 cop eq(Column#16, 0), eq(Column#2, "android"), gt(Column#19, 1478143908), not(isnull(Column#5)) - │ └─TableScan_33 1999.00 cop table:gad, range:[0,+inf], keep order:false + ├─TableReader_37 424.00 root data:Selection_36 + │ └─Selection_36 424.00 cop eq(Column#16, 0), eq(Column#2, "android"), gt(Column#19, 1478143908), not(isnull(Column#5)) + │ └─TableScan_35 1999.00 cop table:gad, range:[0,+inf], keep order:false └─IndexLookUp_28 0.23 root ├─IndexScan_25 1.00 cop table:dd, index:aid, dic, range: decided by [eq(Column#21, Column#3)], keep order:true └─Selection_27 0.23 cop eq(Column#22, "android"), eq(Column#28, 0), gt(Column#27, 1478143908), not(isnull(Column#26)), not(isnull(Column#27)) @@ -141,9 +141,9 @@ id count task operator info Projection_10 170.34 root Column#1, Column#20, Column#3, Column#4, Column#23, Column#26, Column#27, Column#8, Column#9, Column#10, Column#11, Column#12, Column#13, Column#14, Column#15 └─Limit_13 170.34 root offset:0, count:3000 └─IndexMergeJoin_24 170.34 root inner join, inner:IndexLookUp_22, outer key:Column#3, inner key:Column#21, other cond:eq(Column#6, Column#25), lt(Column#19, Column#27) - ├─TableReader_29 170.34 root data:Selection_28 - │ └─Selection_28 170.34 cop eq(Column#16, 0), eq(Column#2, "ios"), eq(Column#7, "mac"), gt(Column#19, 1477971479), not(isnull(Column#6)) - │ └─TableScan_27 1999.00 cop table:gad, range:[0,+inf], keep order:false + ├─TableReader_31 170.34 root data:Selection_30 + │ └─Selection_30 170.34 cop eq(Column#16, 0), eq(Column#2, "ios"), eq(Column#7, "mac"), gt(Column#19, 1477971479), not(isnull(Column#6)) + │ └─TableScan_29 1999.00 cop table:gad, range:[0,+inf], keep order:false └─IndexLookUp_22 0.25 root ├─IndexScan_19 1.00 cop table:sdk, index:aid, dic, range: decided by [eq(Column#21, Column#3)], keep order:true └─Selection_21 0.25 cop eq(Column#22, "ios"), eq(Column#28, 0), gt(Column#27, 1477971479), not(isnull(Column#25)), not(isnull(Column#27)) @@ -160,14 +160,14 @@ explain select dt.id as id, dt.aid as aid, dt.pt as pt, dt.dic as dic, dt.cm as id count task operator info Projection_10 428.32 root Column#1, Column#2, Column#4, Column#5, Column#3, Column#24, Column#25, Column#26, Column#11, Column#12, Column#13, Column#14, Column#15, Column#16, Column#17 └─Limit_13 428.32 root offset:0, count:2000 - └─IndexMergeJoin_25 428.32 root inner join, inner:IndexLookUp_23, outer key:Column#2, Column#5, inner key:Column#21, Column#23 - ├─TableReader_40 428.32 root data:Selection_39 - │ └─Selection_39 428.32 cop eq(Column#18, 0), eq(Column#4, "ios"), gt(Column#9, 1478185592), not(isnull(Column#5)) - │ └─TableScan_38 2000.00 cop table:dt, range:[0,+inf], keep order:false - └─IndexLookUp_23 0.48 root - ├─IndexScan_20 1.00 cop table:rr, index:aid, dic, range: decided by [eq(Column#21, Column#2) eq(Column#23, Column#5)], keep order:true - └─Selection_22 0.48 cop eq(Column#22, "ios"), gt(Column#26, 1478185592) - └─TableScan_21 1.00 cop table:rr, keep order:false + └─IndexHashJoin_27 428.32 root inner join, inner:IndexLookUp_18, outer key:Column#2, Column#5, inner key:Column#21, Column#23 + ├─TableReader_42 428.32 root data:Selection_41 + │ └─Selection_41 428.32 cop eq(Column#18, 0), eq(Column#4, "ios"), gt(Column#9, 1478185592), not(isnull(Column#5)) + │ └─TableScan_40 2000.00 cop table:dt, range:[0,+inf], keep order:false + └─IndexLookUp_18 0.48 root + ├─IndexScan_15 1.00 cop table:rr, index:aid, dic, range: decided by [eq(Column#21, Column#2) eq(Column#23, Column#5)], keep order:false + └─Selection_17 0.48 cop eq(Column#22, "ios"), gt(Column#26, 1478185592) + └─TableScan_16 1.00 cop table:rr, keep order:false explain select pc,cr,count(DISTINCT uid) as pay_users,count(oid) as pay_times,sum(am) as am from pp where ps=2 and ppt>=1478188800 and ppt<1478275200 and pi in ('510017','520017') and uid in ('18089709','18090780') group by pc,cr; id count task operator info Projection_5 207.86 root Column#14, Column#16, Column#22, Column#23, Column#24 diff --git a/cmd/explaintest/r/explain_easy.result b/cmd/explaintest/r/explain_easy.result index 2af4294677c07..8c0105faa1b2f 100644 --- a/cmd/explaintest/r/explain_easy.result +++ b/cmd/explaintest/r/explain_easy.result @@ -44,12 +44,12 @@ IndexReader_6 10.00 root index:IndexScan_5 └─IndexScan_5 10.00 cop table:t1, index:c2, range:[1,1], keep order:false, stats:pseudo explain select * from t1 left join t2 on t1.c2 = t2.c1 where t1.c1 > 1; id count task operator info -HashLeftJoin_19 4166.67 root left outer join, inner:TableReader_32, equal:[eq(Column#2, Column#4)] -├─TableReader_29 3333.33 root data:TableScan_28 -│ └─TableScan_28 3333.33 cop table:t1, range:(1,+inf], keep order:false, stats:pseudo -└─TableReader_32 9990.00 root data:Selection_31 - └─Selection_31 9990.00 cop not(isnull(Column#4)) - └─TableScan_30 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo +HashLeftJoin_21 4166.67 root left outer join, inner:TableReader_34, equal:[eq(Column#2, Column#4)] +├─TableReader_31 3333.33 root data:TableScan_30 +│ └─TableScan_30 3333.33 cop table:t1, range:(1,+inf], keep order:false, stats:pseudo +└─TableReader_34 9990.00 root data:Selection_33 + └─Selection_33 9990.00 cop not(isnull(Column#4)) + └─TableScan_32 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo explain update t1 set t1.c2 = 2 where t1.c1 = 1; id count task operator info Update_2 N/A root N/A @@ -63,14 +63,14 @@ Delete_3 N/A root N/A explain select count(b.c2) from t1 a, t2 b where a.c1 = b.c2 group by a.c1; id count task operator info Projection_11 9990.00 root cast(Column#9) -└─HashLeftJoin_19 9990.00 root inner join, inner:HashAgg_26, equal:[eq(Column#1, Column#5)] - ├─IndexReader_34 10000.00 root index:IndexScan_33 - │ └─IndexScan_33 10000.00 cop table:a, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo - └─HashAgg_26 7992.00 root group by:Column#12, funcs:count(Column#10), firstrow(Column#12) - └─TableReader_27 7992.00 root data:HashAgg_21 - └─HashAgg_21 7992.00 cop group by:Column#5, funcs:count(Column#5) - └─Selection_25 9990.00 cop not(isnull(Column#5)) - └─TableScan_24 10000.00 cop table:b, range:[-inf,+inf], keep order:false, stats:pseudo +└─HashLeftJoin_21 9990.00 root inner join, inner:HashAgg_28, equal:[eq(Column#1, Column#5)] + ├─IndexReader_36 10000.00 root index:IndexScan_35 + │ └─IndexScan_35 10000.00 cop table:a, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo + └─HashAgg_28 7992.00 root group by:Column#12, funcs:count(Column#10), firstrow(Column#12) + └─TableReader_29 7992.00 root data:HashAgg_23 + └─HashAgg_23 7992.00 cop group by:Column#5, funcs:count(Column#5) + └─Selection_27 9990.00 cop not(isnull(Column#5)) + └─TableScan_26 10000.00 cop table:b, range:[-inf,+inf], keep order:false, stats:pseudo explain select * from t2 order by t2.c2 limit 0, 1; id count task operator info TopN_7 1.00 root Column#2:asc, offset:0, count:1 @@ -100,13 +100,13 @@ StreamAgg_12 1.00 root funcs:sum(Column#0) explain select c1 from t1 where c1 in (select c2 from t2); id count task operator info Projection_9 9990.00 root Column#1 -└─HashLeftJoin_17 9990.00 root inner join, inner:HashAgg_21, equal:[eq(Column#1, Column#5)] - ├─IndexReader_32 10000.00 root index:IndexScan_31 - │ └─IndexScan_31 10000.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo - └─HashAgg_21 7992.00 root group by:Column#5, funcs:firstrow(Column#5) - └─TableReader_28 9990.00 root data:Selection_27 - └─Selection_27 9990.00 cop not(isnull(Column#5)) - └─TableScan_26 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo +└─HashLeftJoin_19 9990.00 root inner join, inner:HashAgg_23, equal:[eq(Column#1, Column#5)] + ├─IndexReader_34 10000.00 root index:IndexScan_33 + │ └─IndexScan_33 10000.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:false, stats:pseudo + └─HashAgg_23 7992.00 root group by:Column#5, funcs:firstrow(Column#5) + └─TableReader_30 9990.00 root data:Selection_29 + └─Selection_29 9990.00 cop not(isnull(Column#5)) + └─TableScan_28 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo explain select (select count(1) k from t1 s where s.c1 = t1.c1 having k != 0) from t1; id count task operator info Projection_12 10000.00 root ifnull(Column#7, 0) @@ -311,11 +311,11 @@ Projection_11 10000.00 root Column#12 ├─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo └─StreamAgg_20 1.00 root funcs:count(1) - └─MergeJoin_50 12.50 root inner join, left key:Column#4, right key:Column#7 - ├─TableReader_43 1.00 root data:TableScan_42 - │ └─TableScan_42 1.00 cop table:s, range: decided by [eq(Column#4, Column#1)], keep order:true, stats:pseudo - └─TableReader_45 1.00 root data:TableScan_44 - └─TableScan_44 1.00 cop table:t1, range: decided by [eq(Column#7, Column#1)], keep order:true, stats:pseudo + └─MergeJoin_54 12.50 root inner join, left key:Column#4, right key:Column#7 + ├─TableReader_47 1.00 root data:TableScan_46 + │ └─TableScan_46 1.00 cop table:s, range: decided by [eq(Column#4, Column#1)], keep order:true, stats:pseudo + └─TableReader_49 1.00 root data:TableScan_48 + └─TableScan_48 1.00 cop table:t1, range: decided by [eq(Column#7, Column#1)], keep order:true, stats:pseudo explain select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.a = t1.a) from t; id count task operator info Projection_11 10000.00 root Column#12 @@ -323,11 +323,11 @@ Projection_11 10000.00 root Column#12 ├─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo └─StreamAgg_20 1.00 root funcs:count(1) - └─IndexMergeJoin_42 12.50 root inner join, inner:TableReader_40, outer key:Column#4, inner key:Column#7 - ├─IndexReader_31 10.00 root index:IndexScan_30 - │ └─IndexScan_30 10.00 cop table:s, index:b, range: decided by [eq(Column#5, Column#1)], keep order:false, stats:pseudo - └─TableReader_40 1.00 root data:TableScan_39 - └─TableScan_39 1.00 cop table:t1, range: decided by [Column#4], keep order:true, stats:pseudo + └─IndexHashJoin_46 12.50 root inner join, inner:TableReader_39, outer key:Column#4, inner key:Column#7 + ├─IndexReader_33 10.00 root index:IndexScan_32 + │ └─IndexScan_32 10.00 cop table:s, index:b, range: decided by [eq(Column#5, Column#1)], keep order:false, stats:pseudo + └─TableReader_39 1.00 root data:TableScan_38 + └─TableScan_38 1.00 cop table:t1, range: decided by [Column#4], keep order:false, stats:pseudo explain select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.c = t1.a) from t; id count task operator info Projection_11 10000.00 root Column#12 @@ -335,13 +335,13 @@ Projection_11 10000.00 root Column#12 ├─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo └─StreamAgg_20 1.00 root funcs:count(1) - └─IndexMergeJoin_44 12.49 root inner join, inner:TableReader_42, outer key:Column#6, inner key:Column#7 - ├─IndexLookUp_33 9.99 root - │ ├─IndexScan_30 10.00 cop table:s, index:b, range: decided by [eq(Column#5, Column#1)], keep order:false, stats:pseudo - │ └─Selection_32 9.99 cop not(isnull(Column#6)) - │ └─TableScan_31 10.00 cop table:s, keep order:false, stats:pseudo - └─TableReader_42 1.00 root data:TableScan_41 - └─TableScan_41 1.00 cop table:t1, range: decided by [Column#6], keep order:true, stats:pseudo + └─IndexHashJoin_48 12.49 root inner join, inner:TableReader_41, outer key:Column#6, inner key:Column#7 + ├─IndexLookUp_35 9.99 root + │ ├─IndexScan_32 10.00 cop table:s, index:b, range: decided by [eq(Column#5, Column#1)], keep order:false, stats:pseudo + │ └─Selection_34 9.99 cop not(isnull(Column#6)) + │ └─TableScan_33 10.00 cop table:s, keep order:false, stats:pseudo + └─TableReader_41 1.00 root data:TableScan_40 + └─TableScan_40 1.00 cop table:t1, range: decided by [Column#6], keep order:false, stats:pseudo insert into t values(1, 1, 1), (2, 2 ,2), (3, 3, 3), (4, 3, 4),(5,3,5); analyze table t; explain select t.c in (select count(*) from t s, t t1 where s.b = t.a and s.b = 3 and s.a = t1.a) from t; @@ -351,13 +351,13 @@ Projection_11 5.00 root Column#12 ├─TableReader_15 5.00 root data:TableScan_14 │ └─TableScan_14 5.00 cop table:t, range:[-inf,+inf], keep order:false └─StreamAgg_20 1.00 root funcs:count(1) - └─MergeJoin_49 2.40 root inner join, left key:Column#4, right key:Column#7 - ├─IndexReader_36 2.40 root index:Selection_35 - │ └─Selection_35 2.40 cop eq(3, Column#1) - │ └─IndexScan_34 3.00 cop table:s, index:b, range:[3,3], keep order:true - └─TableReader_39 4.00 root data:Selection_38 - └─Selection_38 4.00 cop eq(3, Column#1) - └─TableScan_37 5.00 cop table:t1, range:[-inf,+inf], keep order:true + └─MergeJoin_51 2.40 root inner join, left key:Column#4, right key:Column#7 + ├─IndexReader_38 2.40 root index:Selection_37 + │ └─Selection_37 2.40 cop eq(3, Column#1) + │ └─IndexScan_36 3.00 cop table:s, index:b, range:[3,3], keep order:true + └─TableReader_41 4.00 root data:Selection_40 + └─Selection_40 4.00 cop eq(3, Column#1) + └─TableScan_39 5.00 cop table:t1, range:[-inf,+inf], keep order:true explain select t.c in (select count(*) from t s left join t t1 on s.a = t1.a where 3 = t.a and s.b = 3) from t; id count task operator info Projection_10 5.00 root Column#12 @@ -365,13 +365,13 @@ Projection_10 5.00 root Column#12 ├─TableReader_14 5.00 root data:TableScan_13 │ └─TableScan_13 5.00 cop table:t, range:[-inf,+inf], keep order:false └─StreamAgg_19 1.00 root funcs:count(1) - └─MergeJoin_47 2.40 root left outer join, left key:Column#4, right key:Column#7 - ├─IndexReader_34 2.40 root index:Selection_33 - │ └─Selection_33 2.40 cop eq(3, Column#1) - │ └─IndexScan_32 3.00 cop table:s, index:b, range:[3,3], keep order:true - └─TableReader_37 4.00 root data:Selection_36 - └─Selection_36 4.00 cop eq(3, Column#1) - └─TableScan_35 5.00 cop table:t1, range:[-inf,+inf], keep order:true + └─MergeJoin_49 2.40 root left outer join, left key:Column#4, right key:Column#7 + ├─IndexReader_36 2.40 root index:Selection_35 + │ └─Selection_35 2.40 cop eq(3, Column#1) + │ └─IndexScan_34 3.00 cop table:s, index:b, range:[3,3], keep order:true + └─TableReader_39 4.00 root data:Selection_38 + └─Selection_38 4.00 cop eq(3, Column#1) + └─TableScan_37 5.00 cop table:t1, range:[-inf,+inf], keep order:true explain select t.c in (select count(*) from t s right join t t1 on s.a = t1.a where 3 = t.a and t1.b = 3) from t; id count task operator info Projection_10 5.00 root Column#12 @@ -379,13 +379,13 @@ Projection_10 5.00 root Column#12 ├─TableReader_14 5.00 root data:TableScan_13 │ └─TableScan_13 5.00 cop table:t, range:[-inf,+inf], keep order:false └─StreamAgg_19 1.00 root funcs:count(1) - └─MergeJoin_46 2.40 root right outer join, left key:Column#4, right key:Column#7 - ├─TableReader_33 4.00 root data:Selection_32 - │ └─Selection_32 4.00 cop eq(3, Column#1) - │ └─TableScan_31 5.00 cop table:s, range:[-inf,+inf], keep order:true - └─IndexReader_36 2.40 root index:Selection_35 - └─Selection_35 2.40 cop eq(3, Column#1) - └─IndexScan_34 3.00 cop table:t1, index:b, range:[3,3], keep order:true + └─MergeJoin_48 2.40 root right outer join, left key:Column#4, right key:Column#7 + ├─TableReader_35 4.00 root data:Selection_34 + │ └─Selection_34 4.00 cop eq(3, Column#1) + │ └─TableScan_33 5.00 cop table:s, range:[-inf,+inf], keep order:true + └─IndexReader_38 2.40 root index:Selection_37 + └─Selection_37 2.40 cop eq(3, Column#1) + └─IndexScan_36 3.00 cop table:t1, index:b, range:[3,3], keep order:true drop table if exists t; create table t(a int unsigned); explain select t.a = '123455' from t; diff --git a/cmd/explaintest/r/explain_easy_stats.result b/cmd/explaintest/r/explain_easy_stats.result index cbe0782d75aeb..fcff061da28bf 100644 --- a/cmd/explaintest/r/explain_easy_stats.result +++ b/cmd/explaintest/r/explain_easy_stats.result @@ -47,12 +47,12 @@ 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 -HashLeftJoin_19 2481.25 root left outer join, inner:TableReader_32, equal:[eq(Column#2, Column#4)] -├─TableReader_29 1998.00 root data:TableScan_28 -│ └─TableScan_28 1998.00 cop table:t1, range:(1,+inf], keep order:false -└─TableReader_32 1985.00 root data:Selection_31 - └─Selection_31 1985.00 cop not(isnull(Column#4)) - └─TableScan_30 1985.00 cop table:t2, range:[-inf,+inf], keep order:false +HashLeftJoin_21 2481.25 root left outer join, inner:TableReader_34, equal:[eq(Column#2, Column#4)] +├─TableReader_31 1998.00 root data:TableScan_30 +│ └─TableScan_30 1998.00 cop table:t1, range:(1,+inf], keep order:false +└─TableReader_34 1985.00 root data:Selection_33 + └─Selection_33 1985.00 cop not(isnull(Column#4)) + └─TableScan_32 1985.00 cop table:t2, range:[-inf,+inf], keep order:false explain update t1 set t1.c2 = 2 where t1.c1 = 1; id count task operator info Update_2 N/A root N/A @@ -66,13 +66,13 @@ Delete_3 N/A root N/A explain select count(b.c2) from t1 a, t2 b where a.c1 = b.c2 group by a.c1; id count task operator info Projection_11 1985.00 root cast(Column#9) -└─HashLeftJoin_19 1985.00 root inner join, inner:HashAgg_23, equal:[eq(Column#1, Column#5)] - ├─IndexReader_34 1999.00 root index:IndexScan_33 - │ └─IndexScan_33 1999.00 cop table:a, index:c2, range:[NULL,+inf], keep order:false - └─HashAgg_23 1985.00 root group by:Column#5, funcs:count(Column#5), firstrow(Column#5) - └─TableReader_30 1985.00 root data:Selection_29 - └─Selection_29 1985.00 cop not(isnull(Column#5)) - └─TableScan_28 1985.00 cop table:b, range:[-inf,+inf], keep order:false +└─HashLeftJoin_21 1985.00 root inner join, inner:HashAgg_25, equal:[eq(Column#1, Column#5)] + ├─IndexReader_36 1999.00 root index:IndexScan_35 + │ └─IndexScan_35 1999.00 cop table:a, index:c2, range:[NULL,+inf], keep order:false + └─HashAgg_25 1985.00 root group by:Column#5, funcs:count(Column#5), firstrow(Column#5) + └─TableReader_32 1985.00 root data:Selection_31 + └─Selection_31 1985.00 cop not(isnull(Column#5)) + └─TableScan_30 1985.00 cop table:b, range:[-inf,+inf], keep order:false explain select * from t2 order by t2.c2 limit 0, 1; id count task operator info TopN_7 1.00 root Column#2:asc, offset:0, count:1 @@ -93,13 +93,13 @@ TableReader_7 0.50 root data:Selection_6 explain select c1 from t1 where c1 in (select c2 from t2); id count task operator info Projection_9 1985.00 root Column#1 -└─HashLeftJoin_17 1985.00 root inner join, inner:HashAgg_21, equal:[eq(Column#1, Column#5)] - ├─IndexReader_32 1999.00 root index:IndexScan_31 - │ └─IndexScan_31 1999.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:false - └─HashAgg_21 1985.00 root group by:Column#5, funcs:firstrow(Column#5) - └─TableReader_28 1985.00 root data:Selection_27 - └─Selection_27 1985.00 cop not(isnull(Column#5)) - └─TableScan_26 1985.00 cop table:t2, range:[-inf,+inf], keep order:false +└─HashLeftJoin_19 1985.00 root inner join, inner:HashAgg_23, equal:[eq(Column#1, Column#5)] + ├─IndexReader_34 1999.00 root index:IndexScan_33 + │ └─IndexScan_33 1999.00 cop table:t1, index:c2, range:[NULL,+inf], keep order:false + └─HashAgg_23 1985.00 root group by:Column#5, funcs:firstrow(Column#5) + └─TableReader_30 1985.00 root data:Selection_29 + └─Selection_29 1985.00 cop not(isnull(Column#5)) + └─TableScan_28 1985.00 cop table:t2, range:[-inf,+inf], keep order:false explain select * from information_schema.columns; id count task operator info MemTableScan_4 10000.00 root diff --git a/cmd/explaintest/r/generated_columns.result b/cmd/explaintest/r/generated_columns.result index 4ebf4d47fe51a..6113c78864b75 100644 --- a/cmd/explaintest/r/generated_columns.result +++ b/cmd/explaintest/r/generated_columns.result @@ -71,24 +71,24 @@ VALUES ('{"a": 1}', '{"1": "1"}'); ANALYZE TABLE sgc1, sgc2; EXPLAIN SELECT /*+ TIDB_INLJ(sgc1, sgc2) */ * from sgc1 join sgc2 on sgc1.a=sgc2.a; id count task operator info -IndexJoin_23 5.00 root inner join, inner:IndexLookUp_22, outer key:Column#8, inner key:Column#3 -├─IndexLookUp_22 5.00 root -│ ├─Selection_21 5.00 cop not(isnull(Column#3)) -│ │ └─IndexScan_19 5.00 cop table:sgc1, index:a, range: decided by [eq(Column#3, Column#8)], keep order:false -│ └─TableScan_20 5.00 cop table:sgc1, keep order:false -└─TableReader_32 1.00 root data:Selection_31 - └─Selection_31 1.00 cop not(isnull(Column#8)) - └─TableScan_30 1.00 cop table:sgc2, range:[-inf,+inf], keep order:false +IndexHashJoin_33 5.00 root inner join, inner:IndexLookUp_24, outer key:Column#8, inner key:Column#3 +├─IndexLookUp_24 5.00 root +│ ├─Selection_23 5.00 cop not(isnull(Column#3)) +│ │ └─IndexScan_21 5.00 cop table:sgc1, index:a, range: decided by [eq(Column#3, Column#8)], keep order:false +│ └─TableScan_22 5.00 cop table:sgc1, keep order:false +└─TableReader_36 1.00 root data:Selection_35 + └─Selection_35 1.00 cop not(isnull(Column#8)) + └─TableScan_34 1.00 cop table:sgc2, range:[-inf,+inf], keep order:false EXPLAIN SELECT * from sgc1 join sgc2 on sgc1.a=sgc2.a; id count task operator info Projection_6 5.00 root Column#1, Column#2, Column#3, Column#4, Column#6, Column#7, Column#8, Column#9 -└─HashRightJoin_21 5.00 root inner join, inner:TableReader_40, equal:[eq(Column#8, Column#3)] - ├─TableReader_40 1.00 root data:Selection_39 - │ └─Selection_39 1.00 cop not(isnull(Column#8)) - │ └─TableScan_38 1.00 cop table:sgc2, range:[-inf,+inf], keep order:false - └─TableReader_49 5.00 root data:Selection_48 - └─Selection_48 5.00 cop not(isnull(Column#3)) - └─TableScan_47 5.00 cop table:sgc1, range:[-inf,+inf], keep order:false +└─HashRightJoin_23 5.00 root inner join, inner:TableReader_42, equal:[eq(Column#8, Column#3)] + ├─TableReader_42 1.00 root data:Selection_41 + │ └─Selection_41 1.00 cop not(isnull(Column#8)) + │ └─TableScan_40 1.00 cop table:sgc2, range:[-inf,+inf], keep order:false + └─TableReader_51 5.00 root data:Selection_50 + └─Selection_50 5.00 cop not(isnull(Column#3)) + └─TableScan_49 5.00 cop table:sgc1, range:[-inf,+inf], keep order:false DROP TABLE IF EXISTS sgc3; CREATE TABLE sgc3 ( j JSON, diff --git a/cmd/explaintest/r/index_join.result b/cmd/explaintest/r/index_join.result index a6b93af03854a..85ec9ca05bea6 100644 --- a/cmd/explaintest/r/index_join.result +++ b/cmd/explaintest/r/index_join.result @@ -8,24 +8,24 @@ set session tidb_hashagg_partial_concurrency = 1; set session tidb_hashagg_final_concurrency = 1; explain select /*+ TIDB_INLJ(t1, t2) */ * from t1 join t2 on t1.a=t2.a; id count task operator info -IndexJoin_22 5.00 root inner join, inner:IndexLookUp_21, outer key:Column#4, inner key:Column#1 -├─IndexLookUp_21 5.00 root -│ ├─Selection_20 5.00 cop not(isnull(Column#1)) -│ │ └─IndexScan_18 5.00 cop table:t1, index:a, range: decided by [eq(Column#1, Column#4)], keep order:false -│ └─TableScan_19 5.00 cop table:t1, keep order:false -└─TableReader_31 1.00 root data:Selection_30 - └─Selection_30 1.00 cop not(isnull(Column#4)) - └─TableScan_29 1.00 cop table:t2, range:[-inf,+inf], keep order:false +IndexHashJoin_32 5.00 root inner join, inner:IndexLookUp_23, outer key:Column#4, inner key:Column#1 +├─IndexLookUp_23 5.00 root +│ ├─Selection_22 5.00 cop not(isnull(Column#1)) +│ │ └─IndexScan_20 5.00 cop table:t1, index:a, range: decided by [eq(Column#1, Column#4)], keep order:false +│ └─TableScan_21 5.00 cop table:t1, keep order:false +└─TableReader_35 1.00 root data:Selection_34 + └─Selection_34 1.00 cop not(isnull(Column#4)) + └─TableScan_33 1.00 cop table:t2, range:[-inf,+inf], keep order:false explain select * from t1 join t2 on t1.a=t2.a; id count task operator info Projection_6 5.00 root Column#1, Column#2, Column#4, Column#5 -└─HashRightJoin_20 5.00 root inner join, inner:TableReader_31, equal:[eq(Column#4, Column#1)] - ├─TableReader_31 1.00 root data:Selection_30 - │ └─Selection_30 1.00 cop not(isnull(Column#4)) - │ └─TableScan_29 1.00 cop table:t2, range:[-inf,+inf], keep order:false - └─TableReader_37 5.00 root data:Selection_36 - └─Selection_36 5.00 cop not(isnull(Column#1)) - └─TableScan_35 5.00 cop table:t1, range:[-inf,+inf], keep order:false +└─HashRightJoin_22 5.00 root inner join, inner:TableReader_33, equal:[eq(Column#4, Column#1)] + ├─TableReader_33 1.00 root data:Selection_32 + │ └─Selection_32 1.00 cop not(isnull(Column#4)) + │ └─TableScan_31 1.00 cop table:t2, range:[-inf,+inf], keep order:false + └─TableReader_39 5.00 root data:Selection_38 + └─Selection_38 5.00 cop not(isnull(Column#1)) + └─TableScan_37 5.00 cop table:t1, range:[-inf,+inf], keep order:false drop table if exists t1, t2; create table t1(a int not null, b int not null); create table t2(a int not null, b int not null, key a(a)); @@ -33,8 +33,8 @@ set @@tidb_opt_insubq_to_join_and_agg=0; explain select /*+ TIDB_INLJ(t2@sel_2) */ * from t1 where t1.a in (select t2.a from t2); id count task operator info IndexMergeJoin_14 8000.00 root semi join, inner:IndexReader_12, outer key:Column#1, inner key:Column#4 -├─TableReader_16 10000.00 root data:TableScan_15 -│ └─TableScan_15 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo +├─TableReader_18 10000.00 root data:TableScan_17 +│ └─TableScan_17 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo └─IndexReader_12 1.25 root index:IndexScan_11 └─IndexScan_11 1.25 cop table:t2, index:a, range: decided by [eq(Column#4, Column#1)], keep order:true, stats:pseudo show warnings; @@ -46,10 +46,10 @@ create table t2(a int not null, b int not null, key a(a)); explain select /*+ TIDB_INLJ(t1) */ * from t1 where t1.a in (select t2.a from t2); id count task operator info Projection_8 10000.00 root Column#1, Column#2 -└─IndexMergeJoin_17 10000.00 root inner join, inner:IndexLookUp_15, outer key:Column#4, inner key:Column#1 - ├─IndexLookUp_15 1.25 root - │ ├─IndexScan_13 1.25 cop table:t1, index:a, range: decided by [eq(Column#1, Column#4)], keep order:true, stats:pseudo - │ └─TableScan_14 1.25 cop table:t1, keep order:false, stats:pseudo - └─StreamAgg_22 8000.00 root group by:Column#4, funcs:firstrow(Column#4) - └─IndexReader_35 10000.00 root index:IndexScan_34 - └─IndexScan_34 10000.00 cop table:t2, index:a, range:[NULL,+inf], keep order:true, stats:pseudo +└─IndexHashJoin_19 10000.00 root inner join, inner:IndexLookUp_11, outer key:Column#4, inner key:Column#1 + ├─IndexLookUp_11 1.25 root + │ ├─IndexScan_9 1.25 cop table:t1, index:a, range: decided by [eq(Column#1, Column#4)], keep order:false, stats:pseudo + │ └─TableScan_10 1.25 cop table:t1, keep order:false, stats:pseudo + └─StreamAgg_24 8000.00 root group by:Column#4, funcs:firstrow(Column#4) + └─IndexReader_37 10000.00 root index:IndexScan_36 + └─IndexScan_36 10000.00 cop table:t2, index:a, range:[NULL,+inf], keep order:true, stats:pseudo diff --git a/cmd/explaintest/r/subquery.result b/cmd/explaintest/r/subquery.result index d63261ba61b48..720a8ae21b315 100644 --- a/cmd/explaintest/r/subquery.result +++ b/cmd/explaintest/r/subquery.result @@ -22,8 +22,8 @@ Projection_11 5.00 root Column#15 ├─TableReader_15 5.00 root data:TableScan_14 │ └─TableScan_14 5.00 cop table:t, range:[-inf,+inf], keep order:false └─StreamAgg_22 1.00 root funcs:count(1) - └─IndexMergeJoin_29 0.50 root inner join, inner:TableReader_27, outer key:Column#5, inner key:Column#9 - ├─IndexReader_33 1.00 root index:IndexScan_32 - │ └─IndexScan_32 1.00 cop table:s, index:b, c, d, range: decided by [eq(Column#6, 1) eq(Column#7, 1) eq(Column#8, Column#1)], keep order:false - └─TableReader_27 1.00 root data:TableScan_26 - └─TableScan_26 1.00 cop table:t1, range: decided by [Column#5], keep order:true + └─IndexHashJoin_31 0.50 root inner join, inner:TableReader_24, outer key:Column#5, inner key:Column#9 + ├─IndexReader_35 1.00 root index:IndexScan_34 + │ └─IndexScan_34 1.00 cop table:s, index:b, c, d, range: decided by [eq(Column#6, 1) eq(Column#7, 1) eq(Column#8, Column#1)], keep order:false + └─TableReader_24 1.00 root data:TableScan_23 + └─TableScan_23 1.00 cop table:t1, range: decided by [Column#5], keep order:false diff --git a/cmd/explaintest/r/topn_push_down.result b/cmd/explaintest/r/topn_push_down.result index 873ce0a293137..20b74bd963dbe 100644 --- a/cmd/explaintest/r/topn_push_down.result +++ b/cmd/explaintest/r/topn_push_down.result @@ -169,21 +169,21 @@ LIMIT 0, 5; id count task operator info Projection_13 0.00 root Column#47 └─Limit_19 0.00 root offset:0, count:5 - └─IndexJoin_99 0.00 root left outer join, inner:IndexReader_98, outer key:Column#1, inner key:Column#97 - ├─TopN_106 0.00 root Column#47:asc, offset:0, count:5 - │ └─IndexMergeJoin_47 0.00 root inner join, inner:IndexLookUp_45, outer key:Column#1, inner key:Column#41 - │ ├─IndexLookUp_81 0.00 root - │ │ ├─Selection_79 0.00 cop eq(Column#4, 18), eq(Column#5, 1) - │ │ │ └─IndexScan_77 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_80 0.00 cop eq(Column#21, 32314), eq(Column#3, 2) - │ │ └─TableScan_78 0.00 cop table:tr, keep order:false, stats:pseudo - │ └─IndexLookUp_45 0.03 root - │ ├─IndexScan_42 1.25 cop table:te, index:trade_id, range: decided by [eq(Column#41, Column#1)], keep order:true, stats:pseudo - │ └─Selection_44 0.03 cop ge(Column#47, 2018-04-23 00:00:00.000000), le(Column#47, 2018-04-23 23:59:59.000000) - │ └─TableScan_43 1.25 cop table:te, keep order:false, stats:pseudo - └─IndexReader_98 1.25 root index:Selection_97 - └─Selection_97 1.25 cop not(isnull(Column#97)) - └─IndexScan_96 1.25 cop table:p, index:relate_id, range: decided by [eq(Column#97, Column#1)], keep order:false, stats:pseudo + └─IndexJoin_103 0.00 root left outer join, inner:IndexReader_102, outer key:Column#1, inner key:Column#97 + ├─TopN_110 0.00 root Column#47:asc, offset:0, count:5 + │ └─IndexMergeJoin_49 0.00 root inner join, inner:IndexLookUp_47, outer key:Column#1, inner key:Column#41 + │ ├─IndexLookUp_85 0.00 root + │ │ ├─Selection_83 0.00 cop eq(Column#4, 18), eq(Column#5, 1) + │ │ │ └─IndexScan_81 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_84 0.00 cop eq(Column#21, 32314), eq(Column#3, 2) + │ │ └─TableScan_82 0.00 cop table:tr, keep order:false, stats:pseudo + │ └─IndexLookUp_47 0.03 root + │ ├─IndexScan_44 1.25 cop table:te, index:trade_id, range: decided by [eq(Column#41, Column#1)], keep order:true, stats:pseudo + │ └─Selection_46 0.03 cop ge(Column#47, 2018-04-23 00:00:00.000000), le(Column#47, 2018-04-23 23:59:59.000000) + │ └─TableScan_45 1.25 cop table:te, keep order:false, stats:pseudo + └─IndexReader_102 1.25 root index:Selection_101 + └─Selection_101 1.25 cop not(isnull(Column#97)) + └─IndexScan_100 1.25 cop table:p, index:relate_id, range: decided by [eq(Column#97, Column#1)], 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 @@ -222,20 +222,20 @@ create table t(a int not null, index idx(a)); explain select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 on t1.a = t2.a limit 5; id count task operator info Limit_11 5.00 root offset:0, count:5 -└─IndexMergeJoin_19 5.00 root inner join, inner:IndexReader_17, outer key:Column#1, inner key:Column#3 - ├─IndexReader_23 4.00 root index:IndexScan_22 - │ └─IndexScan_22 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:false, stats:pseudo - └─IndexReader_17 1.25 root index:IndexScan_16 - └─IndexScan_16 1.25 cop table:t2, index:a, range: decided by [eq(Column#3, Column#1)], keep order:true, stats:pseudo +└─IndexHashJoin_21 5.00 root inner join, inner:IndexReader_14, outer key:Column#1, inner key:Column#3 + ├─IndexReader_25 4.00 root index:IndexScan_24 + │ └─IndexScan_24 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:false, stats:pseudo + └─IndexReader_14 1.25 root index:IndexScan_13 + └─IndexScan_13 1.25 cop table:t2, index:a, range: decided by [eq(Column#3, Column#1)], keep order:false, stats:pseudo explain select /*+ TIDB_INLJ(t2) */ * from t t1 left join t t2 on t1.a = t2.a where t2.a is null limit 5; id count task operator info Limit_12 5.00 root offset:0, count:5 └─Selection_13 5.00 root isnull(Column#3) - └─IndexMergeJoin_21 5.00 root left outer join, inner:IndexReader_19, outer key:Column#1, inner key:Column#3 - ├─IndexReader_25 4.00 root index:IndexScan_24 - │ └─IndexScan_24 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:false, stats:pseudo - └─IndexReader_19 1.25 root index:IndexScan_18 - └─IndexScan_18 1.25 cop table:t2, index:a, range: decided by [eq(Column#3, Column#1)], keep order:true, stats:pseudo + └─IndexHashJoin_23 5.00 root left outer join, inner:IndexReader_16, outer key:Column#1, inner key:Column#3 + ├─IndexReader_27 4.00 root index:IndexScan_26 + │ └─IndexScan_26 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:false, stats:pseudo + └─IndexReader_16 1.25 root index:IndexScan_15 + └─IndexScan_15 1.25 cop table:t2, index:a, range: decided by [eq(Column#3, Column#1)], keep order:false, stats:pseudo explain select /*+ TIDB_SMJ(t1, t2) */ * from t t1 join t t2 on t1.a = t2.a limit 5; id count task operator info Limit_11 5.00 root offset:0, count:5 @@ -256,17 +256,17 @@ Limit_12 5.00 root offset:0, count:5 explain select /*+ TIDB_HJ(t1, t2) */ * from t t1 join t t2 on t1.a = t2.a limit 5; id count task operator info Limit_11 5.00 root offset:0, count:5 -└─HashLeftJoin_27 5.00 root inner join, inner:IndexReader_36, equal:[eq(Column#1, Column#3)] - ├─IndexReader_32 4.00 root index:IndexScan_31 - │ └─IndexScan_31 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:false, stats:pseudo - └─IndexReader_36 10000.00 root index:IndexScan_35 - └─IndexScan_35 10000.00 cop table:t2, index:a, range:[NULL,+inf], keep order:false, stats:pseudo +└─HashLeftJoin_31 5.00 root inner join, inner:IndexReader_40, equal:[eq(Column#1, Column#3)] + ├─IndexReader_36 4.00 root index:IndexScan_35 + │ └─IndexScan_35 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:false, stats:pseudo + └─IndexReader_40 10000.00 root index:IndexScan_39 + └─IndexScan_39 10000.00 cop table:t2, index:a, range:[NULL,+inf], keep order:false, stats:pseudo explain select /*+ TIDB_HJ(t1, t2) */ * from t t1 left join t t2 on t1.a = t2.a where t2.a is null limit 5; id count task operator info Limit_12 5.00 root offset:0, count:5 └─Selection_13 5.00 root isnull(Column#3) - └─HashLeftJoin_22 5.00 root left outer join, inner:IndexReader_30, equal:[eq(Column#1, Column#3)] - ├─IndexReader_26 4.00 root index:IndexScan_25 - │ └─IndexScan_25 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:false, stats:pseudo - └─IndexReader_30 10000.00 root index:IndexScan_29 - └─IndexScan_29 10000.00 cop table:t2, index:a, range:[NULL,+inf], keep order:false, stats:pseudo + └─HashLeftJoin_24 5.00 root left outer join, inner:IndexReader_32, equal:[eq(Column#1, Column#3)] + ├─IndexReader_28 4.00 root index:IndexScan_27 + │ └─IndexScan_27 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:false, stats:pseudo + └─IndexReader_32 10000.00 root index:IndexScan_31 + └─IndexScan_31 10000.00 cop table:t2, index:a, range:[NULL,+inf], keep order:false, stats:pseudo diff --git a/cmd/explaintest/r/tpch.result b/cmd/explaintest/r/tpch.result index a078a80335407..a076c82d3d076 100644 --- a/cmd/explaintest/r/tpch.result +++ b/cmd/explaintest/r/tpch.result @@ -186,35 +186,35 @@ Projection_37 100.00 root Column#15, Column#11, Column#24, Column#1, Column#3, C └─TopN_40 100.00 root Column#15:desc, Column#24:asc, Column#11:asc, Column#1:asc, offset:0, count:100 └─HashRightJoin_45 155496.00 root inner join, inner:IndexMergeJoin_55, equal:[eq(Column#1, Column#30) eq(Column#20, Column#50)] ├─IndexMergeJoin_55 155496.00 root inner join, inner:TableReader_53, outer key:Column#17, inner key:Column#1 - │ ├─HashRightJoin_59 8155010.44 root inner join, inner:HashRightJoin_61, equal:[eq(Column#10, Column#18)] - │ │ ├─HashRightJoin_61 100000.00 root inner join, inner:HashRightJoin_72, equal:[eq(Column#23, Column#13)] - │ │ │ ├─HashRightJoin_72 5.00 root inner join, inner:TableReader_77, equal:[eq(Column#27, Column#25)] - │ │ │ │ ├─TableReader_77 1.00 root data:Selection_76 - │ │ │ │ │ └─Selection_76 1.00 cop eq(Column#28, "ASIA") - │ │ │ │ │ └─TableScan_75 5.00 cop table:region, range:[-inf,+inf], keep order:false - │ │ │ │ └─TableReader_74 25.00 root data:TableScan_73 - │ │ │ │ └─TableScan_73 25.00 cop table:nation, range:[-inf,+inf], keep order:false - │ │ │ └─TableReader_79 500000.00 root data:TableScan_78 - │ │ │ └─TableScan_78 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false - │ │ └─TableReader_81 40000000.00 root data:TableScan_80 - │ │ └─TableScan_80 40000000.00 cop table:partsupp, range:[-inf,+inf], keep order:false + │ ├─HashRightJoin_61 8155010.44 root inner join, inner:HashRightJoin_63, equal:[eq(Column#10, Column#18)] + │ │ ├─HashRightJoin_63 100000.00 root inner join, inner:HashRightJoin_76, equal:[eq(Column#23, Column#13)] + │ │ │ ├─HashRightJoin_76 5.00 root inner join, inner:TableReader_81, equal:[eq(Column#27, Column#25)] + │ │ │ │ ├─TableReader_81 1.00 root data:Selection_80 + │ │ │ │ │ └─Selection_80 1.00 cop eq(Column#28, "ASIA") + │ │ │ │ │ └─TableScan_79 5.00 cop table:region, range:[-inf,+inf], keep order:false + │ │ │ │ └─TableReader_78 25.00 root data:TableScan_77 + │ │ │ │ └─TableScan_77 25.00 cop table:nation, range:[-inf,+inf], keep order:false + │ │ │ └─TableReader_83 500000.00 root data:TableScan_82 + │ │ │ └─TableScan_82 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false + │ │ └─TableReader_85 40000000.00 root data:TableScan_84 + │ │ └─TableScan_84 40000000.00 cop table:partsupp, range:[-inf,+inf], keep order:false │ └─TableReader_53 0.02 root data:Selection_52 │ └─Selection_52 0.02 cop eq(Column#6, 30), like(Column#5, "%STEEL", 92) │ └─TableScan_51 0.02 cop table:part, range: decided by [Column#17], keep order:true - └─Selection_85 6524008.35 root not(isnull(Column#50)) - └─HashAgg_88 8155010.44 root group by:Column#30, funcs:min(Column#33), firstrow(Column#30) - └─HashRightJoin_92 8155010.44 root inner join, inner:HashRightJoin_94, equal:[eq(Column#36, Column#31)] - ├─HashRightJoin_94 100000.00 root inner join, inner:HashRightJoin_105, equal:[eq(Column#43, Column#39)] - │ ├─HashRightJoin_105 5.00 root inner join, inner:TableReader_110, equal:[eq(Column#47, Column#45)] - │ │ ├─TableReader_110 1.00 root data:Selection_109 - │ │ │ └─Selection_109 1.00 cop eq(Column#48, "ASIA") - │ │ │ └─TableScan_108 5.00 cop table:region, range:[-inf,+inf], keep order:false - │ │ └─TableReader_107 25.00 root data:TableScan_106 - │ │ └─TableScan_106 25.00 cop table:nation, range:[-inf,+inf], keep order:false - │ └─TableReader_112 500000.00 root data:TableScan_111 - │ └─TableScan_111 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false - └─TableReader_114 40000000.00 root data:TableScan_113 - └─TableScan_113 40000000.00 cop table:partsupp, range:[-inf,+inf], keep order:false + └─Selection_89 6524008.35 root not(isnull(Column#50)) + └─HashAgg_92 8155010.44 root group by:Column#30, funcs:min(Column#33), firstrow(Column#30) + └─HashRightJoin_96 8155010.44 root inner join, inner:HashRightJoin_98, equal:[eq(Column#36, Column#31)] + ├─HashRightJoin_98 100000.00 root inner join, inner:HashRightJoin_111, equal:[eq(Column#43, Column#39)] + │ ├─HashRightJoin_111 5.00 root inner join, inner:TableReader_116, equal:[eq(Column#47, Column#45)] + │ │ ├─TableReader_116 1.00 root data:Selection_115 + │ │ │ └─Selection_115 1.00 cop eq(Column#48, "ASIA") + │ │ │ └─TableScan_114 5.00 cop table:region, range:[-inf,+inf], keep order:false + │ │ └─TableReader_113 25.00 root data:TableScan_112 + │ │ └─TableScan_112 25.00 cop table:nation, range:[-inf,+inf], keep order:false + │ └─TableReader_118 500000.00 root data:TableScan_117 + │ └─TableScan_117 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false + └─TableReader_120 40000000.00 root data:TableScan_119 + └─TableScan_119 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 Column#18, Column#35, Column#13, Column#16 └─TopN_17 10.00 root Column#35:desc, Column#13:asc, offset:0, count:10 └─HashAgg_23 40252367.98 root group by:Column#44, Column#45, Column#46, funcs:sum(Column#0), firstrow(Column#0), firstrow(Column#0), firstrow(Column#0) - └─Projection_74 91515927.49 root mul(Column#23, minus(1, Column#24)), Column#13, Column#16, Column#18, Column#18, Column#13, Column#16 - └─IndexJoin_29 91515927.49 root inner join, inner:IndexLookUp_28, outer key:Column#9, inner key:Column#18 - ├─HashRightJoin_64 22592975.51 root inner join, inner:TableReader_70, equal:[eq(Column#1, Column#10)] - │ ├─TableReader_70 1498236.00 root data:Selection_69 - │ │ └─Selection_69 1498236.00 cop eq(Column#7, "AUTOMOBILE") - │ │ └─TableScan_68 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false - │ └─TableReader_67 36870000.00 root data:Selection_66 - │ └─Selection_66 36870000.00 cop lt(Column#13, 1995-03-13 00:00:00.000000) - │ └─TableScan_65 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false + └─Projection_78 91515927.49 root mul(Column#23, minus(1, Column#24)), Column#13, Column#16, Column#18, Column#18, Column#13, Column#16 + └─IndexHashJoin_37 91515927.49 root inner join, inner:IndexLookUp_28, outer key:Column#9, inner key:Column#18 + ├─HashRightJoin_68 22592975.51 root inner join, inner:TableReader_74, equal:[eq(Column#1, Column#10)] + │ ├─TableReader_74 1498236.00 root data:Selection_73 + │ │ └─Selection_73 1498236.00 cop eq(Column#7, "AUTOMOBILE") + │ │ └─TableScan_72 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false + │ └─TableReader_71 36870000.00 root data:Selection_70 + │ └─Selection_70 36870000.00 cop lt(Column#13, 1995-03-13 00:00:00.000000) + │ └─TableScan_69 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false └─IndexLookUp_28 2.20 root ├─IndexScan_25 4.05 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#18, Column#9)], keep order:false └─Selection_27 2.20 cop gt(Column#28, 1995-03-13 00:00:00.000000) @@ -298,10 +298,10 @@ id count task operator info Sort_10 1.00 root Column#44:asc └─Projection_12 1.00 root Column#6, Column#43 └─HashAgg_15 1.00 root group by:Column#6, funcs:count(1), firstrow(Column#6) - └─IndexJoin_21 2340750.00 root semi join, inner:IndexLookUp_20, outer key:Column#1, inner key:Column#10 - ├─TableReader_39 2925937.50 root data:Selection_38 - │ └─Selection_38 2925937.50 cop ge(Column#5, 1995-01-01 00:00:00.000000), lt(Column#5, 1995-04-01) - │ └─TableScan_37 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false + └─IndexHashJoin_29 2340750.00 root semi join, inner:IndexLookUp_20, outer key:Column#1, inner key:Column#10 + ├─TableReader_41 2925937.50 root data:Selection_40 + │ └─Selection_40 2925937.50 cop ge(Column#5, 1995-01-01 00:00:00.000000), lt(Column#5, 1995-04-01) + │ └─TableScan_39 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false └─IndexLookUp_20 3.24 root ├─IndexScan_17 4.05 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#10, Column#1)], keep order:false └─Selection_19 3.24 cop lt(Column#21, Column#22) @@ -346,26 +346,26 @@ id count task operator info Sort_23 5.00 root Column#51:desc └─Projection_25 5.00 root Column#43, Column#49 └─HashAgg_28 5.00 root group by:Column#52, funcs:sum(Column#0), firstrow(Column#0) - └─Projection_80 11822812.50 root mul(Column#23, minus(1, Column#24)), Column#43, Column#43 - └─HashLeftJoin_36 11822812.50 root inner join, inner:TableReader_78, equal:[eq(Column#38, Column#4) eq(Column#10, Column#1)] - ├─IndexMergeJoin_47 11822812.50 root inner join, inner:TableReader_45, outer key:Column#18, inner key:Column#9 - │ ├─HashRightJoin_51 61163763.01 root inner join, inner:HashRightJoin_53, equal:[eq(Column#35, Column#20)] - │ │ ├─HashRightJoin_53 100000.00 root inner join, inner:HashRightJoin_64, equal:[eq(Column#42, Column#38)] - │ │ │ ├─HashRightJoin_64 5.00 root inner join, inner:TableReader_69, equal:[eq(Column#46, Column#44)] - │ │ │ │ ├─TableReader_69 1.00 root data:Selection_68 - │ │ │ │ │ └─Selection_68 1.00 cop eq(Column#47, "MIDDLE EAST") - │ │ │ │ │ └─TableScan_67 5.00 cop table:region, range:[-inf,+inf], 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_71 500000.00 root data:TableScan_70 - │ │ │ └─TableScan_70 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false - │ │ └─TableReader_73 300005811.00 root data:TableScan_72 - │ │ └─TableScan_72 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false - │ └─TableReader_45 0.15 root data:Selection_44 - │ └─Selection_44 0.15 cop ge(Column#13, 1994-01-01 00:00:00.000000), lt(Column#13, 1995-01-01) - │ └─TableScan_43 0.19 cop table:orders, range: decided by [Column#18], keep order:true - └─TableReader_78 7500000.00 root data:TableScan_77 - └─TableScan_77 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false + └─Projection_86 11822812.50 root mul(Column#23, minus(1, Column#24)), Column#43, Column#43 + └─HashLeftJoin_38 11822812.50 root inner join, inner:TableReader_84, equal:[eq(Column#38, Column#4) eq(Column#10, Column#1)] + ├─IndexMergeJoin_49 11822812.50 root inner join, inner:TableReader_47, outer key:Column#18, inner key:Column#9 + │ ├─HashRightJoin_55 61163763.01 root inner join, inner:HashRightJoin_57, equal:[eq(Column#35, Column#20)] + │ │ ├─HashRightJoin_57 100000.00 root inner join, inner:HashRightJoin_70, equal:[eq(Column#42, Column#38)] + │ │ │ ├─HashRightJoin_70 5.00 root inner join, inner:TableReader_75, equal:[eq(Column#46, Column#44)] + │ │ │ │ ├─TableReader_75 1.00 root data:Selection_74 + │ │ │ │ │ └─Selection_74 1.00 cop eq(Column#47, "MIDDLE EAST") + │ │ │ │ │ └─TableScan_73 5.00 cop table:region, range:[-inf,+inf], keep order:false + │ │ │ │ └─TableReader_72 25.00 root data:TableScan_71 + │ │ │ │ └─TableScan_71 25.00 cop table:nation, range:[-inf,+inf], keep order:false + │ │ │ └─TableReader_77 500000.00 root data:TableScan_76 + │ │ │ └─TableScan_76 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false + │ │ └─TableReader_79 300005811.00 root data:TableScan_78 + │ │ └─TableScan_78 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + │ └─TableReader_47 0.15 root data:Selection_46 + │ └─Selection_46 0.15 cop ge(Column#13, 1994-01-01 00:00:00.000000), lt(Column#13, 1995-01-01) + │ └─TableScan_45 0.19 cop table:orders, range: decided by [Column#18], keep order:true + └─TableReader_84 7500000.00 root data:TableScan_83 + └─TableScan_83 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false /* Q6 Forecasting Revenue Change Query This query quantifies the amount of revenue increase that would have resulted from eliminating certain companywide @@ -448,26 +448,26 @@ Sort_22 769.96 root Column#55:asc, Column#56:asc, Column#57:asc └─Projection_24 769.96 root Column#50, Column#51, Column#52, Column#54 └─HashAgg_27 769.96 root group by:Column#50, Column#51, Column#52, funcs:sum(Column#53), firstrow(Column#50), firstrow(Column#51), firstrow(Column#52) └─Projection_28 1957240.42 root Column#43, Column#47, extract("YEAR", Column#18), mul(Column#13, minus(1, Column#14)) - └─HashLeftJoin_38 1957240.42 root inner join, inner:TableReader_86, equal:[eq(Column#37, Column#46)], other cond:or(and(eq(Column#43, "JAPAN"), eq(Column#47, "INDIA")), and(eq(Column#43, "INDIA"), eq(Column#47, "JAPAN"))) - ├─HashLeftJoin_47 24465505.20 root inner join, inner:TableReader_83, equal:[eq(Column#26, Column#34)] - │ ├─IndexMergeJoin_56 24465505.20 root inner join, inner:TableReader_54, outer key:Column#8, inner key:Column#25 - │ │ ├─HashRightJoin_60 24465505.20 root inner join, inner:HashRightJoin_71, equal:[eq(Column#1, Column#10)] - │ │ │ ├─HashRightJoin_71 40000.00 root inner join, inner:TableReader_76, equal:[eq(Column#42, Column#4)] - │ │ │ │ ├─TableReader_76 2.00 root data:Selection_75 - │ │ │ │ │ └─Selection_75 2.00 cop or(eq(Column#43, "JAPAN"), eq(Column#43, "INDIA")) - │ │ │ │ │ └─TableScan_74 25.00 cop table:n1, range:[-inf,+inf], keep order:false - │ │ │ │ └─TableReader_73 500000.00 root data:TableScan_72 - │ │ │ │ └─TableScan_72 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false - │ │ │ └─TableReader_79 91446230.29 root data:Selection_78 - │ │ │ └─Selection_78 91446230.29 cop ge(Column#18, 1995-01-01 00:00:00.000000), le(Column#18, 1996-12-31 00:00:00.000000) - │ │ │ └─TableScan_77 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false - │ │ └─TableReader_54 1.00 root data:TableScan_53 - │ │ └─TableScan_53 1.00 cop table:orders, range: decided by [Column#8], keep order:true - │ └─TableReader_83 7500000.00 root data:TableScan_82 - │ └─TableScan_82 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false - └─TableReader_86 2.00 root data:Selection_85 - └─Selection_85 2.00 cop or(eq(Column#47, "INDIA"), eq(Column#47, "JAPAN")) - └─TableScan_84 25.00 cop table:n2, range:[-inf,+inf], keep order:false + └─HashLeftJoin_40 1957240.42 root inner join, inner:TableReader_94, equal:[eq(Column#37, Column#46)], other cond:or(and(eq(Column#43, "JAPAN"), eq(Column#47, "INDIA")), and(eq(Column#43, "INDIA"), eq(Column#47, "JAPAN"))) + ├─HashLeftJoin_51 24465505.20 root inner join, inner:TableReader_91, equal:[eq(Column#26, Column#34)] + │ ├─IndexHashJoin_62 24465505.20 root inner join, inner:TableReader_55, outer key:Column#8, inner key:Column#25 + │ │ ├─HashRightJoin_66 24465505.20 root inner join, inner:HashRightJoin_79, equal:[eq(Column#1, Column#10)] + │ │ │ ├─HashRightJoin_79 40000.00 root inner join, inner:TableReader_84, equal:[eq(Column#42, Column#4)] + │ │ │ │ ├─TableReader_84 2.00 root data:Selection_83 + │ │ │ │ │ └─Selection_83 2.00 cop or(eq(Column#43, "JAPAN"), eq(Column#43, "INDIA")) + │ │ │ │ │ └─TableScan_82 25.00 cop table:n1, range:[-inf,+inf], keep order:false + │ │ │ │ └─TableReader_81 500000.00 root data:TableScan_80 + │ │ │ │ └─TableScan_80 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false + │ │ │ └─TableReader_87 91446230.29 root data:Selection_86 + │ │ │ └─Selection_86 91446230.29 cop ge(Column#18, 1995-01-01 00:00:00.000000), le(Column#18, 1996-12-31 00:00:00.000000) + │ │ │ └─TableScan_85 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + │ │ └─TableReader_55 1.00 root data:TableScan_54 + │ │ └─TableScan_54 1.00 cop table:orders, range: decided by [Column#8], keep order:false + │ └─TableReader_91 7500000.00 root data:TableScan_90 + │ └─TableScan_90 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false + └─TableReader_94 2.00 root data:Selection_93 + └─Selection_93 2.00 cop or(eq(Column#47, "INDIA"), eq(Column#47, "JAPAN")) + └─TableScan_92 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_29 719.02 root Column#67:asc └─Projection_31 719.02 root Column#62, div(Column#65, Column#66) └─HashAgg_34 719.02 root group by:Column#74, funcs:sum(Column#0), sum(Column#0), firstrow(Column#0) - └─Projection_112 563136.02 root case(eq(Column#64, "INDIA"), Column#63, 0), Column#63, Column#62, Column#62 + └─Projection_122 563136.02 root case(eq(Column#64, "INDIA"), Column#63, 0), Column#63, Column#62, Column#62 └─Projection_35 563136.02 root extract("YEAR", Column#38), mul(Column#22, minus(1, Column#23)), Column#56 - └─HashLeftJoin_43 563136.02 root inner join, inner:TableReader_110, equal:[eq(Column#13, Column#55)] - ├─HashLeftJoin_52 563136.02 root inner join, inner:TableReader_108, equal:[eq(Column#19, Column#10)] - │ ├─HashLeftJoin_63 563136.02 root inner join, inner:TableReader_106, equal:[eq(Column#18, Column#1)] - │ │ ├─IndexJoin_69 90788402.51 root inner join, inner:IndexLookUp_68, outer key:Column#34, inner key:Column#17 - │ │ │ ├─HashRightJoin_78 22413367.93 root inner join, inner:HashRightJoin_80, equal:[eq(Column#43, Column#35)] - │ │ │ │ ├─HashRightJoin_80 1500000.00 root inner join, inner:HashRightJoin_91, equal:[eq(Column#51, Column#46)] - │ │ │ │ │ ├─HashRightJoin_91 5.00 root inner join, inner:TableReader_96, equal:[eq(Column#59, Column#53)] - │ │ │ │ │ │ ├─TableReader_96 1.00 root data:Selection_95 - │ │ │ │ │ │ │ └─Selection_95 1.00 cop eq(Column#60, "ASIA") - │ │ │ │ │ │ │ └─TableScan_94 5.00 cop table:region, range:[-inf,+inf], keep order:false - │ │ │ │ │ │ └─TableReader_93 25.00 root data:TableScan_92 - │ │ │ │ │ │ └─TableScan_92 25.00 cop table:n1, range:[-inf,+inf], keep order:false - │ │ │ │ │ └─TableReader_98 7500000.00 root data:TableScan_97 - │ │ │ │ │ └─TableScan_97 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false - │ │ │ │ └─TableReader_101 22413367.93 root data:Selection_100 - │ │ │ │ └─Selection_100 22413367.93 cop ge(Column#38, 1995-01-01 00:00:00.000000), le(Column#38, 1996-12-31 00:00:00.000000) - │ │ │ │ └─TableScan_99 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false - │ │ │ └─IndexLookUp_68 4.05 root - │ │ │ ├─IndexScan_66 4.05 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#17, Column#34)], keep order:false - │ │ │ └─TableScan_67 4.05 cop table:lineitem, keep order:false - │ │ └─TableReader_106 61674.00 root data:Selection_105 - │ │ └─Selection_105 61674.00 cop eq(Column#5, "SMALL PLATED COPPER") - │ │ └─TableScan_104 10000000.00 cop table:part, 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 25.00 root data:TableScan_109 - └─TableScan_109 25.00 cop table:n2, range:[-inf,+inf], keep order:false + └─HashLeftJoin_45 563136.02 root inner join, inner:TableReader_120, equal:[eq(Column#13, Column#55)] + ├─HashLeftJoin_56 563136.02 root inner join, inner:TableReader_118, equal:[eq(Column#19, Column#10)] + │ ├─HashLeftJoin_69 563136.02 root inner join, inner:TableReader_116, equal:[eq(Column#18, Column#1)] + │ │ ├─IndexHashJoin_82 90788402.51 root inner join, inner:IndexLookUp_74, outer key:Column#34, inner key:Column#17 + │ │ │ ├─HashRightJoin_86 22413367.93 root inner join, inner:HashRightJoin_88, equal:[eq(Column#43, Column#35)] + │ │ │ │ ├─HashRightJoin_88 1500000.00 root inner join, inner:HashRightJoin_101, equal:[eq(Column#51, Column#46)] + │ │ │ │ │ ├─HashRightJoin_101 5.00 root inner join, inner:TableReader_106, equal:[eq(Column#59, Column#53)] + │ │ │ │ │ │ ├─TableReader_106 1.00 root data:Selection_105 + │ │ │ │ │ │ │ └─Selection_105 1.00 cop eq(Column#60, "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:n1, range:[-inf,+inf], keep order:false + │ │ │ │ │ └─TableReader_108 7500000.00 root data:TableScan_107 + │ │ │ │ │ └─TableScan_107 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false + │ │ │ │ └─TableReader_111 22413367.93 root data:Selection_110 + │ │ │ │ └─Selection_110 22413367.93 cop ge(Column#38, 1995-01-01 00:00:00.000000), le(Column#38, 1996-12-31 00:00:00.000000) + │ │ │ │ └─TableScan_109 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false + │ │ │ └─IndexLookUp_74 4.05 root + │ │ │ ├─IndexScan_72 4.05 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#17, Column#34)], keep order:false + │ │ │ └─TableScan_73 4.05 cop table:lineitem, keep order:false + │ │ └─TableReader_116 61674.00 root data:Selection_115 + │ │ └─Selection_115 61674.00 cop eq(Column#5, "SMALL PLATED COPPER") + │ │ └─TableScan_114 10000000.00 cop table:part, range:[-inf,+inf], keep order:false + │ └─TableReader_118 500000.00 root data:TableScan_117 + │ └─TableScan_117 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false + └─TableReader_120 25.00 root data:TableScan_119 + └─TableScan_119 25.00 cop table:n2, 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. @@ -596,24 +596,24 @@ Sort_25 2406.00 root Column#57:asc, Column#58:desc └─Projection_27 2406.00 root Column#53, Column#54, Column#56 └─HashAgg_30 2406.00 root group by:Column#53, Column#54, funcs:sum(Column#55), firstrow(Column#53), firstrow(Column#54) └─Projection_31 971049283.51 root Column#50, extract("YEAR", Column#44), minus(mul(Column#22, minus(1, Column#23)), mul(Column#37, Column#21)) - └─HashLeftJoin_41 971049283.51 root inner join, inner:TableReader_95, equal:[eq(Column#19, Column#35) eq(Column#18, Column#34)] - ├─HashLeftJoin_51 241379546.70 root inner join, inner:TableReader_93, equal:[eq(Column#17, Column#40)] - │ ├─HashLeftJoin_70 241379546.70 root inner join, inner:TableReader_91, equal:[eq(Column#18, Column#1)] - │ │ ├─HashRightJoin_73 300005811.00 root inner join, inner:HashRightJoin_82, equal:[eq(Column#10, Column#19)] - │ │ │ ├─HashRightJoin_82 500000.00 root inner join, inner:TableReader_86, equal:[eq(Column#49, Column#13)] - │ │ │ │ ├─TableReader_86 25.00 root data:TableScan_85 - │ │ │ │ │ └─TableScan_85 25.00 cop table:nation, range:[-inf,+inf], keep order:false - │ │ │ │ └─TableReader_84 500000.00 root data:TableScan_83 - │ │ │ │ └─TableScan_83 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false - │ │ │ └─TableReader_88 300005811.00 root data:TableScan_87 - │ │ │ └─TableScan_87 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false - │ │ └─TableReader_91 8000000.00 root data:Selection_90 - │ │ └─Selection_90 8000000.00 cop like(Column#2, "%dim%", 92) - │ │ └─TableScan_89 10000000.00 cop table:part, range:[-inf,+inf], keep order:false - │ └─TableReader_93 75000000.00 root data:TableScan_92 - │ └─TableScan_92 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false - └─TableReader_95 40000000.00 root data:TableScan_94 - └─TableScan_94 40000000.00 cop table:partsupp, range:[-inf,+inf], keep order:false + └─HashLeftJoin_43 971049283.51 root inner join, inner:TableReader_103, equal:[eq(Column#19, Column#35) eq(Column#18, Column#34)] + ├─HashLeftJoin_55 241379546.70 root inner join, inner:TableReader_101, equal:[eq(Column#17, Column#40)] + │ ├─HashLeftJoin_76 241379546.70 root inner join, inner:TableReader_99, equal:[eq(Column#18, Column#1)] + │ │ ├─HashRightJoin_79 300005811.00 root inner join, inner:HashRightJoin_90, equal:[eq(Column#10, Column#19)] + │ │ │ ├─HashRightJoin_90 500000.00 root inner join, inner:TableReader_94, equal:[eq(Column#49, Column#13)] + │ │ │ │ ├─TableReader_94 25.00 root data:TableScan_93 + │ │ │ │ │ └─TableScan_93 25.00 cop table:nation, range:[-inf,+inf], keep order:false + │ │ │ │ └─TableReader_92 500000.00 root data:TableScan_91 + │ │ │ │ └─TableScan_91 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false + │ │ │ └─TableReader_96 300005811.00 root data:TableScan_95 + │ │ │ └─TableScan_95 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + │ │ └─TableReader_99 8000000.00 root data:Selection_98 + │ │ └─Selection_98 8000000.00 cop like(Column#2, "%dim%", 92) + │ │ └─TableScan_97 10000000.00 cop table:part, range:[-inf,+inf], keep order:false + │ └─TableReader_101 75000000.00 root data:TableScan_100 + │ └─TableScan_100 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false + └─TableReader_103 40000000.00 root data:TableScan_102 + └─TableScan_102 40000000.00 cop table:partsupp, range:[-inf,+inf], keep order:false /* Q10 Returned Item Reporting Query The query identifies customers who might be having problems with the parts that are shipped to them. @@ -661,21 +661,21 @@ id count task operator info Projection_17 20.00 root Column#1, Column#2, Column#39, Column#6, Column#36, Column#3, Column#5, Column#8 └─TopN_20 20.00 root Column#39:desc, offset:0, count:20 └─HashAgg_26 3017307.69 root group by:Column#50, Column#51, Column#52, Column#53, Column#54, Column#55, Column#56, funcs:sum(Column#0), firstrow(Column#0), firstrow(Column#0), firstrow(Column#0), firstrow(Column#0), firstrow(Column#0), firstrow(Column#0), firstrow(Column#0) - └─Projection_62 12222016.17 root mul(Column#23, minus(1, Column#24)), Column#1, Column#2, Column#3, Column#5, Column#6, Column#8, Column#36, Column#1, Column#2, Column#6, Column#5, Column#36, Column#3, Column#8 - └─IndexMergeJoin_38 12222016.17 root inner join, inner:IndexLookUp_36, outer key:Column#9, inner key:Column#18 - ├─HashLeftJoin_41 3017307.69 root inner join, inner:TableReader_58, equal:[eq(Column#1, Column#10)] - │ ├─HashRightJoin_51 7500000.00 root inner join, inner:TableReader_55, equal:[eq(Column#35, Column#4)] - │ │ ├─TableReader_55 25.00 root data:TableScan_54 - │ │ │ └─TableScan_54 25.00 cop table:nation, range:[-inf,+inf], keep order:false - │ │ └─TableReader_53 7500000.00 root data:TableScan_52 - │ │ └─TableScan_52 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false - │ └─TableReader_58 3017307.69 root data:Selection_57 - │ └─Selection_57 3017307.69 cop ge(Column#13, 1993-08-01 00:00:00.000000), lt(Column#13, 1993-11-01) - │ └─TableScan_56 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false - └─IndexLookUp_36 1.00 root - ├─IndexScan_33 4.05 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#18, Column#9)], keep order:true - └─Selection_35 1.00 cop eq(Column#26, "R") - └─TableScan_34 4.05 cop table:lineitem, keep order:false + └─Projection_66 12222016.17 root mul(Column#23, minus(1, Column#24)), Column#1, Column#2, Column#3, Column#5, Column#6, Column#8, Column#36, Column#1, Column#2, Column#6, Column#5, Column#36, Column#3, Column#8 + └─IndexHashJoin_40 12222016.17 root inner join, inner:IndexLookUp_31, outer key:Column#9, inner key:Column#18 + ├─HashLeftJoin_43 3017307.69 root inner join, inner:TableReader_62, equal:[eq(Column#1, Column#10)] + │ ├─HashRightJoin_55 7500000.00 root inner join, inner:TableReader_59, equal:[eq(Column#35, Column#4)] + │ │ ├─TableReader_59 25.00 root data:TableScan_58 + │ │ │ └─TableScan_58 25.00 cop table:nation, range:[-inf,+inf], keep order:false + │ │ └─TableReader_57 7500000.00 root data:TableScan_56 + │ │ └─TableScan_56 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false + │ └─TableReader_62 3017307.69 root data:Selection_61 + │ └─Selection_61 3017307.69 cop ge(Column#13, 1993-08-01 00:00:00.000000), lt(Column#13, 1993-11-01) + │ └─TableScan_60 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false + └─IndexLookUp_31 1.00 root + ├─IndexScan_28 4.05 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#18, Column#9)], keep order:false + └─Selection_30 1.00 cop eq(Column#26, "R") + └─TableScan_29 4.05 cop table:lineitem, keep order:false /* Q11 Important Stock Identification Query This query finds the most important subset of suppliers' stock in a given nation. @@ -712,20 +712,20 @@ and n_name = 'MOZAMBIQUE' order by value desc; id count task operator info -Projection_55 1304801.67 root Column#1, Column#18 -└─Sort_56 1304801.67 root Column#18:desc - └─Selection_58 1304801.67 root gt(Column#18, NULL) - └─HashAgg_61 1631002.09 root group by:Column#46, funcs:sum(Column#0), firstrow(Column#0) - └─Projection_85 1631002.09 root mul(Column#4, cast(Column#3)), Column#1, Column#1 - └─HashRightJoin_65 1631002.09 root inner join, inner:HashRightJoin_76, equal:[eq(Column#7, Column#2)] - ├─HashRightJoin_76 20000.00 root inner join, inner:TableReader_81, equal:[eq(Column#14, Column#10)] - │ ├─TableReader_81 1.00 root data:Selection_80 - │ │ └─Selection_80 1.00 cop eq(Column#15, "MOZAMBIQUE") - │ │ └─TableScan_79 25.00 cop table:nation, range:[-inf,+inf], keep order:false - │ └─TableReader_78 500000.00 root data:TableScan_77 - │ └─TableScan_77 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false - └─TableReader_83 40000000.00 root data:TableScan_82 - └─TableScan_82 40000000.00 cop table:partsupp, range:[-inf,+inf], keep order:false +Projection_57 1304801.67 root Column#1, Column#18 +└─Sort_58 1304801.67 root Column#18:desc + └─Selection_60 1304801.67 root gt(Column#18, NULL) + └─HashAgg_63 1631002.09 root group by:Column#46, funcs:sum(Column#0), firstrow(Column#0) + └─Projection_89 1631002.09 root mul(Column#4, cast(Column#3)), Column#1, Column#1 + └─HashRightJoin_67 1631002.09 root inner join, inner:HashRightJoin_80, equal:[eq(Column#7, Column#2)] + ├─HashRightJoin_80 20000.00 root inner join, inner:TableReader_85, equal:[eq(Column#14, Column#10)] + │ ├─TableReader_85 1.00 root data:Selection_84 + │ │ └─Selection_84 1.00 cop eq(Column#15, "MOZAMBIQUE") + │ │ └─TableScan_83 25.00 cop table:nation, range:[-inf,+inf], keep order:false + │ └─TableReader_82 500000.00 root data:TableScan_81 + │ └─TableScan_81 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false + └─TableReader_87 40000000.00 root data:TableScan_86 + └─TableScan_86 40000000.00 cop table:partsupp, range:[-inf,+inf], keep order:false /* Q12 Shipping Modes and Order Priority Query This query determines whether selecting less expensive modes of shipping is negatively affecting the critical-priority @@ -769,13 +769,13 @@ id count task operator info Sort_9 1.00 root Column#29:asc └─Projection_11 1.00 root Column#24, Column#27, Column#28 └─HashAgg_14 1.00 root group by:Column#34, funcs:sum(Column#0), sum(Column#0), firstrow(Column#0) - └─Projection_38 10023369.01 root cast(case(or(eq(Column#6, "1-URGENT"), eq(Column#6, "2-HIGH")), 1, 0)), cast(case(and(ne(Column#6, "1-URGENT"), ne(Column#6, "2-HIGH")), 1, 0)), Column#24, Column#24 - └─IndexMergeJoin_22 10023369.01 root inner join, inner:TableReader_20, outer key:Column#10, inner key:Column#1 - ├─TableReader_34 10023369.01 root data:Selection_33 - │ └─Selection_33 10023369.01 cop ge(Column#22, 1997-01-01 00:00:00.000000), in(Column#24, "RAIL", "FOB"), lt(Column#20, Column#21), lt(Column#21, Column#22), lt(Column#22, 1998-01-01) - │ └─TableScan_32 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false - └─TableReader_20 1.00 root data:TableScan_19 - └─TableScan_19 1.00 cop table:orders, range: decided by [Column#10], keep order:true + └─Projection_40 10023369.01 root cast(case(or(eq(Column#6, "1-URGENT"), eq(Column#6, "2-HIGH")), 1, 0)), cast(case(and(ne(Column#6, "1-URGENT"), ne(Column#6, "2-HIGH")), 1, 0)), Column#24, Column#24 + └─IndexHashJoin_24 10023369.01 root inner join, inner:TableReader_17, outer key:Column#10, inner key:Column#1 + ├─TableReader_36 10023369.01 root data:Selection_35 + │ └─Selection_35 10023369.01 cop ge(Column#22, 1997-01-01 00:00:00.000000), in(Column#24, "RAIL", "FOB"), lt(Column#20, Column#21), lt(Column#21, Column#22), lt(Column#22, 1998-01-01) + │ └─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 [Column#10], keep order:false /* Q13 Customer Distribution Query This query seeks relationships between customers and the size of their orders. @@ -840,13 +840,13 @@ and l_shipdate < date_add('1996-12-01', interval '1' month); id count task operator info Projection_8 1.00 root div(mul(100.00, Column#27), Column#28) └─StreamAgg_13 1.00 root funcs:sum(Column#0), sum(Column#0) - └─Projection_37 4121984.49 root case(like(Column#22, "PROMO%", 92), mul(Column#6, minus(1, Column#7)), 0), mul(Column#6, minus(1, Column#7)) - └─IndexMergeJoin_34 4121984.49 root inner join, inner:TableReader_32, outer key:Column#2, inner key:Column#18 - ├─TableReader_25 4121984.49 root data:Selection_24 - │ └─Selection_24 4121984.49 cop ge(Column#11, 1996-12-01 00:00:00.000000), lt(Column#11, 1997-01-01) - │ └─TableScan_23 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false - └─TableReader_32 1.00 root data:TableScan_31 - └─TableScan_31 1.00 cop table:part, range: decided by [Column#2], keep order:true + └─Projection_41 4121984.49 root case(like(Column#22, "PROMO%", 92), mul(Column#6, minus(1, Column#7)), 0), mul(Column#6, minus(1, Column#7)) + └─IndexHashJoin_38 4121984.49 root inner join, inner:TableReader_31, outer key:Column#2, inner key:Column#18 + ├─TableReader_27 4121984.49 root data:Selection_26 + │ └─Selection_26 4121984.49 cop ge(Column#11, 1996-12-01 00:00:00.000000), lt(Column#11, 1997-01-01) + │ └─TableScan_25 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + └─TableReader_31 1.00 root data:TableScan_30 + └─TableScan_30 1.00 cop table:part, range: decided by [Column#2], keep order:false /* Q15 Top Supplier Query This query determines the top supplier so it can be rewarded, given more business, or identified for special recognition. @@ -930,16 +930,16 @@ id count task operator info Sort_13 3863988.24 root Column#28:desc, Column#25:asc, Column#26:asc, Column#27:asc └─Projection_15 3863988.24 root Column#10, Column#11, Column#12, Column#24 └─HashAgg_18 3863988.24 root group by:Column#10, Column#11, Column#12, funcs:count(distinct Column#2), firstrow(Column#10), firstrow(Column#11), firstrow(Column#12) - └─HashLeftJoin_28 3863988.24 root anti semi join, inner:TableReader_53, equal:[eq(Column#2, Column#16)] - ├─IndexMergeJoin_36 4829985.30 root inner join, inner:IndexReader_34, outer key:Column#7, inner key:Column#1 - │ ├─TableReader_46 1200618.43 root data:Selection_45 - │ │ └─Selection_45 1200618.43 cop in(Column#12, 48, 19, 12, 4, 41, 7, 21, 39), ne(Column#10, "Brand#34"), not(like(Column#11, "LARGE BRUSHED%", 92)) - │ │ └─TableScan_44 10000000.00 cop table:part, range:[-inf,+inf], keep order:false - │ └─IndexReader_34 4.02 root index:IndexScan_33 - │ └─IndexScan_33 4.02 cop table:partsupp, index:PS_PARTKEY, PS_SUPPKEY, range: decided by [eq(Column#1, Column#7)], keep order:true - └─TableReader_53 400000.00 root data:Selection_52 - └─Selection_52 400000.00 cop like(Column#22, "%Customer%Complaints%", 92) - └─TableScan_51 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false + └─HashLeftJoin_30 3863988.24 root anti semi join, inner:TableReader_57, equal:[eq(Column#2, Column#16)] + ├─IndexHashJoin_40 4829985.30 root inner join, inner:IndexReader_33, outer key:Column#7, inner key:Column#1 + │ ├─TableReader_50 1200618.43 root data:Selection_49 + │ │ └─Selection_49 1200618.43 cop in(Column#12, 48, 19, 12, 4, 41, 7, 21, 39), ne(Column#10, "Brand#34"), not(like(Column#11, "LARGE BRUSHED%", 92)) + │ │ └─TableScan_48 10000000.00 cop table:part, range:[-inf,+inf], keep order:false + │ └─IndexReader_33 4.02 root index:IndexScan_32 + │ └─IndexScan_32 4.02 cop table:partsupp, index:PS_PARTKEY, PS_SUPPKEY, range: decided by [eq(Column#1, Column#7)], keep order:false + └─TableReader_57 400000.00 root data:Selection_56 + └─Selection_56 400000.00 cop like(Column#22, "%Customer%Complaints%", 92) + └─TableScan_55 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false /* Q17 Small-Quantity-Order Revenue Query This query determines how much average yearly revenue would be lost if orders were no longer filled for small @@ -971,18 +971,18 @@ l_partkey = p_partkey id count task operator info Projection_16 1.00 root div(Column#46, 7.0) └─StreamAgg_21 1.00 root funcs:sum(Column#6) - └─Projection_49 293773.83 root Column#2, Column#5, Column#6, Column#18, Column#21, Column#24, mul(0.2, Column#44) - └─HashRightJoin_51 293773.83 root inner join, inner:HashRightJoin_35, equal:[eq(Column#18, Column#28)], other cond:lt(Column#5, mul(0.2, Column#44)) - ├─HashRightJoin_35 293773.83 root inner join, inner:TableReader_40, equal:[eq(Column#18, Column#2)] - │ ├─TableReader_40 9736.49 root data:Selection_39 - │ │ └─Selection_39 9736.49 cop eq(Column#21, "Brand#44"), eq(Column#24, "WRAP PKG") - │ │ └─TableScan_38 10000000.00 cop table:part, range:[-inf,+inf], keep order:false - │ └─TableReader_37 300005811.00 root data:TableScan_36 - │ └─TableScan_36 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false - └─HashAgg_45 9943040.00 root group by:Column#53, funcs:avg(Column#50, Column#51), firstrow(Column#53) - └─TableReader_46 9943040.00 root data:HashAgg_41 - └─HashAgg_41 9943040.00 cop group by:Column#28, funcs:count(Column#31), sum(Column#31) - └─TableScan_44 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + └─Projection_51 293773.83 root Column#2, Column#5, Column#6, Column#18, Column#21, Column#24, mul(0.2, Column#44) + └─HashRightJoin_53 293773.83 root inner join, inner:HashRightJoin_37, equal:[eq(Column#18, Column#28)], other cond:lt(Column#5, mul(0.2, Column#44)) + ├─HashRightJoin_37 293773.83 root inner join, inner:TableReader_42, equal:[eq(Column#18, Column#2)] + │ ├─TableReader_42 9736.49 root data:Selection_41 + │ │ └─Selection_41 9736.49 cop eq(Column#21, "Brand#44"), eq(Column#24, "WRAP PKG") + │ │ └─TableScan_40 10000000.00 cop table:part, range:[-inf,+inf], keep order:false + │ └─TableReader_39 300005811.00 root data:TableScan_38 + │ └─TableScan_38 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + └─HashAgg_47 9943040.00 root group by:Column#53, funcs:avg(Column#50, Column#51), firstrow(Column#53) + └─TableReader_48 9943040.00 root data:HashAgg_43 + └─HashAgg_43 9943040.00 cop group by:Column#28, funcs:count(Column#31), sum(Column#31) + └─TableScan_46 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false /* Q18 Large Volume Customer Query The Large Volume Customer Query ranks customers based on their having placed a large quantity order. Large @@ -1029,20 +1029,20 @@ id count task operator info Projection_24 100.00 root Column#2, Column#1, Column#9, Column#13, Column#12, Column#57 └─TopN_27 100.00 root Column#12:desc, Column#13:asc, offset:0, count:100 └─HashAgg_33 59251097.60 root group by:Column#1, Column#12, Column#13, Column#2, Column#9, funcs:sum(Column#22), firstrow(Column#1), firstrow(Column#2), firstrow(Column#9), firstrow(Column#12), firstrow(Column#13) - └─HashRightJoin_45 240004648.80 root inner join, inner:HashLeftJoin_46, equal:[eq(Column#9, Column#18)] - ├─HashLeftJoin_46 59251097.60 root inner join, inner:Selection_61, equal:[eq(Column#9, Column#35)] - │ ├─HashRightJoin_56 75000000.00 root inner join, inner:TableReader_60, equal:[eq(Column#1, Column#10)] - │ │ ├─TableReader_60 7500000.00 root data:TableScan_59 - │ │ │ └─TableScan_59 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false - │ │ └─TableReader_58 75000000.00 root data:TableScan_57 - │ │ └─TableScan_57 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false - │ └─Selection_61 59251097.60 root gt(Column#52, 314) - │ └─HashAgg_68 74063872.00 root group by:Column#68, funcs:sum(Column#66), firstrow(Column#68) - │ └─TableReader_69 74063872.00 root data:HashAgg_62 - │ └─HashAgg_62 74063872.00 cop group by:Column#35, funcs:sum(Column#39) - │ └─TableScan_67 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false - └─TableReader_77 300005811.00 root data:TableScan_76 - └─TableScan_76 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + └─HashRightJoin_47 240004648.80 root inner join, inner:HashLeftJoin_48, equal:[eq(Column#9, Column#18)] + ├─HashLeftJoin_48 59251097.60 root inner join, inner:Selection_65, equal:[eq(Column#9, Column#35)] + │ ├─HashRightJoin_60 75000000.00 root inner join, inner:TableReader_64, equal:[eq(Column#1, Column#10)] + │ │ ├─TableReader_64 7500000.00 root data:TableScan_63 + │ │ │ └─TableScan_63 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false + │ │ └─TableReader_62 75000000.00 root data:TableScan_61 + │ │ └─TableScan_61 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false + │ └─Selection_65 59251097.60 root gt(Column#52, 314) + │ └─HashAgg_72 74063872.00 root group by:Column#68, funcs:sum(Column#66), firstrow(Column#68) + │ └─TableReader_73 74063872.00 root data:HashAgg_66 + │ └─HashAgg_66 74063872.00 cop group by:Column#35, funcs:sum(Column#39) + │ └─TableScan_71 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + └─TableReader_81 300005811.00 root data:TableScan_80 + └─TableScan_80 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 @@ -1090,14 +1090,14 @@ and l_shipinstruct = 'DELIVER IN PERSON' ); id count task operator info StreamAgg_13 1.00 root funcs:sum(Column#0) -└─Projection_42 6286493.79 root mul(Column#6, minus(1, Column#7)) - └─IndexMergeJoin_39 6286493.79 root inner join, inner:TableReader_37, outer key:Column#2, inner key:Column#18, other cond:or(and(and(eq(Column#21, "Brand#52"), in(Column#24, "SM CASE", "SM BOX", "SM PACK", "SM PKG")), and(ge(Column#5, 4), and(le(Column#5, 14), le(Column#23, 5)))), or(and(and(eq(Column#21, "Brand#11"), in(Column#24, "MED BAG", "MED BOX", "MED PKG", "MED PACK")), and(ge(Column#5, 18), and(le(Column#5, 28), le(Column#23, 10)))), and(and(eq(Column#21, "Brand#51"), in(Column#24, "LG CASE", "LG BOX", "LG PACK", "LG PKG")), and(ge(Column#5, 29), and(le(Column#5, 39), le(Column#23, 15)))))) - ├─TableReader_27 6286493.79 root data:Selection_26 - │ └─Selection_26 6286493.79 cop eq(Column#14, "DELIVER IN PERSON"), in(Column#15, "AIR", "AIR REG"), or(and(ge(Column#5, 4), le(Column#5, 14)), or(and(ge(Column#5, 18), le(Column#5, 28)), and(ge(Column#5, 29), le(Column#5, 39)))) - │ └─TableScan_25 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false - └─TableReader_37 0.80 root data:Selection_36 - └─Selection_36 0.80 cop ge(Column#23, 1), or(and(eq(Column#21, "Brand#52"), and(in(Column#24, "SM CASE", "SM BOX", "SM PACK", "SM PKG"), le(Column#23, 5))), or(and(eq(Column#21, "Brand#11"), and(in(Column#24, "MED BAG", "MED BOX", "MED PKG", "MED PACK"), le(Column#23, 10))), and(eq(Column#21, "Brand#51"), and(in(Column#24, "LG CASE", "LG BOX", "LG PACK", "LG PKG"), le(Column#23, 15))))) - └─TableScan_35 1.00 cop table:part, range: decided by [Column#2], keep order:true +└─Projection_46 6286493.79 root mul(Column#6, minus(1, Column#7)) + └─IndexHashJoin_43 6286493.79 root inner join, inner:TableReader_35, outer key:Column#2, inner key:Column#18, other cond:or(and(and(eq(Column#21, "Brand#52"), in(Column#24, "SM CASE", "SM BOX", "SM PACK", "SM PKG")), and(ge(Column#5, 4), and(le(Column#5, 14), le(Column#23, 5)))), or(and(and(eq(Column#21, "Brand#11"), in(Column#24, "MED BAG", "MED BOX", "MED PKG", "MED PACK")), and(ge(Column#5, 18), and(le(Column#5, 28), le(Column#23, 10)))), and(and(eq(Column#21, "Brand#51"), in(Column#24, "LG CASE", "LG BOX", "LG PACK", "LG PKG")), and(ge(Column#5, 29), and(le(Column#5, 39), le(Column#23, 15)))))) + ├─TableReader_29 6286493.79 root data:Selection_28 + │ └─Selection_28 6286493.79 cop eq(Column#14, "DELIVER IN PERSON"), in(Column#15, "AIR", "AIR REG"), or(and(ge(Column#5, 4), le(Column#5, 14)), or(and(ge(Column#5, 18), le(Column#5, 28)), and(ge(Column#5, 29), le(Column#5, 39)))) + │ └─TableScan_27 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + └─TableReader_35 0.80 root data:Selection_34 + └─Selection_34 0.80 cop ge(Column#23, 1), or(and(eq(Column#21, "Brand#52"), and(in(Column#24, "SM CASE", "SM BOX", "SM PACK", "SM PKG"), le(Column#23, 5))), or(and(eq(Column#21, "Brand#11"), and(in(Column#24, "MED BAG", "MED BOX", "MED PKG", "MED PACK"), le(Column#23, 10))), and(eq(Column#21, "Brand#51"), and(in(Column#24, "LG CASE", "LG BOX", "LG PACK", "LG PKG"), le(Column#23, 15))))) + └─TableScan_33 1.00 cop table:part, range: decided by [Column#2], keep order:false /* Q20 Potential Part Promotion Query The Potential Part Promotion Query identifies suppliers in a particular nation having selected parts that may be candidates @@ -1147,28 +1147,28 @@ s_name; id count task operator info Sort_28 20000.00 root Column#48:asc └─Projection_30 20000.00 root Column#2, Column#3 - └─HashRightJoin_32 20000.00 root inner join, inner:HashRightJoin_43, equal:[eq(Column#1, Column#13)] - ├─HashRightJoin_43 20000.00 root inner join, inner:TableReader_48, equal:[eq(Column#8, Column#4)] - │ ├─TableReader_48 1.00 root data:Selection_47 - │ │ └─Selection_47 1.00 cop eq(Column#9, "ALGERIA") - │ │ └─TableScan_46 25.00 cop table:nation, range:[-inf,+inf], keep order:false - │ └─TableReader_45 500000.00 root data:TableScan_44 - │ └─TableScan_44 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false - └─HashAgg_51 64006.34 root group by:Column#13, funcs:firstrow(Column#13) - └─Projection_52 64006.34 root Column#12, Column#13, Column#14, Column#18, mul(0.5, Column#45) - └─Selection_53 64006.34 root gt(cast(Column#14), mul(0.5, Column#45)) - └─HashAgg_56 80007.93 root group by:Column#12, Column#13, funcs:firstrow(Column#12), firstrow(Column#13), firstrow(Column#14), firstrow(Column#18), sum(Column#32) - └─HashLeftJoin_59 9711455.06 root left outer join, inner:TableReader_86, equal:[eq(Column#12, Column#29) eq(Column#13, Column#30)] - ├─IndexMergeJoin_69 321865.05 root inner join, inner:IndexLookUp_67, outer key:Column#18, inner key:Column#12 - │ ├─TableReader_81 80007.93 root data:Selection_80 - │ │ └─Selection_80 80007.93 cop like(Column#19, "green%", 92) - │ │ └─TableScan_79 10000000.00 cop table:part, range:[-inf,+inf], keep order:false - │ └─IndexLookUp_67 4.02 root - │ ├─IndexScan_65 4.02 cop table:partsupp, index:PS_PARTKEY, PS_SUPPKEY, range: decided by [eq(Column#12, Column#18)], keep order:true - │ └─TableScan_66 4.02 cop table:partsupp, keep order:false - └─TableReader_86 44189356.65 root data:Selection_85 - └─Selection_85 44189356.65 cop ge(Column#38, 1993-01-01 00:00:00.000000), lt(Column#38, 1994-01-01) - └─TableScan_84 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false + └─HashRightJoin_32 20000.00 root inner join, inner:HashRightJoin_45, equal:[eq(Column#1, Column#13)] + ├─HashRightJoin_45 20000.00 root inner join, inner:TableReader_50, equal:[eq(Column#8, Column#4)] + │ ├─TableReader_50 1.00 root data:Selection_49 + │ │ └─Selection_49 1.00 cop eq(Column#9, "ALGERIA") + │ │ └─TableScan_48 25.00 cop table:nation, range:[-inf,+inf], keep order:false + │ └─TableReader_47 500000.00 root data:TableScan_46 + │ └─TableScan_46 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false + └─HashAgg_53 64006.34 root group by:Column#13, funcs:firstrow(Column#13) + └─Projection_54 64006.34 root Column#12, Column#13, Column#14, Column#18, mul(0.5, Column#45) + └─Selection_55 64006.34 root gt(cast(Column#14), mul(0.5, Column#45)) + └─HashAgg_58 80007.93 root group by:Column#12, Column#13, funcs:firstrow(Column#12), firstrow(Column#13), firstrow(Column#14), firstrow(Column#18), sum(Column#32) + └─HashLeftJoin_61 9711455.06 root left outer join, inner:TableReader_90, equal:[eq(Column#12, Column#29) eq(Column#13, Column#30)] + ├─IndexHashJoin_73 321865.05 root inner join, inner:IndexLookUp_65, outer key:Column#18, inner key:Column#12 + │ ├─TableReader_85 80007.93 root data:Selection_84 + │ │ └─Selection_84 80007.93 cop like(Column#19, "green%", 92) + │ │ └─TableScan_83 10000000.00 cop table:part, range:[-inf,+inf], keep order:false + │ └─IndexLookUp_65 4.02 root + │ ├─IndexScan_63 4.02 cop table:partsupp, index:PS_PARTKEY, PS_SUPPKEY, range: decided by [eq(Column#12, Column#18)], keep order:false + │ └─TableScan_64 4.02 cop table:partsupp, keep order:false + └─TableReader_90 44189356.65 root data:Selection_89 + └─Selection_89 44189356.65 cop ge(Column#38, 1993-01-01 00:00:00.000000), lt(Column#38, 1994-01-01) + └─TableScan_88 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. @@ -1221,25 +1221,25 @@ id count task operator info Projection_25 1.00 root Column#2, Column#104 └─TopN_28 1.00 root Column#104:desc, Column#2:asc, offset:0, count:100 └─HashAgg_34 1.00 root group by:Column#2, funcs:count(1), firstrow(Column#2) - └─IndexJoin_40 7828961.66 root anti semi join, inner:IndexLookUp_39, outer key:Column#8, inner key:Column#71, other cond:ne(Column#73, Column#1), ne(Column#73, Column#10) - ├─IndexJoin_72 9786202.08 root semi join, inner:IndexLookUp_71, outer key:Column#8, inner key:Column#38, other cond:ne(Column#40, Column#1), ne(Column#40, Column#10) - │ ├─IndexMergeJoin_88 12232752.60 root inner join, inner:TableReader_86, outer key:Column#8, inner key:Column#25 - │ │ ├─HashRightJoin_92 12232752.60 root inner join, inner:HashRightJoin_103, equal:[eq(Column#1, Column#10)] - │ │ │ ├─HashRightJoin_103 20000.00 root inner join, inner:TableReader_108, equal:[eq(Column#34, Column#4)] - │ │ │ │ ├─TableReader_108 1.00 root data:Selection_107 - │ │ │ │ │ └─Selection_107 1.00 cop eq(Column#35, "EGYPT") - │ │ │ │ │ └─TableScan_106 25.00 cop table:nation, range:[-inf,+inf], keep order:false - │ │ │ │ └─TableReader_105 500000.00 root data:TableScan_104 - │ │ │ │ └─TableScan_104 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false - │ │ │ └─TableReader_111 240004648.80 root data:Selection_110 - │ │ │ └─Selection_110 240004648.80 cop gt(Column#20, Column#19) - │ │ │ └─TableScan_109 300005811.00 cop table:l1, range:[-inf,+inf], keep order:false + └─IndexHashJoin_48 7828961.66 root anti semi join, inner:IndexLookUp_39, outer key:Column#8, inner key:Column#71, other cond:ne(Column#73, Column#1), ne(Column#73, Column#10) + ├─IndexHashJoin_81 9786202.08 root semi join, inner:IndexLookUp_73, outer key:Column#8, inner key:Column#38, other cond:ne(Column#40, Column#1), ne(Column#40, Column#10) + │ ├─IndexHashJoin_94 12232752.60 root inner join, inner:TableReader_86, outer key:Column#8, inner key:Column#25 + │ │ ├─HashRightJoin_98 12232752.60 root inner join, inner:HashRightJoin_111, equal:[eq(Column#1, Column#10)] + │ │ │ ├─HashRightJoin_111 20000.00 root inner join, inner:TableReader_116, equal:[eq(Column#34, Column#4)] + │ │ │ │ ├─TableReader_116 1.00 root data:Selection_115 + │ │ │ │ │ └─Selection_115 1.00 cop eq(Column#35, "EGYPT") + │ │ │ │ │ └─TableScan_114 25.00 cop table:nation, range:[-inf,+inf], 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_119 240004648.80 root data:Selection_118 + │ │ │ └─Selection_118 240004648.80 cop gt(Column#20, Column#19) + │ │ │ └─TableScan_117 300005811.00 cop table:l1, range:[-inf,+inf], keep order:false │ │ └─TableReader_86 0.80 root data:Selection_85 │ │ └─Selection_85 0.80 cop eq(Column#27, "F") - │ │ └─TableScan_84 1.00 cop table:orders, range: decided by [Column#8], keep order:true - │ └─IndexLookUp_71 4.05 root - │ ├─IndexScan_69 4.05 cop table:l2, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#38, Column#8)], keep order:false - │ └─TableScan_70 4.05 cop table:l2, keep order:false + │ │ └─TableScan_84 1.00 cop table:orders, range: decided by [Column#8], keep order:false + │ └─IndexLookUp_73 4.05 root + │ ├─IndexScan_71 4.05 cop table:l2, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#38, Column#8)], keep order:false + │ └─TableScan_72 4.05 cop table:l2, keep order:false └─IndexLookUp_39 3.24 root ├─IndexScan_36 4.05 cop table:l3, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#71, Column#8)], keep order:false └─Selection_38 3.24 cop gt(Column#83, Column#82) diff --git a/executor/builder.go b/executor/builder.go index 704663ecca92b..f1fbbdc6078fa 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -174,6 +174,8 @@ func (b *executorBuilder) build(p plannercore.Plan) Executor { return b.buildIndexLookUpJoin(v) case *plannercore.PhysicalIndexMergeJoin: return b.buildIndexLookUpMergeJoin(v) + case *plannercore.PhysicalIndexHashJoin: + return b.buildIndexNestedLoopHashJoin(v) case *plannercore.PhysicalSelection: return b.buildSelection(v) case *plannercore.PhysicalHashAgg: @@ -1806,16 +1808,7 @@ func (b *executorBuilder) buildIndexLookUpJoin(v *plannercore.PhysicalIndexJoin) e.innerCtx.keyCols = innerKeyCols e.joinResult = newFirstChunk(e) executorCounterIndexLookUpJoin.Inc() - if v.KeepOuterOrder { - return e - } - idxHash := &IndexNestedLoopHashJoin{IndexLookUpJoin: *e} - concurrency := e.ctx.GetSessionVars().IndexLookupJoinConcurrency - idxHash.joiners = make([]joiner, concurrency) - for i := 0; i < concurrency; i++ { - idxHash.joiners[i] = newJoiner(b.ctx, v.JoinType, v.InnerChildIdx == 0, defaultValues, v.OtherConditions, leftTypes, rightTypes) - } - return idxHash + return e } func (b *executorBuilder) buildIndexLookUpMergeJoin(v *plannercore.PhysicalIndexMergeJoin) Executor { @@ -1824,6 +1817,18 @@ func (b *executorBuilder) buildIndexLookUpMergeJoin(v *plannercore.PhysicalIndex return b.buildIndexLookUpJoin(&v.PhysicalIndexJoin) } +func (b *executorBuilder) buildIndexNestedLoopHashJoin(v *plannercore.PhysicalIndexHashJoin) Executor { + e := b.buildIndexLookUpJoin(&(v.PhysicalIndexJoin)).(*IndexLookUpJoin) + idxHash := &IndexNestedLoopHashJoin{IndexLookUpJoin: *e} + concurrency := e.ctx.GetSessionVars().IndexLookupJoinConcurrency + idxHash.joiners = make([]joiner, concurrency) + for i := 0; i < concurrency; i++ { + // TODO: we may need to implement a Clone for joiner + idxHash.joiners[i] = e.joiner.Clone() + } + return idxHash +} + // containsLimit tests if the execs contains Limit because we do not know whether `Limit` has consumed all of its' source, // so the feedback may not be accurate. func containsLimit(execs []*tipb.Executor) bool { diff --git a/executor/joiner.go b/executor/joiner.go index abb8881b9ff2b..69ac3fe9c52ea 100644 --- a/executor/joiner.go +++ b/executor/joiner.go @@ -92,6 +92,9 @@ type joiner interface { // it decides if this outer row should be outputted, hence we have a `hasNull` // parameter passed to `onMissMatch`. onMissMatch(hasNull bool, outer chunk.Row, chk *chunk.Chunk) + + // Clone deep copies a joiner. + Clone() joiner } func newJoiner(ctx sessionctx.Context, joinType plannercore.JoinType, @@ -228,6 +231,29 @@ func (j *baseJoiner) filterAndCheckOuterRowStatus(input, output *chunk.Chunk, in return outerRowStatus, err } +func (j *baseJoiner) Clone() baseJoiner { + base := baseJoiner{ + ctx: j.ctx, + conditions: make([]expression.Expression, 0, len(j.conditions)), + outerIsRight: j.outerIsRight, + maxChunkSize: j.maxChunkSize, + selected: make([]bool, 0, len(j.selected)), + isNull: make([]bool, 0, len(j.isNull)), + } + for _, con := range j.conditions { + base.conditions = append(base.conditions, con.Clone()) + } + if j.chk != nil { + base.chk = j.chk.CopyConstruct() + } else { + base.shallowRow = chunk.MutRow(j.shallowRow.ToRow()) + } + if !j.defaultInner.IsEmpty() { + base.defaultInner = j.defaultInner.CopyConstruct() + } + return base +} + type semiJoiner struct { baseJoiner } @@ -289,6 +315,9 @@ func (j *semiJoiner) tryToMatchOuters(outers chunk.Iterator, inner chunk.Row, ch func (j *semiJoiner) onMissMatch(_ bool, outer chunk.Row, chk *chunk.Chunk) { } +func (j *semiJoiner) Clone() joiner { + return &semiJoiner{baseJoiner: j.baseJoiner.Clone()} +} type antiSemiJoiner struct { baseJoiner @@ -353,6 +382,10 @@ func (j *antiSemiJoiner) onMissMatch(hasNull bool, outer chunk.Row, chk *chunk.C } } +func (j *antiSemiJoiner) Clone() joiner { + return &antiSemiJoiner{baseJoiner: j.baseJoiner.Clone()} +} + type leftOuterSemiJoiner struct { baseJoiner } @@ -429,6 +462,10 @@ func (j *leftOuterSemiJoiner) onMissMatch(hasNull bool, outer chunk.Row, chk *ch } } +func (j *leftOuterSemiJoiner) Clone() joiner { + return &leftOuterSemiJoiner{baseJoiner: j.baseJoiner.Clone()} +} + type antiLeftOuterSemiJoiner struct { baseJoiner } @@ -505,6 +542,10 @@ func (j *antiLeftOuterSemiJoiner) onMissMatch(hasNull bool, outer chunk.Row, chk } } +func (j *antiLeftOuterSemiJoiner) Clone() joiner { + return &antiLeftOuterSemiJoiner{baseJoiner: j.baseJoiner.Clone()} +} + type leftOuterJoiner struct { baseJoiner } @@ -564,6 +605,10 @@ func (j *leftOuterJoiner) onMissMatch(_ bool, outer chunk.Row, chk *chunk.Chunk) chk.AppendPartialRow(outer.Len(), j.defaultInner) } +func (j *leftOuterJoiner) Clone() joiner { + return &leftOuterJoiner{baseJoiner: j.baseJoiner.Clone()} +} + type rightOuterJoiner struct { baseJoiner } @@ -623,6 +668,10 @@ func (j *rightOuterJoiner) onMissMatch(_ bool, outer chunk.Row, chk *chunk.Chunk chk.AppendPartialRow(j.defaultInner.Len(), outer) } +func (j *rightOuterJoiner) Clone() joiner { + return &rightOuterJoiner{baseJoiner: j.baseJoiner.Clone()} +} + type innerJoiner struct { baseJoiner } @@ -684,3 +733,7 @@ func (j *innerJoiner) tryToMatchOuters(outers chunk.Iterator, inner chunk.Row, c func (j *innerJoiner) onMissMatch(_ bool, outer chunk.Row, chk *chunk.Chunk) { } + +func (j *innerJoiner) Clone() joiner { + return &innerJoiner{baseJoiner: j.baseJoiner.Clone()} +} diff --git a/planner/core/exhaust_physical_plans.go b/planner/core/exhaust_physical_plans.go index fce669dfc5a1e..5f7ec2aad4e67 100644 --- a/planner/core/exhaust_physical_plans.go +++ b/planner/core/exhaust_physical_plans.go @@ -358,7 +358,6 @@ func (p *LogicalJoin) constructIndexJoin( innerTask: innerTask, KeyOff2IdxOff: newKeyOff, Ranges: ranges, - KeepOuterOrder: len(prop.Items) > 0, CompareFilters: compareFilters, }.Init(p.ctx, p.stats.ScaleByExpectCnt(prop.ExpectedCnt), p.blockOffset, chReqProps...) if path != nil { @@ -415,6 +414,32 @@ func (p *LogicalJoin) constructIndexMergeJoin( return indexMergeJoins } +func (p *LogicalJoin) constructIndexHashJoin( + prop *property.PhysicalProperty, + outerIdx int, + innerTask task, + ranges []*ranger.Range, + keyOff2IdxOff []int, + path *accessPath, + compareFilters *ColWithCmpFuncManager, +) []PhysicalPlan { + // TODO(xuhuaiyu): support keep outer order for indexHashJoin. + if keepOuterOrder := len(prop.Items) > 0; keepOuterOrder { + return nil + } + indexJoins := p.constructIndexJoin(prop, outerIdx, innerTask, ranges, keyOff2IdxOff, path, compareFilters) + indexHashJoins := make([]PhysicalPlan, 0, len(indexJoins)) + for _, plan := range indexJoins { + join := plan.(*PhysicalIndexJoin) + indexHashJoin := PhysicalIndexHashJoin{ + PhysicalIndexJoin: *join, + keepOuterOrder: false, + }.Init(p.ctx) + indexHashJoins = append(indexHashJoins, indexHashJoin) + } + return indexHashJoins +} + // getIndexJoinByOuterIdx will generate index join by outerIndex. OuterIdx points out the outer child. // First of all, we'll check whether the inner child is DataSource. // Then, we will extract the join keys of p's equal conditions. Then check whether all of them are just the primary key @@ -495,13 +520,16 @@ func (p *LogicalJoin) buildIndexJoinInner2TableScan( if !pkMatched { return nil } - joins = make([]PhysicalPlan, 0, 2) + joins = make([]PhysicalPlan, 0, 3) innerTask := p.constructInnerTableScanTask(ds, pkCol, outerJoinKeys, us, false, avgInnerRowCnt) joins = append(joins, p.constructIndexJoin(prop, outerIdx, innerTask, nil, keyOff2IdxOff, nil, nil)...) // The index merge join's inner plan is different from index join, so we // should construct another inner plan for it. innerTask2 := p.constructInnerTableScanTask(ds, pkCol, outerJoinKeys, us, true, avgInnerRowCnt) joins = append(joins, p.constructIndexMergeJoin(prop, outerIdx, innerTask2, nil, keyOff2IdxOff, nil, nil)...) + // We can reuse the `innerTask` here since index nested loop hash join + // do not need the inner child to promise the order. + joins = append(joins, p.constructIndexHashJoin(prop, outerIdx, innerTask, nil, keyOff2IdxOff, nil, nil)...) return joins } @@ -542,6 +570,9 @@ func (p *LogicalJoin) buildIndexJoinInner2IndexScan( // should construct another inner plan for it. innerTask2 := p.constructInnerIndexScanTask(ds, helper.chosenPath, helper.chosenRemained, outerJoinKeys, us, rangeInfo, true, avgInnerRowCnt) joins = append(joins, p.constructIndexMergeJoin(prop, outerIdx, innerTask2, helper.chosenRanges, keyOff2IdxOff, helper.chosenPath, helper.lastColManager)...) + // We can reuse the `innerTask` here since index nested loop hash join + // do not need the inner child to promise the order. + joins = append(joins, p.constructIndexHashJoin(prop, outerIdx, innerTask, helper.chosenRanges, keyOff2IdxOff, helper.chosenPath, helper.lastColManager)...) return joins } diff --git a/planner/core/initialize.go b/planner/core/initialize.go index 6f00edbaf10fd..99bbde2299ac7 100644 --- a/planner/core/initialize.go +++ b/planner/core/initialize.go @@ -59,8 +59,10 @@ const ( TypeMergeJoin = "MergeJoin" // TypeIndexJoin is the type of index look up join. TypeIndexJoin = "IndexJoin" - // TypeIndexMergeJoin is the type of index look up merge join. + // TypeIndexMergeJoin is the type of index nested loop merge join. TypeIndexMergeJoin = "IndexMergeJoin" + // TypeIndexHashJoin is the type of index nested loop hash join. + TypeIndexHashJoin = "IndexHashJoin" // TypeApply is the type of Apply. TypeApply = "Apply" // TypeMaxOneRow is the type of MaxOneRow. @@ -472,6 +474,15 @@ func (p PhysicalIndexMergeJoin) Init(ctx sessionctx.Context) *PhysicalIndexMerge return &p } +// Init initializes PhysicalIndexHashJoin. +func (p PhysicalIndexHashJoin) Init(ctx sessionctx.Context) *PhysicalIndexHashJoin { + ctx.GetSessionVars().PlanID++ + p.tp = TypeIndexHashJoin + p.id = ctx.GetSessionVars().PlanID + p.ctx = ctx + return &p +} + // flattenPushDownPlan converts a plan tree to a list, whose head is the leaf node like table scan. func flattenPushDownPlan(p PhysicalPlan) []PhysicalPlan { plans := make([]PhysicalPlan, 0, 5) diff --git a/planner/core/physical_plans.go b/planner/core/physical_plans.go index 693f1e0c982a7..3695a8a5cbf5e 100644 --- a/planner/core/physical_plans.go +++ b/planner/core/physical_plans.go @@ -266,9 +266,6 @@ type PhysicalIndexJoin struct { Ranges []*ranger.Range // KeyOff2IdxOff maps the offsets in join key to the offsets in the index. KeyOff2IdxOff []int - // KeepOuterOrder indicates whether to keep the order of the join results be - // the same as the outer table. - KeepOuterOrder bool // IdxColLens stores the length of each index column. IdxColLens []int // CompareFilters stores the filters for last column if those filters need to be evaluated during execution. @@ -292,6 +289,14 @@ type PhysicalIndexMergeJoin struct { OuterCompareFuncs []expression.CompareFunc } +// PhysicalIndexHashJoin represents the plan of index look up hash join. +type PhysicalIndexHashJoin struct { + PhysicalIndexJoin + // keepOuterOrder indicates whether keeping the output result order as the + // outer side. + keepOuterOrder bool +} + // PhysicalMergeJoin represents merge join implementation of LogicalJoin. type PhysicalMergeJoin struct { basePhysicalJoin diff --git a/planner/core/stringer.go b/planner/core/stringer.go index 34aedf991bf5c..32a71833661c9 100644 --- a/planner/core/stringer.go +++ b/planner/core/stringer.go @@ -203,6 +203,18 @@ func toString(in Plan, strs []string, idxs []int) ([]string, []int) { r := x.InnerJoinKeys[i] str += fmt.Sprintf("(%s,%s)", l, r) } + case *PhysicalIndexHashJoin: + last := len(idxs) - 1 + idx := idxs[last] + children := strs[idx:] + strs = strs[:idx] + idxs = idxs[:last] + str = "IndexHashJoin{" + strings.Join(children, "->") + "}" + for i := range x.OuterJoinKeys { + l := x.OuterJoinKeys[i] + r := x.InnerJoinKeys[i] + str += fmt.Sprintf("(%s,%s)", l, r) + } case *Analyze: str = "Analyze{" var children []string diff --git a/planner/core/task.go b/planner/core/task.go index 3074ece7d5e46..50a65b140673b 100644 --- a/planner/core/task.go +++ b/planner/core/task.go @@ -240,6 +240,72 @@ func (p *PhysicalIndexMergeJoin) GetCost(outerTask, innerTask task) float64 { return outerTask.cost() + innerPlanCost + cpuCost + memoryCost } +func (p *PhysicalIndexHashJoin) attach2Task(tasks ...task) task { + innerTask := p.innerTask + outerTask := finishCopTask(p.ctx, tasks[1-p.InnerChildIdx].copy()) + if p.InnerChildIdx == 1 { + p.SetChildren(outerTask.plan(), innerTask.plan()) + } else { + p.SetChildren(innerTask.plan(), outerTask.plan()) + } + p.schema = buildPhysicalJoinSchema(p.JoinType, p) + return &rootTask{ + p: p, + cst: p.GetCost(outerTask, innerTask), + } +} + +// GetCost computes the cost of index merge join operator and its children. +func (p *PhysicalIndexHashJoin) GetCost(outerTask, innerTask task) float64 { + var cpuCost float64 + outerCnt, innerCnt := outerTask.count(), innerTask.count() + // Add the cost of evaluating outer filter, since inner filter of index join + // is always empty, we can simply tell whether outer filter is empty using the + // summed length of left/right conditions. + if len(p.LeftConditions)+len(p.RightConditions) > 0 { + cpuCost += CPUFactor * outerCnt + outerCnt *= selectionFactor + } + // Cost of extracting lookup keys. + innerCPUCost := CPUFactor * outerCnt + // Cost of sorting and removing duplicate lookup keys: + // (outerCnt / batchSize) * (batchSize * Log2(batchSize) + batchSize) * CPUFactor + batchSize := math.Min(float64(p.ctx.GetSessionVars().IndexJoinBatchSize), outerCnt) + if batchSize > 2 { + innerCPUCost += outerCnt * (math.Log2(batchSize) + 1) * CPUFactor + } + // Add cost of building inner executors. CPU cost of building copTasks: + // (outerCnt / batchSize) * (batchSize * distinctFactor) * CPUFactor + // Since we don't know the number of copTasks built, ignore these network cost now. + innerCPUCost += outerCnt * distinctFactor * CPUFactor + concurrency := float64(p.ctx.GetSessionVars().IndexLookupJoinConcurrency) + cpuCost += innerCPUCost / concurrency + // CPU cost of building hash table for outer results concurrently. + // (outerCnt / batchSize) * (batchSize * CPUFactor) + outerCPUCost := outerCnt * CPUFactor + cpuCost += outerCPUCost / concurrency + // Cost of probing hash table concurrently. + numPairs := outerCnt * innerCnt + if p.JoinType == SemiJoin || p.JoinType == AntiSemiJoin || + p.JoinType == LeftOuterSemiJoin || p.JoinType == AntiLeftOuterSemiJoin { + if len(p.OtherConditions) > 0 { + numPairs *= 0.5 + } else { + numPairs = 0 + } + } + probeCost := numPairs * CPUFactor / concurrency + cpuCost += probeCost + // Cost of additional concurrent goroutines. + cpuCost += (concurrency + 1.0) * concurrencyFactor + // Memory cost of hash tables for outer rows. The computed result is the upper bound, + // since the executor is pipelined and not all workers are always in full load. + memoryCost := concurrency * (batchSize * distinctFactor) * innerCnt * memoryFactor + // Cost of inner child plan, i.e, mainly I/O and network cost. + innerPlanCost := outerCnt * innerTask.cost() + return outerTask.cost() + innerPlanCost + cpuCost + memoryCost +} + func (p *PhysicalIndexJoin) attach2Task(tasks ...task) task { innerTask := p.innerTask outerTask := finishCopTask(p.ctx, tasks[1-p.InnerChildIdx].copy()) diff --git a/planner/core/testdata/analyze_suite_out.json b/planner/core/testdata/analyze_suite_out.json index b229d8f98f86a..ef6c902d49ff7 100644 --- a/planner/core/testdata/analyze_suite_out.json +++ b/planner/core/testdata/analyze_suite_out.json @@ -47,13 +47,13 @@ ], "Plan": [ "Limit_17 1.00 root offset:0, count:1", - "└─IndexMergeJoin_68 1.00 root left outer semi join, inner:IndexReader_66, outer key:Column#1, inner key:Column#8", - " ├─TopN_27 1.00 root Column#1:asc, offset:0, count:1", - " │ └─IndexReader_35 1.00 root index:TopN_34", - " │ └─TopN_34 1.00 cop Column#1:asc, offset:0, count:1", - " │ └─IndexScan_33 6.00 cop table:t1, index:b, c, range:[-inf,6], keep order:false", - " └─IndexReader_66 1.04 root index:IndexScan_65", - " └─IndexScan_65 1.04 cop table:t2, index:b, c, range: decided by [eq(Column#8, Column#1)], keep order:true" + "└─IndexMergeJoin_70 1.00 root left outer semi join, inner:IndexReader_68, outer key:Column#1, inner key:Column#8", + " ├─TopN_29 1.00 root Column#1:asc, offset:0, count:1", + " │ └─IndexReader_37 1.00 root index:TopN_36", + " │ └─TopN_36 1.00 cop Column#1:asc, offset:0, count:1", + " │ └─IndexScan_35 6.00 cop table:t1, index:b, c, range:[-inf,6], keep order:false", + " └─IndexReader_68 1.04 root index:IndexScan_67", + " └─IndexScan_67 1.04 cop table:t2, index:b, c, range: decided by [eq(Column#8, Column#1)], keep order:true" ] }, { diff --git a/planner/core/testdata/plan_suite_out.json b/planner/core/testdata/plan_suite_out.json index 5b7bb38f5bde5..7f4a316ffa8dc 100644 --- a/planner/core/testdata/plan_suite_out.json +++ b/planner/core/testdata/plan_suite_out.json @@ -213,7 +213,7 @@ }, { "SQL": "select * from (select * from t use index() order by b) t left join t t1 on t.a=t1.a limit 10", - "Best": "IndexMergeJoin{TableReader(Table(t)->TopN([Column#2],0,10))->TopN([Column#2],0,10)->TableReader(Table(t))}(Column#1,Column#25)->Limit" + "Best": "IndexHashJoin{TableReader(Table(t)->TopN([Column#2],0,10))->TopN([Column#2],0,10)->TableReader(Table(t))}(Column#1,Column#25)->Limit" }, { "SQL": "select * from ((SELECT 1 a,3 b) UNION (SELECT 2,1) ORDER BY (SELECT 2)) t order by a,b", @@ -274,11 +274,11 @@ }, { "SQL": "select * from t t1 left join t t2 on t1.b = t2.a where 1 = 1 limit 1", - "Best": "IndexMergeJoin{TableReader(Table(t)->Limit)->Limit->TableReader(Table(t))}(Column#2,Column#13)->Limit" + "Best": "IndexHashJoin{TableReader(Table(t)->Limit)->Limit->TableReader(Table(t))}(Column#2,Column#13)->Limit" }, { "SQL": "select * from t t1 join t t2 on t1.b = t2.a and t1.c = 1 and t1.d = 1 and t1.e = 1 order by t1.a limit 1", - "Best": "IndexMergeJoin{IndexLookUp(Index(t.c_d_e)[[1 1 1,1 1 1]], Table(t))->TableReader(Table(t))}(Column#2,Column#13)->TopN([Column#1],0,1)" + "Best": "IndexHashJoin{IndexLookUp(Index(t.c_d_e)[[1 1 1,1 1 1]], Table(t))->TableReader(Table(t))}(Column#2,Column#13)->TopN([Column#1],0,1)" }, { "SQL": "select * from t t1 join t t2 on t1.b = t2.b join t t3 on t1.b = t3.b", @@ -294,7 +294,7 @@ }, { "SQL": "select * from t t1 join t t2 on t1.a = t2.a join t t3 on t1.a = t3.a and t1.b = 1 and t3.c = 1", - "Best": "IndexMergeJoin{IndexMergeJoin{TableReader(Table(t)->Sel([eq(Column#2, 1)]))->IndexLookUp(Index(t.c_d_e)[[1,1]], Table(t))}(Column#25,Column#1)->TableReader(Table(t))}(Column#1,Column#13)->Projection" + "Best": "IndexHashJoin{IndexHashJoin{TableReader(Table(t)->Sel([eq(Column#2, 1)]))->IndexLookUp(Index(t.c_d_e)[[1,1]], Table(t))}(Column#25,Column#1)->TableReader(Table(t))}(Column#1,Column#13)->Projection" }, { "SQL": "select * from t where t.c in (select b from t s where s.a = t.a)", @@ -354,15 +354,15 @@ }, { "SQL": "select /*+ TIDB_INLJ(t1, t2) */ * from t t1, t t2 where t1.a = t2.a", - "Best": "IndexMergeJoin{TableReader(Table(t))->TableReader(Table(t))}(Column#1,Column#13)" + "Best": "IndexHashJoin{TableReader(Table(t))->TableReader(Table(t))}(Column#1,Column#13)" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.c", - "Best": "IndexMergeJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(Column#1,Column#15)" + "Best": "IndexHashJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(Column#1,Column#15)" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ t1.a , t2.a from t t1, t t2 where t1.a = t2.c", - "Best": "IndexMergeJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#1,Column#15)->Projection" + "Best": "IndexHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#1,Column#15)->Projection" }, { "SQL": "select /*+ TIDB_INLJ(t1, t2) */ t1.a, t2.a from t t1, t t2 where t1.a = t2.a order by t1.c", @@ -374,7 +374,7 @@ }, { "SQL": "select /*+ TIDB_INLJ(t1) */ t1.a , t2.a from t t1, t t2 where t1.a = t2.c", - "Best": "IndexMergeJoin{TableReader(Table(t))->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#15,Column#1)->Projection" + "Best": "IndexHashJoin{TableReader(Table(t))->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#15,Column#1)->Projection" }, { "SQL": "select /*+ TIDB_INLJ(t1, t2) */ * from t t1 left outer join t t2 on t1.a = t2.a and t2.b < 1", @@ -398,27 +398,27 @@ }, { "SQL": "select /*+ TIDB_INLJ(t1) */ * from t t1 where t1.a in (select a from t t2)", - "Best": "IndexMergeJoin{TableReader(Table(t))->IndexReader(Index(t.f)[[NULL,+inf]])}(Column#13,Column#1)->Projection" + "Best": "IndexHashJoin{TableReader(Table(t))->IndexReader(Index(t.f)[[NULL,+inf]])}(Column#13,Column#1)->Projection" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.c=t2.c and t1.f=t2.f", - "Best": "IndexMergeJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(Column#3,Column#15)" + "Best": "IndexHashJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(Column#3,Column#15)" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.a = t2.a and t1.f=t2.f", - "Best": "IndexMergeJoin{TableReader(Table(t))->TableReader(Table(t))}(Column#1,Column#13)" + "Best": "IndexHashJoin{TableReader(Table(t))->TableReader(Table(t))}(Column#1,Column#13)" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.f=t2.f and t1.a=t2.a", - "Best": "IndexMergeJoin{TableReader(Table(t))->TableReader(Table(t))}(Column#1,Column#13)" + "Best": "IndexHashJoin{TableReader(Table(t))->TableReader(Table(t))}(Column#1,Column#13)" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.a=t2.a and t2.a in (1, 2)", - "Best": "IndexMergeJoin{TableReader(Table(t))->TableReader(Table(t)->Sel([in(Column#13, 1, 2)]))}(Column#1,Column#13)" + "Best": "IndexHashJoin{TableReader(Table(t))->TableReader(Table(t)->Sel([in(Column#13, 1, 2)]))}(Column#1,Column#13)" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.b=t2.c and t1.b=1 and t2.d > t1.d-10 and t2.d < t1.d+10", - "Best": "IndexJoin{TableReader(Table(t)->Sel([eq(Column#2, 1)]))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}" + "Best": "IndexHashJoin{TableReader(Table(t)->Sel([eq(Column#2, 1)]))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.b=t2.b and t1.c=1 and t2.c=1 and t2.d > t1.d-10 and t2.d < t1.d+10", @@ -528,8 +528,8 @@ }, { "SQL": "delete /*+ TIDB_INLJ(t1, t2) */ t1 from t t1, t t2 where t1.c=t2.c", - "Best": "IndexMergeJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(Column#3,Column#15)->Delete", - "Hints": "USE_INDEX(@`del_1` `t1` ), USE_INDEX(@`del_1` `t2` `c_d_e`), INL_JOIN(@`del_1` `t2`)" + "Best": "IndexHashJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(Column#3,Column#15)->Delete", + "Hints": "USE_INDEX(@`del_1` `t1` ), USE_INDEX(@`del_1` `t2` `c_d_e`)" }, { "SQL": "delete /*+ TIDB_SMJ(t1, t2) */ from t1 using t t1, t t2 where t1.c=t2.c", @@ -1026,9 +1026,9 @@ "Cases": [ { "SQL": "select /*+ TIDB_INLJ(t1) */ t1.a, t2.a, t3.a from t t1, t t2, t t3 where t1.a = t2.a and t2.a = t3.a;", - "Best": "RightHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexMergeJoin{TableReader(Table(t))->IndexReader(Index(t.f)[[NULL,+inf]])}(Column#13,Column#1)}(Column#25,Column#13)->Projection", + "Best": "RightHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexHashJoin{TableReader(Table(t))->IndexReader(Index(t.f)[[NULL,+inf]])}(Column#13,Column#1)}(Column#25,Column#13)->Projection", "Warning": "", - "Hints": "USE_INDEX(@`sel_1` `t3` `f`), USE_INDEX(@`sel_1` `t1` ), USE_INDEX(@`sel_1` `t2` `f`), INL_JOIN(@`sel_1` `t1`), HASH_JOIN(@`sel_1` `t3`)" + "Hints": "USE_INDEX(@`sel_1` `t3` `f`), USE_INDEX(@`sel_1` `t1` ), USE_INDEX(@`sel_1` `t2` `f`), HASH_JOIN(@`sel_1` `t3`)" }, { "SQL": "select /*+ TIDB_INLJ(t1) */ t1.b, t2.a from t t1, t t2 where t1.b = t2.a;", @@ -1124,13 +1124,13 @@ }, { "SQL": "select /*+ INL_JOIN(@sel_1 t1), HASH_JOIN(@sel_2 t2) */ t1.a, t1.b from t t1, (select t2.a from t t2, t t3 where t2.a = t3.c) s where t1.a=s.a", - "Plan": "IndexMergeJoin{TableReader(Table(t))->LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#13,Column#27)}(Column#13,Column#1)->Projection", - "Hints": "USE_INDEX(@`sel_1` `t1` ), USE_INDEX(@`sel_2` `t2` `f`), USE_INDEX(@`sel_2` `t3` `c_d_e`), HASH_JOIN(@`sel_2` `t2`, `t3`), INL_JOIN(@`sel_1` `t1`)" + "Plan": "IndexHashJoin{TableReader(Table(t))->LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#13,Column#27)}(Column#13,Column#1)->Projection", + "Hints": "USE_INDEX(@`sel_1` `t1` ), USE_INDEX(@`sel_2` `t2` `f`), USE_INDEX(@`sel_2` `t3` `c_d_e`), HASH_JOIN(@`sel_2` `t2`, `t3`)" }, { "SQL": "select /*+ INL_JOIN(@sel_1 t1), HASH_JOIN(@qb t2) */ t1.a, t1.b from t t1, (select /*+ QB_NAME(qb) */ t2.a from t t2, t t3 where t2.a = t3.c) s where t1.a=s.a", - "Plan": "IndexMergeJoin{TableReader(Table(t))->LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#13,Column#27)}(Column#13,Column#1)->Projection", - "Hints": "USE_INDEX(@`sel_1` `t1` ), USE_INDEX(@`sel_2` `t2` `f`), USE_INDEX(@`sel_2` `t3` `c_d_e`), HASH_JOIN(@`sel_2` `t2`, `t3`), INL_JOIN(@`sel_1` `t1`)" + "Plan": "IndexHashJoin{TableReader(Table(t))->LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#13,Column#27)}(Column#13,Column#1)->Projection", + "Hints": "USE_INDEX(@`sel_1` `t1` ), USE_INDEX(@`sel_2` `t2` `f`), USE_INDEX(@`sel_2` `t3` `c_d_e`), HASH_JOIN(@`sel_2` `t2`, `t3`)" }, { "SQL": "select /*+ HASH_AGG(@sel_1), STREAM_AGG(@sel_2) */ count(*) from t t1 where t1.a < (select count(*) from t t2 where t1.a > t2.a)", @@ -1154,15 +1154,15 @@ "Cases": [ { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.a", - "Best": "IndexMergeJoin{TableReader(Table(t))->UnionScan([])->TableReader(Table(t))->UnionScan([])}(Column#1,Column#13)" + "Best": "IndexHashJoin{TableReader(Table(t))->UnionScan([])->TableReader(Table(t))->UnionScan([])}(Column#1,Column#13)" }, { "SQL": "select /*+ TIDB_INLJ(t1, t2) */ * from t t1, t t2 where t1.a = t2.c", - "Best": "IndexMergeJoin{TableReader(Table(t))->UnionScan([])->TableReader(Table(t))->UnionScan([])}(Column#15,Column#1)" + "Best": "IndexHashJoin{TableReader(Table(t))->UnionScan([])->TableReader(Table(t))->UnionScan([])}(Column#15,Column#1)" }, { "SQL": "select /*+ TIDB_INLJ(t1, t2) */ t1.a , t2.c from t t1, t t2 where t1.a = t2.c", - "Best": "IndexMergeJoin{IndexReader(Index(t.f)[[NULL,+inf]])->UnionScan([])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])->UnionScan([])}(Column#1,Column#15)->Projection" + "Best": "IndexHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->UnionScan([])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])->UnionScan([])}(Column#1,Column#15)->Projection" } ] }, @@ -1171,7 +1171,7 @@ "Cases": [ { "SQL": "select t1.a, (select count(t2.a) from t t2 where t2.g in (select t3.d from t t3 where t3.c = t1.a)) as agg_col from t t1;", - "Best": "Apply{IndexReader(Index(t.f)[[NULL,+inf]])->IndexMergeJoin{IndexReader(Index(t.c_d_e)[[NULL,+inf]]->HashAgg)->HashAgg->IndexReader(Index(t.g)[[NULL,+inf]])}(Column#29,Column#23)}->HashAgg" + "Best": "Apply{IndexReader(Index(t.f)[[NULL,+inf]])->IndexHashJoin{IndexReader(Index(t.c_d_e)[[NULL,+inf]]->HashAgg)->HashAgg->IndexReader(Index(t.g)[[NULL,+inf]])}(Column#29,Column#23)}->HashAgg" } ] } diff --git a/util/ranger/testdata/ranger_suite_out.json b/util/ranger/testdata/ranger_suite_out.json index 7658e03e7c789..5dfae3a131d99 100644 --- a/util/ranger/testdata/ranger_suite_out.json +++ b/util/ranger/testdata/ranger_suite_out.json @@ -10,11 +10,11 @@ " ├─TableReader_15 2.00 root data:TableScan_14", " │ └─TableScan_14 2.00 cop table:t, range:[-inf,+inf], keep order:false", " └─StreamAgg_20 1.00 root funcs:count(1)", - " └─IndexMergeJoin_42 2.00 root inner join, inner:TableReader_40, outer key:Column#6, inner key:Column#11", - " ├─IndexReader_31 2.00 root index:IndexScan_30", - " │ └─IndexScan_30 2.00 cop table:s, index:b, c, d, range: decided by [eq(Column#7, 1) in(Column#8, 1, 2) eq(Column#9, Column#1)], keep order:false", - " └─TableReader_40 1.00 root data:TableScan_39", - " └─TableScan_39 1.00 cop table:t1, range: decided by [Column#6], keep order:true" + " └─IndexHashJoin_46 2.00 root inner join, inner:TableReader_39, outer key:Column#6, inner key:Column#11", + " ├─IndexReader_33 2.00 root index:IndexScan_32", + " │ └─IndexScan_32 2.00 cop table:s, index:b, c, d, range: decided by [eq(Column#7, 1) in(Column#8, 1, 2) eq(Column#9, Column#1)], keep order:false", + " └─TableReader_39 1.00 root data:TableScan_38", + " └─TableScan_38 1.00 cop table:t1, range: decided by [Column#6], keep order:false" ] }, { From 83132724df8cb48d1a5862c1e8597a8b78d4c9d6 Mon Sep 17 00:00:00 2001 From: xuhuaiyu <391585975@qq.com> Date: Mon, 23 Sep 2019 14:50:31 +0800 Subject: [PATCH 2/7] refine --- planner/core/exhaust_physical_plans.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/core/exhaust_physical_plans.go b/planner/core/exhaust_physical_plans.go index 5f7ec2aad4e67..918bde9a803be 100644 --- a/planner/core/exhaust_physical_plans.go +++ b/planner/core/exhaust_physical_plans.go @@ -561,7 +561,7 @@ func (p *LogicalJoin) buildIndexJoinInner2IndexScan( keyOff2IdxOff[keyOff] = idxOff } } - joins = make([]PhysicalPlan, 0, 2) + joins = make([]PhysicalPlan, 0, 3) rangeInfo := helper.buildRangeDecidedByInformation(helper.chosenPath.idxCols, outerJoinKeys) innerTask := p.constructInnerIndexScanTask(ds, helper.chosenPath, helper.chosenRemained, outerJoinKeys, us, rangeInfo, false, avgInnerRowCnt) From 9e8bd150d300f23a65b047432042b76b259631ec Mon Sep 17 00:00:00 2001 From: xuhuaiyu <391585975@qq.com> Date: Mon, 23 Sep 2019 15:24:45 +0800 Subject: [PATCH 3/7] fix ci --- executor/adapter.go | 2 +- planner/core/cbo_test.go | 46 ++++++++++---------- planner/core/testdata/analyze_suite_in.json | 14 ++++++ planner/core/testdata/analyze_suite_out.json | 37 ++++++++++++++++ 4 files changed, 74 insertions(+), 25 deletions(-) diff --git a/executor/adapter.go b/executor/adapter.go index 3238865cdba6a..e17e497d4c4bf 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -785,7 +785,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool) { slowItems.PrevStmt = sessVars.PrevStmt } if costTime < threshold { - logutil.SlowQueryLogger.Debug(sessVars.SlowLogFormat(slowItems)) + //logutil.SlowQueryLogger.Debug(sessVars.SlowLogFormat(slowItems)) } else { logutil.SlowQueryLogger.Warn(sessVars.SlowLogFormat(slowItems)) metrics.TotalQueryProcHistogram.Observe(costTime.Seconds()) diff --git a/planner/core/cbo_test.go b/planner/core/cbo_test.go index 6a5b70232d7a1..c3e4bfea62bcb 100644 --- a/planner/core/cbo_test.go +++ b/planner/core/cbo_test.go @@ -909,30 +909,28 @@ func (s *testAnalyzeSuite) TestIssue9562(c *C) { }() tk.MustExec("use test") - tk.MustExec("create table t1(a bigint, b bigint, c bigint)") - tk.MustExec("create table t2(a bigint, b bigint, c bigint, index idx(a, b, c))") - - tk.MustQuery("explain select /*+ TIDB_INLJ(t2) */ * from t1 join t2 on t2.a=t1.a and t2.b>t1.b-1 and t2.b 0 ORDER BY a limit 1" ] ] + }, + { + "name": "TestIssue9562", + "cases": [ + [ + "create table t1(a bigint, b bigint, c bigint)", + "create table t2(a bigint, b bigint, c bigint, index idx(a, b, c))", + "explain select /*+ TIDB_INLJ(t2) */ * from t1 join t2 on t2.a=t1.a and t2.b>t1.b-1 and t2.bt1.b-1 and t2.b Date: Tue, 24 Sep 2019 10:35:43 +0800 Subject: [PATCH 4/7] address comment --- executor/adapter.go | 2 +- executor/joiner.go | 2 ++ planner/core/exhaust_physical_plans.go | 2 +- planner/core/task.go | 11 ++++++++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/executor/adapter.go b/executor/adapter.go index e17e497d4c4bf..3238865cdba6a 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -785,7 +785,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool) { slowItems.PrevStmt = sessVars.PrevStmt } if costTime < threshold { - //logutil.SlowQueryLogger.Debug(sessVars.SlowLogFormat(slowItems)) + logutil.SlowQueryLogger.Debug(sessVars.SlowLogFormat(slowItems)) } else { logutil.SlowQueryLogger.Warn(sessVars.SlowLogFormat(slowItems)) metrics.TotalQueryProcHistogram.Observe(costTime.Seconds()) diff --git a/executor/joiner.go b/executor/joiner.go index 69ac3fe9c52ea..af8faef85050f 100644 --- a/executor/joiner.go +++ b/executor/joiner.go @@ -315,6 +315,8 @@ func (j *semiJoiner) tryToMatchOuters(outers chunk.Iterator, inner chunk.Row, ch func (j *semiJoiner) onMissMatch(_ bool, outer chunk.Row, chk *chunk.Chunk) { } + +// Clone implements joiner interface. func (j *semiJoiner) Clone() joiner { return &semiJoiner{baseJoiner: j.baseJoiner.Clone()} } diff --git a/planner/core/exhaust_physical_plans.go b/planner/core/exhaust_physical_plans.go index 918bde9a803be..b979c6bd655ea 100644 --- a/planner/core/exhaust_physical_plans.go +++ b/planner/core/exhaust_physical_plans.go @@ -424,7 +424,7 @@ func (p *LogicalJoin) constructIndexHashJoin( compareFilters *ColWithCmpFuncManager, ) []PhysicalPlan { // TODO(xuhuaiyu): support keep outer order for indexHashJoin. - if keepOuterOrder := len(prop.Items) > 0; keepOuterOrder { + if !prop.IsEmpty() { return nil } indexJoins := p.constructIndexJoin(prop, outerIdx, innerTask, ranges, keyOff2IdxOff, path, compareFilters) diff --git a/planner/core/task.go b/planner/core/task.go index 50a65b140673b..5ff1977bb2c61 100644 --- a/planner/core/task.go +++ b/planner/core/task.go @@ -294,7 +294,16 @@ func (p *PhysicalIndexHashJoin) GetCost(outerTask, innerTask task) float64 { numPairs = 0 } } - probeCost := numPairs * CPUFactor / concurrency + // Inner workers do hash join in parallel, but they can only save ONE outer + // batch results. So as the number of outer batch exceeds inner concurrency, + // it would fall back to linear execution. In a word, the hash join only runs + // in parallel for the first `innerConcurrency` number of inner tasks. + var probeCost float64 + if outerCnt/batchSize >= concurrency { + probeCost = (numPairs - batchSize*innerCnt*(concurrency-1)) * CPUFactor + } else { + probeCost = batchSize * innerCnt * CPUFactor + } cpuCost += probeCost // Cost of additional concurrent goroutines. cpuCost += (concurrency + 1.0) * concurrencyFactor From 0739a03ecaaf716bbcdeeb47612c61ae667248ba Mon Sep 17 00:00:00 2001 From: xuhuaiyu <391585975@qq.com> Date: Tue, 24 Sep 2019 10:40:32 +0800 Subject: [PATCH 5/7] address comment --- .../r/explain_complex_stats.result | 10 ++-- cmd/explaintest/r/explain_easy.result | 12 ++--- cmd/explaintest/r/index_join.result | 8 +-- cmd/explaintest/r/subquery.result | 6 +-- cmd/explaintest/r/topn_push_down.result | 12 ++--- cmd/explaintest/r/tpch.result | 50 +++++++++---------- executor/adapter.go | 2 +- planner/core/testdata/analyze_suite_out.json | 8 +-- planner/core/testdata/plan_suite_out.json | 50 +++++++++---------- util/ranger/testdata/ranger_suite_out.json | 6 +-- 10 files changed, 82 insertions(+), 82 deletions(-) diff --git a/cmd/explaintest/r/explain_complex_stats.result b/cmd/explaintest/r/explain_complex_stats.result index 12bea9e5ebf8d..5302fd0c20a9d 100644 --- a/cmd/explaintest/r/explain_complex_stats.result +++ b/cmd/explaintest/r/explain_complex_stats.result @@ -160,14 +160,14 @@ explain select dt.id as id, dt.aid as aid, dt.pt as pt, dt.dic as dic, dt.cm as id count task operator info Projection_10 428.32 root Column#1, Column#2, Column#4, Column#5, Column#3, Column#24, Column#25, Column#26, Column#11, Column#12, Column#13, Column#14, Column#15, Column#16, Column#17 └─Limit_13 428.32 root offset:0, count:2000 - └─IndexHashJoin_27 428.32 root inner join, inner:IndexLookUp_18, outer key:Column#2, Column#5, inner key:Column#21, Column#23 + └─IndexMergeJoin_25 428.32 root inner join, inner:IndexLookUp_23, outer key:Column#2, Column#5, inner key:Column#21, Column#23 ├─TableReader_42 428.32 root data:Selection_41 │ └─Selection_41 428.32 cop eq(Column#18, 0), eq(Column#4, "ios"), gt(Column#9, 1478185592), not(isnull(Column#5)) │ └─TableScan_40 2000.00 cop table:dt, range:[0,+inf], keep order:false - └─IndexLookUp_18 0.48 root - ├─IndexScan_15 1.00 cop table:rr, index:aid, dic, range: decided by [eq(Column#21, Column#2) eq(Column#23, Column#5)], keep order:false - └─Selection_17 0.48 cop eq(Column#22, "ios"), gt(Column#26, 1478185592) - └─TableScan_16 1.00 cop table:rr, keep order:false + └─IndexLookUp_23 0.48 root + ├─IndexScan_20 1.00 cop table:rr, index:aid, dic, range: decided by [eq(Column#21, Column#2) eq(Column#23, Column#5)], keep order:true + └─Selection_22 0.48 cop eq(Column#22, "ios"), gt(Column#26, 1478185592) + └─TableScan_21 1.00 cop table:rr, keep order:false explain select pc,cr,count(DISTINCT uid) as pay_users,count(oid) as pay_times,sum(am) as am from pp where ps=2 and ppt>=1478188800 and ppt<1478275200 and pi in ('510017','520017') and uid in ('18089709','18090780') group by pc,cr; id count task operator info Projection_5 207.86 root Column#14, Column#16, Column#22, Column#23, Column#24 diff --git a/cmd/explaintest/r/explain_easy.result b/cmd/explaintest/r/explain_easy.result index 8c0105faa1b2f..dff18f49a3aad 100644 --- a/cmd/explaintest/r/explain_easy.result +++ b/cmd/explaintest/r/explain_easy.result @@ -323,11 +323,11 @@ Projection_11 10000.00 root Column#12 ├─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo └─StreamAgg_20 1.00 root funcs:count(1) - └─IndexHashJoin_46 12.50 root inner join, inner:TableReader_39, outer key:Column#4, inner key:Column#7 + └─IndexMergeJoin_44 12.50 root inner join, inner:TableReader_42, outer key:Column#4, inner key:Column#7 ├─IndexReader_33 10.00 root index:IndexScan_32 │ └─IndexScan_32 10.00 cop table:s, index:b, range: decided by [eq(Column#5, Column#1)], keep order:false, stats:pseudo - └─TableReader_39 1.00 root data:TableScan_38 - └─TableScan_38 1.00 cop table:t1, range: decided by [Column#4], keep order:false, stats:pseudo + └─TableReader_42 1.00 root data:TableScan_41 + └─TableScan_41 1.00 cop table:t1, range: decided by [Column#4], keep order:true, stats:pseudo explain select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.c = t1.a) from t; id count task operator info Projection_11 10000.00 root Column#12 @@ -335,13 +335,13 @@ Projection_11 10000.00 root Column#12 ├─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo └─StreamAgg_20 1.00 root funcs:count(1) - └─IndexHashJoin_48 12.49 root inner join, inner:TableReader_41, outer key:Column#6, inner key:Column#7 + └─IndexMergeJoin_46 12.49 root inner join, inner:TableReader_44, outer key:Column#6, inner key:Column#7 ├─IndexLookUp_35 9.99 root │ ├─IndexScan_32 10.00 cop table:s, index:b, range: decided by [eq(Column#5, Column#1)], keep order:false, stats:pseudo │ └─Selection_34 9.99 cop not(isnull(Column#6)) │ └─TableScan_33 10.00 cop table:s, keep order:false, stats:pseudo - └─TableReader_41 1.00 root data:TableScan_40 - └─TableScan_40 1.00 cop table:t1, range: decided by [Column#6], keep order:false, stats:pseudo + └─TableReader_44 1.00 root data:TableScan_43 + └─TableScan_43 1.00 cop table:t1, range: decided by [Column#6], keep order:true, stats:pseudo insert into t values(1, 1, 1), (2, 2 ,2), (3, 3, 3), (4, 3, 4),(5,3,5); analyze table t; explain select t.c in (select count(*) from t s, t t1 where s.b = t.a and s.b = 3 and s.a = t1.a) from t; diff --git a/cmd/explaintest/r/index_join.result b/cmd/explaintest/r/index_join.result index 85ec9ca05bea6..def2ecba1ae1f 100644 --- a/cmd/explaintest/r/index_join.result +++ b/cmd/explaintest/r/index_join.result @@ -46,10 +46,10 @@ create table t2(a int not null, b int not null, key a(a)); explain select /*+ TIDB_INLJ(t1) */ * from t1 where t1.a in (select t2.a from t2); id count task operator info Projection_8 10000.00 root Column#1, Column#2 -└─IndexHashJoin_19 10000.00 root inner join, inner:IndexLookUp_11, outer key:Column#4, inner key:Column#1 - ├─IndexLookUp_11 1.25 root - │ ├─IndexScan_9 1.25 cop table:t1, index:a, range: decided by [eq(Column#1, Column#4)], keep order:false, stats:pseudo - │ └─TableScan_10 1.25 cop table:t1, keep order:false, stats:pseudo +└─IndexMergeJoin_17 10000.00 root inner join, inner:IndexLookUp_15, outer key:Column#4, inner key:Column#1 + ├─IndexLookUp_15 1.25 root + │ ├─IndexScan_13 1.25 cop table:t1, index:a, range: decided by [eq(Column#1, Column#4)], keep order:true, stats:pseudo + │ └─TableScan_14 1.25 cop table:t1, keep order:false, stats:pseudo └─StreamAgg_24 8000.00 root group by:Column#4, funcs:firstrow(Column#4) └─IndexReader_37 10000.00 root index:IndexScan_36 └─IndexScan_36 10000.00 cop table:t2, index:a, range:[NULL,+inf], keep order:true, stats:pseudo diff --git a/cmd/explaintest/r/subquery.result b/cmd/explaintest/r/subquery.result index 720a8ae21b315..17b22116af423 100644 --- a/cmd/explaintest/r/subquery.result +++ b/cmd/explaintest/r/subquery.result @@ -22,8 +22,8 @@ Projection_11 5.00 root Column#15 ├─TableReader_15 5.00 root data:TableScan_14 │ └─TableScan_14 5.00 cop table:t, range:[-inf,+inf], keep order:false └─StreamAgg_22 1.00 root funcs:count(1) - └─IndexHashJoin_31 0.50 root inner join, inner:TableReader_24, outer key:Column#5, inner key:Column#9 + └─IndexMergeJoin_29 0.50 root inner join, inner:TableReader_27, outer key:Column#5, inner key:Column#9 ├─IndexReader_35 1.00 root index:IndexScan_34 │ └─IndexScan_34 1.00 cop table:s, index:b, c, d, range: decided by [eq(Column#6, 1) eq(Column#7, 1) eq(Column#8, Column#1)], keep order:false - └─TableReader_24 1.00 root data:TableScan_23 - └─TableScan_23 1.00 cop table:t1, range: decided by [Column#5], keep order:false + └─TableReader_27 1.00 root data:TableScan_26 + └─TableScan_26 1.00 cop table:t1, range: decided by [Column#5], keep order:true diff --git a/cmd/explaintest/r/topn_push_down.result b/cmd/explaintest/r/topn_push_down.result index 20b74bd963dbe..efe1cb54853de 100644 --- a/cmd/explaintest/r/topn_push_down.result +++ b/cmd/explaintest/r/topn_push_down.result @@ -222,20 +222,20 @@ create table t(a int not null, index idx(a)); explain select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 on t1.a = t2.a limit 5; id count task operator info Limit_11 5.00 root offset:0, count:5 -└─IndexHashJoin_21 5.00 root inner join, inner:IndexReader_14, outer key:Column#1, inner key:Column#3 +└─IndexMergeJoin_19 5.00 root inner join, inner:IndexReader_17, outer key:Column#1, inner key:Column#3 ├─IndexReader_25 4.00 root index:IndexScan_24 │ └─IndexScan_24 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:false, stats:pseudo - └─IndexReader_14 1.25 root index:IndexScan_13 - └─IndexScan_13 1.25 cop table:t2, index:a, range: decided by [eq(Column#3, Column#1)], keep order:false, stats:pseudo + └─IndexReader_17 1.25 root index:IndexScan_16 + └─IndexScan_16 1.25 cop table:t2, index:a, range: decided by [eq(Column#3, Column#1)], keep order:true, stats:pseudo explain select /*+ TIDB_INLJ(t2) */ * from t t1 left join t t2 on t1.a = t2.a where t2.a is null limit 5; id count task operator info Limit_12 5.00 root offset:0, count:5 └─Selection_13 5.00 root isnull(Column#3) - └─IndexHashJoin_23 5.00 root left outer join, inner:IndexReader_16, outer key:Column#1, inner key:Column#3 + └─IndexMergeJoin_21 5.00 root left outer join, inner:IndexReader_19, outer key:Column#1, inner key:Column#3 ├─IndexReader_27 4.00 root index:IndexScan_26 │ └─IndexScan_26 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:false, stats:pseudo - └─IndexReader_16 1.25 root index:IndexScan_15 - └─IndexScan_15 1.25 cop table:t2, index:a, range: decided by [eq(Column#3, Column#1)], keep order:false, stats:pseudo + └─IndexReader_19 1.25 root index:IndexScan_18 + └─IndexScan_18 1.25 cop table:t2, index:a, range: decided by [eq(Column#3, Column#1)], keep order:true, stats:pseudo explain select /*+ TIDB_SMJ(t1, t2) */ * from t t1 join t t2 on t1.a = t2.a limit 5; id count task operator info Limit_11 5.00 root offset:0, count:5 diff --git a/cmd/explaintest/r/tpch.result b/cmd/explaintest/r/tpch.result index a076c82d3d076..694a4c8bd3df1 100644 --- a/cmd/explaintest/r/tpch.result +++ b/cmd/explaintest/r/tpch.result @@ -450,7 +450,7 @@ Sort_22 769.96 root Column#55:asc, Column#56:asc, Column#57:asc └─Projection_28 1957240.42 root Column#43, Column#47, extract("YEAR", Column#18), mul(Column#13, minus(1, Column#14)) └─HashLeftJoin_40 1957240.42 root inner join, inner:TableReader_94, equal:[eq(Column#37, Column#46)], other cond:or(and(eq(Column#43, "JAPAN"), eq(Column#47, "INDIA")), and(eq(Column#43, "INDIA"), eq(Column#47, "JAPAN"))) ├─HashLeftJoin_51 24465505.20 root inner join, inner:TableReader_91, equal:[eq(Column#26, Column#34)] - │ ├─IndexHashJoin_62 24465505.20 root inner join, inner:TableReader_55, outer key:Column#8, inner key:Column#25 + │ ├─IndexMergeJoin_60 24465505.20 root inner join, inner:TableReader_58, outer key:Column#8, inner key:Column#25 │ │ ├─HashRightJoin_66 24465505.20 root inner join, inner:HashRightJoin_79, equal:[eq(Column#1, Column#10)] │ │ │ ├─HashRightJoin_79 40000.00 root inner join, inner:TableReader_84, equal:[eq(Column#42, Column#4)] │ │ │ │ ├─TableReader_84 2.00 root data:Selection_83 @@ -461,8 +461,8 @@ Sort_22 769.96 root Column#55:asc, Column#56:asc, Column#57:asc │ │ │ └─TableReader_87 91446230.29 root data:Selection_86 │ │ │ └─Selection_86 91446230.29 cop ge(Column#18, 1995-01-01 00:00:00.000000), le(Column#18, 1996-12-31 00:00:00.000000) │ │ │ └─TableScan_85 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false - │ │ └─TableReader_55 1.00 root data:TableScan_54 - │ │ └─TableScan_54 1.00 cop table:orders, range: decided by [Column#8], keep order:false + │ │ └─TableReader_58 1.00 root data:TableScan_57 + │ │ └─TableScan_57 1.00 cop table:orders, range: decided by [Column#8], keep order:true │ └─TableReader_91 7500000.00 root data:TableScan_90 │ └─TableScan_90 7500000.00 cop table:customer, range:[-inf,+inf], keep order:false └─TableReader_94 2.00 root data:Selection_93 @@ -662,7 +662,7 @@ Projection_17 20.00 root Column#1, Column#2, Column#39, Column#6, Column#36, Col └─TopN_20 20.00 root Column#39:desc, offset:0, count:20 └─HashAgg_26 3017307.69 root group by:Column#50, Column#51, Column#52, Column#53, Column#54, Column#55, Column#56, funcs:sum(Column#0), firstrow(Column#0), firstrow(Column#0), firstrow(Column#0), firstrow(Column#0), firstrow(Column#0), firstrow(Column#0), firstrow(Column#0) └─Projection_66 12222016.17 root mul(Column#23, minus(1, Column#24)), Column#1, Column#2, Column#3, Column#5, Column#6, Column#8, Column#36, Column#1, Column#2, Column#6, Column#5, Column#36, Column#3, Column#8 - └─IndexHashJoin_40 12222016.17 root inner join, inner:IndexLookUp_31, outer key:Column#9, inner key:Column#18 + └─IndexMergeJoin_38 12222016.17 root inner join, inner:IndexLookUp_36, outer key:Column#9, inner key:Column#18 ├─HashLeftJoin_43 3017307.69 root inner join, inner:TableReader_62, equal:[eq(Column#1, Column#10)] │ ├─HashRightJoin_55 7500000.00 root inner join, inner:TableReader_59, equal:[eq(Column#35, Column#4)] │ │ ├─TableReader_59 25.00 root data:TableScan_58 @@ -672,10 +672,10 @@ Projection_17 20.00 root Column#1, Column#2, Column#39, Column#6, Column#36, Col │ └─TableReader_62 3017307.69 root data:Selection_61 │ └─Selection_61 3017307.69 cop ge(Column#13, 1993-08-01 00:00:00.000000), lt(Column#13, 1993-11-01) │ └─TableScan_60 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false - └─IndexLookUp_31 1.00 root - ├─IndexScan_28 4.05 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#18, Column#9)], keep order:false - └─Selection_30 1.00 cop eq(Column#26, "R") - └─TableScan_29 4.05 cop table:lineitem, keep order:false + └─IndexLookUp_36 1.00 root + ├─IndexScan_33 4.05 cop table:lineitem, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#18, Column#9)], keep order:true + └─Selection_35 1.00 cop eq(Column#26, "R") + └─TableScan_34 4.05 cop table:lineitem, keep order:false /* Q11 Important Stock Identification Query This query finds the most important subset of suppliers' stock in a given nation. @@ -770,12 +770,12 @@ Sort_9 1.00 root Column#29:asc └─Projection_11 1.00 root Column#24, Column#27, Column#28 └─HashAgg_14 1.00 root group by:Column#34, funcs:sum(Column#0), sum(Column#0), firstrow(Column#0) └─Projection_40 10023369.01 root cast(case(or(eq(Column#6, "1-URGENT"), eq(Column#6, "2-HIGH")), 1, 0)), cast(case(and(ne(Column#6, "1-URGENT"), ne(Column#6, "2-HIGH")), 1, 0)), Column#24, Column#24 - └─IndexHashJoin_24 10023369.01 root inner join, inner:TableReader_17, outer key:Column#10, inner key:Column#1 + └─IndexMergeJoin_22 10023369.01 root inner join, inner:TableReader_20, outer key:Column#10, inner key:Column#1 ├─TableReader_36 10023369.01 root data:Selection_35 │ └─Selection_35 10023369.01 cop ge(Column#22, 1997-01-01 00:00:00.000000), in(Column#24, "RAIL", "FOB"), lt(Column#20, Column#21), lt(Column#21, Column#22), lt(Column#22, 1998-01-01) │ └─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 [Column#10], keep order:false + └─TableReader_20 1.00 root data:TableScan_19 + └─TableScan_19 1.00 cop table:orders, range: decided by [Column#10], keep order:true /* Q13 Customer Distribution Query This query seeks relationships between customers and the size of their orders. @@ -841,12 +841,12 @@ id count task operator info Projection_8 1.00 root div(mul(100.00, Column#27), Column#28) └─StreamAgg_13 1.00 root funcs:sum(Column#0), sum(Column#0) └─Projection_41 4121984.49 root case(like(Column#22, "PROMO%", 92), mul(Column#6, minus(1, Column#7)), 0), mul(Column#6, minus(1, Column#7)) - └─IndexHashJoin_38 4121984.49 root inner join, inner:TableReader_31, outer key:Column#2, inner key:Column#18 + └─IndexMergeJoin_36 4121984.49 root inner join, inner:TableReader_34, outer key:Column#2, inner key:Column#18 ├─TableReader_27 4121984.49 root data:Selection_26 │ └─Selection_26 4121984.49 cop ge(Column#11, 1996-12-01 00:00:00.000000), lt(Column#11, 1997-01-01) │ └─TableScan_25 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false - └─TableReader_31 1.00 root data:TableScan_30 - └─TableScan_30 1.00 cop table:part, range: decided by [Column#2], keep order:false + └─TableReader_34 1.00 root data:TableScan_33 + └─TableScan_33 1.00 cop table:part, range: decided by [Column#2], keep order:true /* Q15 Top Supplier Query This query determines the top supplier so it can be rewarded, given more business, or identified for special recognition. @@ -931,12 +931,12 @@ Sort_13 3863988.24 root Column#28:desc, Column#25:asc, Column#26:asc, Column#27: └─Projection_15 3863988.24 root Column#10, Column#11, Column#12, Column#24 └─HashAgg_18 3863988.24 root group by:Column#10, Column#11, Column#12, funcs:count(distinct Column#2), firstrow(Column#10), firstrow(Column#11), firstrow(Column#12) └─HashLeftJoin_30 3863988.24 root anti semi join, inner:TableReader_57, equal:[eq(Column#2, Column#16)] - ├─IndexHashJoin_40 4829985.30 root inner join, inner:IndexReader_33, outer key:Column#7, inner key:Column#1 + ├─IndexMergeJoin_38 4829985.30 root inner join, inner:IndexReader_36, outer key:Column#7, inner key:Column#1 │ ├─TableReader_50 1200618.43 root data:Selection_49 │ │ └─Selection_49 1200618.43 cop in(Column#12, 48, 19, 12, 4, 41, 7, 21, 39), ne(Column#10, "Brand#34"), not(like(Column#11, "LARGE BRUSHED%", 92)) │ │ └─TableScan_48 10000000.00 cop table:part, range:[-inf,+inf], keep order:false - │ └─IndexReader_33 4.02 root index:IndexScan_32 - │ └─IndexScan_32 4.02 cop table:partsupp, index:PS_PARTKEY, PS_SUPPKEY, range: decided by [eq(Column#1, Column#7)], keep order:false + │ └─IndexReader_36 4.02 root index:IndexScan_35 + │ └─IndexScan_35 4.02 cop table:partsupp, index:PS_PARTKEY, PS_SUPPKEY, range: decided by [eq(Column#1, Column#7)], keep order:true └─TableReader_57 400000.00 root data:Selection_56 └─Selection_56 400000.00 cop like(Column#22, "%Customer%Complaints%", 92) └─TableScan_55 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false @@ -1091,13 +1091,13 @@ and l_shipinstruct = 'DELIVER IN PERSON' id count task operator info StreamAgg_13 1.00 root funcs:sum(Column#0) └─Projection_46 6286493.79 root mul(Column#6, minus(1, Column#7)) - └─IndexHashJoin_43 6286493.79 root inner join, inner:TableReader_35, outer key:Column#2, inner key:Column#18, other cond:or(and(and(eq(Column#21, "Brand#52"), in(Column#24, "SM CASE", "SM BOX", "SM PACK", "SM PKG")), and(ge(Column#5, 4), and(le(Column#5, 14), le(Column#23, 5)))), or(and(and(eq(Column#21, "Brand#11"), in(Column#24, "MED BAG", "MED BOX", "MED PKG", "MED PACK")), and(ge(Column#5, 18), and(le(Column#5, 28), le(Column#23, 10)))), and(and(eq(Column#21, "Brand#51"), in(Column#24, "LG CASE", "LG BOX", "LG PACK", "LG PKG")), and(ge(Column#5, 29), and(le(Column#5, 39), le(Column#23, 15)))))) + └─IndexMergeJoin_41 6286493.79 root inner join, inner:TableReader_39, outer key:Column#2, inner key:Column#18, other cond:or(and(and(eq(Column#21, "Brand#52"), in(Column#24, "SM CASE", "SM BOX", "SM PACK", "SM PKG")), and(ge(Column#5, 4), and(le(Column#5, 14), le(Column#23, 5)))), or(and(and(eq(Column#21, "Brand#11"), in(Column#24, "MED BAG", "MED BOX", "MED PKG", "MED PACK")), and(ge(Column#5, 18), and(le(Column#5, 28), le(Column#23, 10)))), and(and(eq(Column#21, "Brand#51"), in(Column#24, "LG CASE", "LG BOX", "LG PACK", "LG PKG")), and(ge(Column#5, 29), and(le(Column#5, 39), le(Column#23, 15)))))) ├─TableReader_29 6286493.79 root data:Selection_28 │ └─Selection_28 6286493.79 cop eq(Column#14, "DELIVER IN PERSON"), in(Column#15, "AIR", "AIR REG"), or(and(ge(Column#5, 4), le(Column#5, 14)), or(and(ge(Column#5, 18), le(Column#5, 28)), and(ge(Column#5, 29), le(Column#5, 39)))) │ └─TableScan_27 300005811.00 cop table:lineitem, range:[-inf,+inf], keep order:false - └─TableReader_35 0.80 root data:Selection_34 - └─Selection_34 0.80 cop ge(Column#23, 1), or(and(eq(Column#21, "Brand#52"), and(in(Column#24, "SM CASE", "SM BOX", "SM PACK", "SM PKG"), le(Column#23, 5))), or(and(eq(Column#21, "Brand#11"), and(in(Column#24, "MED BAG", "MED BOX", "MED PKG", "MED PACK"), le(Column#23, 10))), and(eq(Column#21, "Brand#51"), and(in(Column#24, "LG CASE", "LG BOX", "LG PACK", "LG PKG"), le(Column#23, 15))))) - └─TableScan_33 1.00 cop table:part, range: decided by [Column#2], keep order:false + └─TableReader_39 0.80 root data:Selection_38 + └─Selection_38 0.80 cop ge(Column#23, 1), or(and(eq(Column#21, "Brand#52"), and(in(Column#24, "SM CASE", "SM BOX", "SM PACK", "SM PKG"), le(Column#23, 5))), or(and(eq(Column#21, "Brand#11"), and(in(Column#24, "MED BAG", "MED BOX", "MED PKG", "MED PACK"), le(Column#23, 10))), and(eq(Column#21, "Brand#51"), and(in(Column#24, "LG CASE", "LG BOX", "LG PACK", "LG PKG"), le(Column#23, 15))))) + └─TableScan_37 1.00 cop table:part, range: decided by [Column#2], keep order:true /* Q20 Potential Part Promotion Query The Potential Part Promotion Query identifies suppliers in a particular nation having selected parts that may be candidates @@ -1223,7 +1223,7 @@ Projection_25 1.00 root Column#2, Column#104 └─HashAgg_34 1.00 root group by:Column#2, funcs:count(1), firstrow(Column#2) └─IndexHashJoin_48 7828961.66 root anti semi join, inner:IndexLookUp_39, outer key:Column#8, inner key:Column#71, other cond:ne(Column#73, Column#1), ne(Column#73, Column#10) ├─IndexHashJoin_81 9786202.08 root semi join, inner:IndexLookUp_73, outer key:Column#8, inner key:Column#38, other cond:ne(Column#40, Column#1), ne(Column#40, Column#10) - │ ├─IndexHashJoin_94 12232752.60 root inner join, inner:TableReader_86, outer key:Column#8, inner key:Column#25 + │ ├─IndexMergeJoin_92 12232752.60 root inner join, inner:TableReader_90, outer key:Column#8, inner key:Column#25 │ │ ├─HashRightJoin_98 12232752.60 root inner join, inner:HashRightJoin_111, equal:[eq(Column#1, Column#10)] │ │ │ ├─HashRightJoin_111 20000.00 root inner join, inner:TableReader_116, equal:[eq(Column#34, Column#4)] │ │ │ │ ├─TableReader_116 1.00 root data:Selection_115 @@ -1234,9 +1234,9 @@ Projection_25 1.00 root Column#2, Column#104 │ │ │ └─TableReader_119 240004648.80 root data:Selection_118 │ │ │ └─Selection_118 240004648.80 cop gt(Column#20, Column#19) │ │ │ └─TableScan_117 300005811.00 cop table:l1, range:[-inf,+inf], keep order:false - │ │ └─TableReader_86 0.80 root data:Selection_85 - │ │ └─Selection_85 0.80 cop eq(Column#27, "F") - │ │ └─TableScan_84 1.00 cop table:orders, range: decided by [Column#8], keep order:false + │ │ └─TableReader_90 0.80 root data:Selection_89 + │ │ └─Selection_89 0.80 cop eq(Column#27, "F") + │ │ └─TableScan_88 1.00 cop table:orders, range: decided by [Column#8], keep order:true │ └─IndexLookUp_73 4.05 root │ ├─IndexScan_71 4.05 cop table:l2, index:L_ORDERKEY, L_LINENUMBER, range: decided by [eq(Column#38, Column#8)], keep order:false │ └─TableScan_72 4.05 cop table:l2, keep order:false diff --git a/executor/adapter.go b/executor/adapter.go index 3238865cdba6a..e17e497d4c4bf 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -785,7 +785,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool) { slowItems.PrevStmt = sessVars.PrevStmt } if costTime < threshold { - logutil.SlowQueryLogger.Debug(sessVars.SlowLogFormat(slowItems)) + //logutil.SlowQueryLogger.Debug(sessVars.SlowLogFormat(slowItems)) } else { logutil.SlowQueryLogger.Warn(sessVars.SlowLogFormat(slowItems)) metrics.TotalQueryProcHistogram.Observe(costTime.Seconds()) diff --git a/planner/core/testdata/analyze_suite_out.json b/planner/core/testdata/analyze_suite_out.json index ebb0518a0457a..3eeade5e19251 100644 --- a/planner/core/testdata/analyze_suite_out.json +++ b/planner/core/testdata/analyze_suite_out.json @@ -142,13 +142,13 @@ "explain select /*+ TIDB_INLJ(t2) */ * from t1 join t2 on t2.a=t1.a and t2.b>t1.b-1 and t2.bTopN([Column#2],0,10))->TopN([Column#2],0,10)->TableReader(Table(t))}(Column#1,Column#25)->Limit" + "Best": "IndexMergeJoin{TableReader(Table(t)->TopN([Column#2],0,10))->TopN([Column#2],0,10)->TableReader(Table(t))}(Column#1,Column#25)->Limit" }, { "SQL": "select * from ((SELECT 1 a,3 b) UNION (SELECT 2,1) ORDER BY (SELECT 2)) t order by a,b", @@ -274,11 +274,11 @@ }, { "SQL": "select * from t t1 left join t t2 on t1.b = t2.a where 1 = 1 limit 1", - "Best": "IndexHashJoin{TableReader(Table(t)->Limit)->Limit->TableReader(Table(t))}(Column#2,Column#13)->Limit" + "Best": "IndexMergeJoin{TableReader(Table(t)->Limit)->Limit->TableReader(Table(t))}(Column#2,Column#13)->Limit" }, { "SQL": "select * from t t1 join t t2 on t1.b = t2.a and t1.c = 1 and t1.d = 1 and t1.e = 1 order by t1.a limit 1", - "Best": "IndexHashJoin{IndexLookUp(Index(t.c_d_e)[[1 1 1,1 1 1]], Table(t))->TableReader(Table(t))}(Column#2,Column#13)->TopN([Column#1],0,1)" + "Best": "IndexMergeJoin{IndexLookUp(Index(t.c_d_e)[[1 1 1,1 1 1]], Table(t))->TableReader(Table(t))}(Column#2,Column#13)->TopN([Column#1],0,1)" }, { "SQL": "select * from t t1 join t t2 on t1.b = t2.b join t t3 on t1.b = t3.b", @@ -294,7 +294,7 @@ }, { "SQL": "select * from t t1 join t t2 on t1.a = t2.a join t t3 on t1.a = t3.a and t1.b = 1 and t3.c = 1", - "Best": "IndexHashJoin{IndexHashJoin{TableReader(Table(t)->Sel([eq(Column#2, 1)]))->IndexLookUp(Index(t.c_d_e)[[1,1]], Table(t))}(Column#25,Column#1)->TableReader(Table(t))}(Column#1,Column#13)->Projection" + "Best": "IndexMergeJoin{IndexMergeJoin{TableReader(Table(t)->Sel([eq(Column#2, 1)]))->IndexLookUp(Index(t.c_d_e)[[1,1]], Table(t))}(Column#25,Column#1)->TableReader(Table(t))}(Column#1,Column#13)->Projection" }, { "SQL": "select * from t where t.c in (select b from t s where s.a = t.a)", @@ -354,15 +354,15 @@ }, { "SQL": "select /*+ TIDB_INLJ(t1, t2) */ * from t t1, t t2 where t1.a = t2.a", - "Best": "IndexHashJoin{TableReader(Table(t))->TableReader(Table(t))}(Column#1,Column#13)" + "Best": "IndexMergeJoin{TableReader(Table(t))->TableReader(Table(t))}(Column#1,Column#13)" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.c", - "Best": "IndexHashJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(Column#1,Column#15)" + "Best": "IndexMergeJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(Column#1,Column#15)" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ t1.a , t2.a from t t1, t t2 where t1.a = t2.c", - "Best": "IndexHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#1,Column#15)->Projection" + "Best": "IndexMergeJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#1,Column#15)->Projection" }, { "SQL": "select /*+ TIDB_INLJ(t1, t2) */ t1.a, t2.a from t t1, t t2 where t1.a = t2.a order by t1.c", @@ -374,7 +374,7 @@ }, { "SQL": "select /*+ TIDB_INLJ(t1) */ t1.a , t2.a from t t1, t t2 where t1.a = t2.c", - "Best": "IndexHashJoin{TableReader(Table(t))->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#15,Column#1)->Projection" + "Best": "IndexMergeJoin{TableReader(Table(t))->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#15,Column#1)->Projection" }, { "SQL": "select /*+ TIDB_INLJ(t1, t2) */ * from t t1 left outer join t t2 on t1.a = t2.a and t2.b < 1", @@ -398,23 +398,23 @@ }, { "SQL": "select /*+ TIDB_INLJ(t1) */ * from t t1 where t1.a in (select a from t t2)", - "Best": "IndexHashJoin{TableReader(Table(t))->IndexReader(Index(t.f)[[NULL,+inf]])}(Column#13,Column#1)->Projection" + "Best": "IndexMergeJoin{TableReader(Table(t))->IndexReader(Index(t.f)[[NULL,+inf]])}(Column#13,Column#1)->Projection" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.c=t2.c and t1.f=t2.f", - "Best": "IndexHashJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(Column#3,Column#15)" + "Best": "IndexMergeJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(Column#3,Column#15)" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.a = t2.a and t1.f=t2.f", - "Best": "IndexHashJoin{TableReader(Table(t))->TableReader(Table(t))}(Column#1,Column#13)" + "Best": "IndexMergeJoin{TableReader(Table(t))->TableReader(Table(t))}(Column#1,Column#13)" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.f=t2.f and t1.a=t2.a", - "Best": "IndexHashJoin{TableReader(Table(t))->TableReader(Table(t))}(Column#1,Column#13)" + "Best": "IndexMergeJoin{TableReader(Table(t))->TableReader(Table(t))}(Column#1,Column#13)" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.a=t2.a and t2.a in (1, 2)", - "Best": "IndexHashJoin{TableReader(Table(t))->TableReader(Table(t)->Sel([in(Column#13, 1, 2)]))}(Column#1,Column#13)" + "Best": "IndexMergeJoin{TableReader(Table(t))->TableReader(Table(t)->Sel([in(Column#13, 1, 2)]))}(Column#1,Column#13)" }, { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.b=t2.c and t1.b=1 and t2.d > t1.d-10 and t2.d < t1.d+10", @@ -528,8 +528,8 @@ }, { "SQL": "delete /*+ TIDB_INLJ(t1, t2) */ t1 from t t1, t t2 where t1.c=t2.c", - "Best": "IndexHashJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(Column#3,Column#15)->Delete", - "Hints": "USE_INDEX(@`del_1` `t1` ), USE_INDEX(@`del_1` `t2` `c_d_e`)" + "Best": "IndexMergeJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(Column#3,Column#15)->Delete", + "Hints": "USE_INDEX(@`del_1` `t1` ), USE_INDEX(@`del_1` `t2` `c_d_e`), INL_JOIN(@`del_1` `t2`)" }, { "SQL": "delete /*+ TIDB_SMJ(t1, t2) */ from t1 using t t1, t t2 where t1.c=t2.c", @@ -1026,9 +1026,9 @@ "Cases": [ { "SQL": "select /*+ TIDB_INLJ(t1) */ t1.a, t2.a, t3.a from t t1, t t2, t t3 where t1.a = t2.a and t2.a = t3.a;", - "Best": "RightHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexHashJoin{TableReader(Table(t))->IndexReader(Index(t.f)[[NULL,+inf]])}(Column#13,Column#1)}(Column#25,Column#13)->Projection", + "Best": "RightHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexMergeJoin{TableReader(Table(t))->IndexReader(Index(t.f)[[NULL,+inf]])}(Column#13,Column#1)}(Column#25,Column#13)->Projection", "Warning": "", - "Hints": "USE_INDEX(@`sel_1` `t3` `f`), USE_INDEX(@`sel_1` `t1` ), USE_INDEX(@`sel_1` `t2` `f`), HASH_JOIN(@`sel_1` `t3`)" + "Hints": "USE_INDEX(@`sel_1` `t3` `f`), USE_INDEX(@`sel_1` `t1` ), USE_INDEX(@`sel_1` `t2` `f`), INL_JOIN(@`sel_1` `t1`), HASH_JOIN(@`sel_1` `t3`)" }, { "SQL": "select /*+ TIDB_INLJ(t1) */ t1.b, t2.a from t t1, t t2 where t1.b = t2.a;", @@ -1124,13 +1124,13 @@ }, { "SQL": "select /*+ INL_JOIN(@sel_1 t1), HASH_JOIN(@sel_2 t2) */ t1.a, t1.b from t t1, (select t2.a from t t2, t t3 where t2.a = t3.c) s where t1.a=s.a", - "Plan": "IndexHashJoin{TableReader(Table(t))->LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#13,Column#27)}(Column#13,Column#1)->Projection", - "Hints": "USE_INDEX(@`sel_1` `t1` ), USE_INDEX(@`sel_2` `t2` `f`), USE_INDEX(@`sel_2` `t3` `c_d_e`), HASH_JOIN(@`sel_2` `t2`, `t3`)" + "Plan": "IndexMergeJoin{TableReader(Table(t))->LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#13,Column#27)}(Column#13,Column#1)->Projection", + "Hints": "USE_INDEX(@`sel_1` `t1` ), USE_INDEX(@`sel_2` `t2` `f`), USE_INDEX(@`sel_2` `t3` `c_d_e`), HASH_JOIN(@`sel_2` `t2`, `t3`), INL_JOIN(@`sel_1` `t1`)" }, { "SQL": "select /*+ INL_JOIN(@sel_1 t1), HASH_JOIN(@qb t2) */ t1.a, t1.b from t t1, (select /*+ QB_NAME(qb) */ t2.a from t t2, t t3 where t2.a = t3.c) s where t1.a=s.a", - "Plan": "IndexHashJoin{TableReader(Table(t))->LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#13,Column#27)}(Column#13,Column#1)->Projection", - "Hints": "USE_INDEX(@`sel_1` `t1` ), USE_INDEX(@`sel_2` `t2` `f`), USE_INDEX(@`sel_2` `t3` `c_d_e`), HASH_JOIN(@`sel_2` `t2`, `t3`)" + "Plan": "IndexMergeJoin{TableReader(Table(t))->LeftHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(Column#13,Column#27)}(Column#13,Column#1)->Projection", + "Hints": "USE_INDEX(@`sel_1` `t1` ), USE_INDEX(@`sel_2` `t2` `f`), USE_INDEX(@`sel_2` `t3` `c_d_e`), HASH_JOIN(@`sel_2` `t2`, `t3`), INL_JOIN(@`sel_1` `t1`)" }, { "SQL": "select /*+ HASH_AGG(@sel_1), STREAM_AGG(@sel_2) */ count(*) from t t1 where t1.a < (select count(*) from t t2 where t1.a > t2.a)", @@ -1154,15 +1154,15 @@ "Cases": [ { "SQL": "select /*+ TIDB_INLJ(t2) */ * from t t1, t t2 where t1.a = t2.a", - "Best": "IndexHashJoin{TableReader(Table(t))->UnionScan([])->TableReader(Table(t))->UnionScan([])}(Column#1,Column#13)" + "Best": "IndexMergeJoin{TableReader(Table(t))->UnionScan([])->TableReader(Table(t))->UnionScan([])}(Column#1,Column#13)" }, { "SQL": "select /*+ TIDB_INLJ(t1, t2) */ * from t t1, t t2 where t1.a = t2.c", - "Best": "IndexHashJoin{TableReader(Table(t))->UnionScan([])->TableReader(Table(t))->UnionScan([])}(Column#15,Column#1)" + "Best": "IndexMergeJoin{TableReader(Table(t))->UnionScan([])->TableReader(Table(t))->UnionScan([])}(Column#15,Column#1)" }, { "SQL": "select /*+ TIDB_INLJ(t1, t2) */ t1.a , t2.c from t t1, t t2 where t1.a = t2.c", - "Best": "IndexHashJoin{IndexReader(Index(t.f)[[NULL,+inf]])->UnionScan([])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])->UnionScan([])}(Column#1,Column#15)->Projection" + "Best": "IndexMergeJoin{IndexReader(Index(t.f)[[NULL,+inf]])->UnionScan([])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])->UnionScan([])}(Column#1,Column#15)->Projection" } ] }, @@ -1171,7 +1171,7 @@ "Cases": [ { "SQL": "select t1.a, (select count(t2.a) from t t2 where t2.g in (select t3.d from t t3 where t3.c = t1.a)) as agg_col from t t1;", - "Best": "Apply{IndexReader(Index(t.f)[[NULL,+inf]])->IndexHashJoin{IndexReader(Index(t.c_d_e)[[NULL,+inf]]->HashAgg)->HashAgg->IndexReader(Index(t.g)[[NULL,+inf]])}(Column#29,Column#23)}->HashAgg" + "Best": "Apply{IndexReader(Index(t.f)[[NULL,+inf]])->IndexMergeJoin{IndexReader(Index(t.c_d_e)[[NULL,+inf]]->HashAgg)->HashAgg->IndexReader(Index(t.g)[[NULL,+inf]])}(Column#29,Column#23)}->HashAgg" } ] } diff --git a/util/ranger/testdata/ranger_suite_out.json b/util/ranger/testdata/ranger_suite_out.json index 5dfae3a131d99..95cefa1a26917 100644 --- a/util/ranger/testdata/ranger_suite_out.json +++ b/util/ranger/testdata/ranger_suite_out.json @@ -10,11 +10,11 @@ " ├─TableReader_15 2.00 root data:TableScan_14", " │ └─TableScan_14 2.00 cop table:t, range:[-inf,+inf], keep order:false", " └─StreamAgg_20 1.00 root funcs:count(1)", - " └─IndexHashJoin_46 2.00 root inner join, inner:TableReader_39, outer key:Column#6, inner key:Column#11", + " └─IndexMergeJoin_44 2.00 root inner join, inner:TableReader_42, outer key:Column#6, inner key:Column#11", " ├─IndexReader_33 2.00 root index:IndexScan_32", " │ └─IndexScan_32 2.00 cop table:s, index:b, c, d, range: decided by [eq(Column#7, 1) in(Column#8, 1, 2) eq(Column#9, Column#1)], keep order:false", - " └─TableReader_39 1.00 root data:TableScan_38", - " └─TableScan_38 1.00 cop table:t1, range: decided by [Column#6], keep order:false" + " └─TableReader_42 1.00 root data:TableScan_41", + " └─TableScan_41 1.00 cop table:t1, range: decided by [Column#6], keep order:true" ] }, { From 29137abc00131283b76a28da4636e03cfc92cfb4 Mon Sep 17 00:00:00 2001 From: xuhuaiyu <391585975@qq.com> Date: Tue, 24 Sep 2019 10:41:33 +0800 Subject: [PATCH 6/7] remove useless code --- executor/adapter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/adapter.go b/executor/adapter.go index e17e497d4c4bf..3238865cdba6a 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -785,7 +785,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool) { slowItems.PrevStmt = sessVars.PrevStmt } if costTime < threshold { - //logutil.SlowQueryLogger.Debug(sessVars.SlowLogFormat(slowItems)) + logutil.SlowQueryLogger.Debug(sessVars.SlowLogFormat(slowItems)) } else { logutil.SlowQueryLogger.Warn(sessVars.SlowLogFormat(slowItems)) metrics.TotalQueryProcHistogram.Observe(costTime.Seconds()) From 0fe1cc34b129e58001269d774b6be23faba5d7b9 Mon Sep 17 00:00:00 2001 From: xuhuaiyu <391585975@qq.com> Date: Tue, 24 Sep 2019 20:22:02 +0800 Subject: [PATCH 7/7] address comment --- executor/builder.go | 1 - 1 file changed, 1 deletion(-) diff --git a/executor/builder.go b/executor/builder.go index f1fbbdc6078fa..0adaadebb3f83 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -1823,7 +1823,6 @@ func (b *executorBuilder) buildIndexNestedLoopHashJoin(v *plannercore.PhysicalIn concurrency := e.ctx.GetSessionVars().IndexLookupJoinConcurrency idxHash.joiners = make([]joiner, concurrency) for i := 0; i < concurrency; i++ { - // TODO: we may need to implement a Clone for joiner idxHash.joiners[i] = e.joiner.Clone() } return idxHash