From c3c467d9dc62fcad7f2462946e07deed130383be Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Tue, 30 Apr 2019 13:06:54 +0800 Subject: [PATCH] planner/core: fix privilege check for update (#10281) --- cmd/explaintest/r/explain_complex.result | 30 +-- .../r/explain_complex_stats.result | 30 +-- cmd/explaintest/r/explain_easy.result | 52 ++--- cmd/explaintest/r/explain_easy_stats.result | 10 +- cmd/explaintest/r/select.result | 18 +- cmd/explaintest/r/subquery.result | 6 +- cmd/explaintest/r/topn_push_down.result | 56 ++--- cmd/explaintest/r/tpch.result | 50 ++-- executor/merge_join_test.go | 2 +- planner/core/cbo_test.go | 12 +- planner/core/logical_plan_builder.go | 1 - planner/core/logical_plan_test.go | 221 +++++++++--------- planner/core/physical_plan_test.go | 126 +++++----- session/session_test.go | 23 ++ 14 files changed, 329 insertions(+), 308 deletions(-) diff --git a/cmd/explaintest/r/explain_complex.result b/cmd/explaintest/r/explain_complex.result index 6380dd5b5f9f3..38d116aff19e7 100644 --- a/cmd/explaintest/r/explain_complex.result +++ b/cmd/explaintest/r/explain_complex.result @@ -115,30 +115,30 @@ Projection_7 53.00 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt. └─TableScan_15 2650.00 cop table:dt, 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, gad.t as gtime from st gad join (select id, aid, pt, dic, ip, t from dd where pt = 'android' and bm = 0 and t > 1478143908) sdk on gad.aid = sdk.aid and gad.ip = sdk.ip and sdk.t > gad.t where gad.t > 1478143908 and gad.bm = 0 and gad.pt = 'android' group by gad.aid, sdk.dic limit 2500; id count task operator info -Projection_12 1.00 root gad.id, test.dd.id, gad.aid, gad.cm, test.dd.dic, test.dd.ip, test.dd.t, gad.p1, gad.p2, gad.p3, gad.p4, gad.p5, gad.p6_md5, gad.p7_md5, gad.ext, gad.t +Projection_12 1.00 root test.gad.id, test.dd.id, test.gad.aid, test.gad.cm, test.dd.dic, test.dd.ip, test.dd.t, test.gad.p1, test.gad.p2, test.gad.p3, test.gad.p4, test.gad.p5, test.gad.p6_md5, test.gad.p7_md5, test.gad.ext, test.gad.t └─Limit_15 1.00 root offset:0, count:2500 - └─HashAgg_18 1.00 root group by:gad.aid, test.dd.dic, funcs:firstrow(gad.id), firstrow(gad.aid), firstrow(gad.cm), firstrow(gad.p1), firstrow(gad.p2), firstrow(gad.p3), firstrow(gad.p4), firstrow(gad.p5), firstrow(gad.p6_md5), firstrow(gad.p7_md5), firstrow(gad.ext), firstrow(gad.t), firstrow(test.dd.id), firstrow(test.dd.dic), firstrow(test.dd.ip), firstrow(test.dd.t) - └─IndexJoin_23 0.00 root inner join, inner:IndexLookUp_22, outer key:gad.aid, inner key:test.dd.aid, other cond:eq(gad.ip, test.dd.ip), gt(test.dd.t, gad.t) + └─HashAgg_18 1.00 root group by:test.dd.dic, test.gad.aid, funcs:firstrow(test.gad.id), firstrow(test.gad.aid), firstrow(test.gad.cm), firstrow(test.gad.p1), firstrow(test.gad.p2), firstrow(test.gad.p3), firstrow(test.gad.p4), firstrow(test.gad.p5), firstrow(test.gad.p6_md5), firstrow(test.gad.p7_md5), firstrow(test.gad.ext), firstrow(test.gad.t), firstrow(test.dd.id), firstrow(test.dd.dic), firstrow(test.dd.ip), firstrow(test.dd.t) + └─IndexJoin_23 0.00 root inner join, inner:IndexLookUp_22, outer key:test.gad.aid, inner key:test.dd.aid, other cond:eq(test.gad.ip, test.dd.ip), gt(test.dd.t, test.gad.t) ├─IndexLookUp_32 0.00 root │ ├─IndexScan_29 3333.33 cop table:gad, index:t, range:(1478143908,+inf], keep order:false, stats:pseudo - │ └─Selection_31 0.00 cop eq(gad.bm, 0), eq(gad.pt, "android") + │ └─Selection_31 0.00 cop eq(test.gad.bm, 0), eq(test.gad.pt, "android") │ └─TableScan_30 3333.33 cop table:st, keep order:false, stats:pseudo └─IndexLookUp_22 0.00 root - ├─IndexScan_19 10.00 cop table:dd, index:aid, dic, range: decided by [gad.aid gad.ip], keep order:false, stats:pseudo + ├─IndexScan_19 10.00 cop table:dd, index:aid, dic, range: decided by [test.gad.aid test.gad.ip], keep order:false, stats:pseudo └─Selection_21 0.00 cop eq(test.dd.bm, 0), eq(test.dd.pt, "android"), gt(test.dd.t, 1478143908) └─TableScan_20 10.00 cop table:dd, 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_9 0.00 root gad.id, sdk.id, gad.aid, gad.cm, sdk.dic, sdk.ip, sdk.t, gad.p1, gad.p2, gad.p3, gad.p4, gad.p5, gad.p6_md5, gad.p7_md5, gad.ext +Projection_9 0.00 root test.gad.id, test.sdk.id, test.gad.aid, test.gad.cm, test.sdk.dic, test.sdk.ip, test.sdk.t, test.gad.p1, test.gad.p2, test.gad.p3, test.gad.p4, test.gad.p5, test.gad.p6_md5, test.gad.p7_md5, test.gad.ext └─Limit_12 0.00 root offset:0, count:3000 - └─IndexJoin_17 0.00 root inner join, inner:IndexLookUp_16, outer key:gad.aid, inner key:sdk.aid, other cond:eq(gad.dic, sdk.mac), lt(gad.t, sdk.t) + └─IndexJoin_17 0.00 root inner join, inner:IndexLookUp_16, outer key:test.gad.aid, inner key:test.sdk.aid, other cond:eq(test.gad.dic, test.sdk.mac), lt(test.gad.t, test.sdk.t) ├─IndexLookUp_26 0.00 root │ ├─IndexScan_23 3333.33 cop table:gad, index:t, range:(1477971479,+inf], keep order:false, stats:pseudo - │ └─Selection_25 0.00 cop eq(gad.bm, 0), eq(gad.dit, "mac"), eq(gad.pt, "ios") + │ └─Selection_25 0.00 cop eq(test.gad.bm, 0), eq(test.gad.dit, "mac"), eq(test.gad.pt, "ios") │ └─TableScan_24 3333.33 cop table:st, keep order:false, stats:pseudo └─IndexLookUp_16 0.00 root - ├─IndexScan_13 10.00 cop table:sdk, index:aid, dic, range: decided by [gad.aid gad.dic], keep order:false, stats:pseudo - └─Selection_15 0.00 cop eq(sdk.bm, 0), eq(sdk.pt, "ios"), gt(sdk.t, 1477971479) + ├─IndexScan_13 10.00 cop table:sdk, index:aid, dic, range: decided by [test.gad.aid test.gad.dic], keep order:false, stats:pseudo + └─Selection_15 0.00 cop eq(test.sdk.bm, 0), eq(test.sdk.pt, "ios"), gt(test.sdk.t, 1477971479) └─TableScan_14 10.00 cop table:dd, keep order:false, stats:pseudo explain SELECT cm, p1, p2, p3, p4, p5, p6_md5, p7_md5, count(1) as click_pv, count(DISTINCT ip) as click_ip FROM st WHERE (t between 1478188800 and 1478275200) and aid='cn.sbkcq' and pt='android' GROUP BY cm, p1, p2, p3, p4, p5, p6_md5, p7_md5; id count task operator info @@ -150,15 +150,15 @@ Projection_5 1.00 root test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st.p └─TableScan_14 250.00 cop table:st, keep order:false, stats:pseudo explain select dt.id as id, dt.aid as aid, dt.pt as pt, dt.dic as dic, dt.cm as cm, rr.gid as gid, rr.acd as acd, rr.t as t,dt.p1 as p1, dt.p2 as p2, dt.p3 as p3, dt.p4 as p4, dt.p5 as p5, dt.p6_md5 as p6, dt.p7_md5 as p7 from dt dt join rr rr on (rr.pt = 'ios' and rr.t > 1478185592 and dt.aid = rr.aid and dt.dic = rr.dic) where dt.pt = 'ios' and dt.t > 1478185592 and dt.bm = 0 limit 2000; id count task operator info -Projection_9 0.00 root dt.id, dt.aid, dt.pt, dt.dic, dt.cm, rr.gid, rr.acd, rr.t, dt.p1, dt.p2, dt.p3, dt.p4, dt.p5, dt.p6_md5, dt.p7_md5 +Projection_9 0.00 root test.dt.id, test.dt.aid, test.dt.pt, test.dt.dic, test.dt.cm, test.rr.gid, test.rr.acd, test.rr.t, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5 └─Limit_12 0.00 root offset:0, count:2000 - └─IndexJoin_18 0.00 root inner join, inner:IndexLookUp_17, outer key:dt.aid, dt.dic, inner key:rr.aid, rr.dic + └─IndexJoin_18 0.00 root inner join, inner:IndexLookUp_17, outer key:test.dt.aid, test.dt.dic, inner key:test.rr.aid, test.rr.dic ├─TableReader_38 0.00 root data:Selection_37 - │ └─Selection_37 0.00 cop eq(dt.bm, 0), eq(dt.pt, "ios"), gt(dt.t, 1478185592) + │ └─Selection_37 0.00 cop eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592) │ └─TableScan_36 10000.00 cop table:dt, range:[0,+inf], keep order:false, stats:pseudo └─IndexLookUp_17 3.33 root - ├─IndexScan_14 10.00 cop table:rr, index:aid, dic, range: decided by [dt.aid dt.dic], keep order:false, stats:pseudo - └─Selection_16 3.33 cop eq(rr.pt, "ios"), gt(rr.t, 1478185592) + ├─IndexScan_14 10.00 cop table:rr, index:aid, dic, range: decided by [test.dt.aid test.dt.dic], keep order:false, stats:pseudo + └─Selection_16 3.33 cop eq(test.rr.pt, "ios"), gt(test.rr.t, 1478185592) └─TableScan_15 10.00 cop table:rr, keep order:false, stats:pseudo 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 diff --git a/cmd/explaintest/r/explain_complex_stats.result b/cmd/explaintest/r/explain_complex_stats.result index e05f88234f156..452fbc7cfc1d5 100644 --- a/cmd/explaintest/r/explain_complex_stats.result +++ b/cmd/explaintest/r/explain_complex_stats.result @@ -125,28 +125,28 @@ Projection_7 21.40 root test.dt.ds, test.dt.p1, test.dt.p2, test.dt.p3, test.dt. └─TableScan_15 128.32 cop table:dt, keep order:false 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, gad.t as gtime from st gad join (select id, aid, pt, dic, ip, t from dd where pt = 'android' and bm = 0 and t > 1478143908) sdk on gad.aid = sdk.aid and gad.ip = sdk.ip and sdk.t > gad.t where gad.t > 1478143908 and gad.bm = 0 and gad.pt = 'android' group by gad.aid, sdk.dic limit 2500; id count task operator info -Projection_12 424.00 root gad.id, test.dd.id, gad.aid, gad.cm, test.dd.dic, test.dd.ip, test.dd.t, gad.p1, gad.p2, gad.p3, gad.p4, gad.p5, gad.p6_md5, gad.p7_md5, gad.ext, gad.t +Projection_12 424.00 root test.gad.id, test.dd.id, test.gad.aid, test.gad.cm, test.dd.dic, test.dd.ip, test.dd.t, test.gad.p1, test.gad.p2, test.gad.p3, test.gad.p4, test.gad.p5, test.gad.p6_md5, test.gad.p7_md5, test.gad.ext, test.gad.t └─Limit_15 424.00 root offset:0, count:2500 - └─HashAgg_18 424.00 root group by:gad.aid, test.dd.dic, funcs:firstrow(gad.id), firstrow(gad.aid), firstrow(gad.cm), firstrow(gad.p1), firstrow(gad.p2), firstrow(gad.p3), firstrow(gad.p4), firstrow(gad.p5), firstrow(gad.p6_md5), firstrow(gad.p7_md5), firstrow(gad.ext), firstrow(gad.t), firstrow(test.dd.id), firstrow(test.dd.dic), firstrow(test.dd.ip), firstrow(test.dd.t) - └─IndexJoin_23 424.00 root inner join, inner:IndexLookUp_22, outer key:gad.aid, inner key:test.dd.aid, other cond:eq(gad.ip, test.dd.ip), gt(test.dd.t, gad.t) + └─HashAgg_18 424.00 root group by:test.dd.dic, test.gad.aid, funcs:firstrow(test.gad.id), firstrow(test.gad.aid), firstrow(test.gad.cm), firstrow(test.gad.p1), firstrow(test.gad.p2), firstrow(test.gad.p3), firstrow(test.gad.p4), firstrow(test.gad.p5), firstrow(test.gad.p6_md5), firstrow(test.gad.p7_md5), firstrow(test.gad.ext), firstrow(test.gad.t), firstrow(test.dd.id), firstrow(test.dd.dic), firstrow(test.dd.ip), firstrow(test.dd.t) + └─IndexJoin_23 424.00 root inner join, inner:IndexLookUp_22, outer key:test.gad.aid, inner key:test.dd.aid, other cond:eq(test.gad.ip, test.dd.ip), gt(test.dd.t, test.gad.t) ├─TableReader_28 424.00 root data:Selection_27 - │ └─Selection_27 424.00 cop eq(gad.bm, 0), eq(gad.pt, "android"), gt(gad.t, 1478143908) + │ └─Selection_27 424.00 cop eq(test.gad.bm, 0), eq(test.gad.pt, "android"), gt(test.gad.t, 1478143908) │ └─TableScan_26 1999.00 cop table:gad, range:[0,+inf], keep order:false └─IndexLookUp_22 455.80 root - ├─IndexScan_19 1.00 cop table:dd, index:aid, dic, range: decided by [gad.aid gad.ip], keep order:false + ├─IndexScan_19 1.00 cop table:dd, index:aid, dic, range: decided by [test.gad.aid test.gad.ip], keep order:false └─Selection_21 455.80 cop eq(test.dd.bm, 0), eq(test.dd.pt, "android"), gt(test.dd.t, 1478143908) └─TableScan_20 1.00 cop table:dd, keep order:false 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_9 170.34 root gad.id, sdk.id, gad.aid, gad.cm, sdk.dic, sdk.ip, sdk.t, gad.p1, gad.p2, gad.p3, gad.p4, gad.p5, gad.p6_md5, gad.p7_md5, gad.ext +Projection_9 170.34 root test.gad.id, test.sdk.id, test.gad.aid, test.gad.cm, test.sdk.dic, test.sdk.ip, test.sdk.t, test.gad.p1, test.gad.p2, test.gad.p3, test.gad.p4, test.gad.p5, test.gad.p6_md5, test.gad.p7_md5, test.gad.ext └─Limit_12 170.34 root offset:0, count:3000 - └─IndexJoin_17 170.34 root inner join, inner:IndexLookUp_16, outer key:gad.aid, inner key:sdk.aid, other cond:eq(gad.dic, sdk.mac), lt(gad.t, sdk.t) + └─IndexJoin_17 170.34 root inner join, inner:IndexLookUp_16, outer key:test.gad.aid, inner key:test.sdk.aid, other cond:eq(test.gad.dic, test.sdk.mac), lt(test.gad.t, test.sdk.t) ├─TableReader_22 170.34 root data:Selection_21 - │ └─Selection_21 170.34 cop eq(gad.bm, 0), eq(gad.dit, "mac"), eq(gad.pt, "ios"), gt(gad.t, 1477971479) + │ └─Selection_21 170.34 cop eq(test.gad.bm, 0), eq(test.gad.dit, "mac"), eq(test.gad.pt, "ios"), gt(test.gad.t, 1477971479) │ └─TableScan_20 1999.00 cop table:gad, range:[0,+inf], keep order:false └─IndexLookUp_16 509.04 root - ├─IndexScan_13 1.00 cop table:sdk, index:aid, dic, range: decided by [gad.aid gad.dic], keep order:false - └─Selection_15 509.04 cop eq(sdk.bm, 0), eq(sdk.pt, "ios"), gt(sdk.t, 1477971479) + ├─IndexScan_13 1.00 cop table:sdk, index:aid, dic, range: decided by [test.gad.aid test.gad.dic], keep order:false + └─Selection_15 509.04 cop eq(test.sdk.bm, 0), eq(test.sdk.pt, "ios"), gt(test.sdk.t, 1477971479) └─TableScan_14 1.00 cop table:dd, keep order:false explain SELECT cm, p1, p2, p3, p4, p5, p6_md5, p7_md5, count(1) as click_pv, count(DISTINCT ip) as click_ip FROM st WHERE (t between 1478188800 and 1478275200) and aid='cn.sbkcq' and pt='android' GROUP BY cm, p1, p2, p3, p4, p5, p6_md5, p7_md5; id count task operator info @@ -158,15 +158,15 @@ Projection_5 39.28 root test.st.cm, test.st.p1, test.st.p2, test.st.p3, test.st. └─TableScan_14 160.23 cop table:st, keep order:false explain select dt.id as id, dt.aid as aid, dt.pt as pt, dt.dic as dic, dt.cm as cm, rr.gid as gid, rr.acd as acd, rr.t as t,dt.p1 as p1, dt.p2 as p2, dt.p3 as p3, dt.p4 as p4, dt.p5 as p5, dt.p6_md5 as p6, dt.p7_md5 as p7 from dt dt join rr rr on (rr.pt = 'ios' and rr.t > 1478185592 and dt.aid = rr.aid and dt.dic = rr.dic) where dt.pt = 'ios' and dt.t > 1478185592 and dt.bm = 0 limit 2000; id count task operator info -Projection_9 428.32 root dt.id, dt.aid, dt.pt, dt.dic, dt.cm, rr.gid, rr.acd, rr.t, dt.p1, dt.p2, dt.p3, dt.p4, dt.p5, dt.p6_md5, dt.p7_md5 +Projection_9 428.32 root test.dt.id, test.dt.aid, test.dt.pt, test.dt.dic, test.dt.cm, test.rr.gid, test.rr.acd, test.rr.t, test.dt.p1, test.dt.p2, test.dt.p3, test.dt.p4, test.dt.p5, test.dt.p6_md5, test.dt.p7_md5 └─Limit_12 428.32 root offset:0, count:2000 - └─IndexJoin_18 428.32 root inner join, inner:IndexLookUp_17, outer key:dt.aid, dt.dic, inner key:rr.aid, rr.dic + └─IndexJoin_18 428.32 root inner join, inner:IndexLookUp_17, outer key:test.dt.aid, test.dt.dic, inner key:test.rr.aid, test.rr.dic ├─TableReader_38 428.32 root data:Selection_37 - │ └─Selection_37 428.32 cop eq(dt.bm, 0), eq(dt.pt, "ios"), gt(dt.t, 1478185592) + │ └─Selection_37 428.32 cop eq(test.dt.bm, 0), eq(test.dt.pt, "ios"), gt(test.dt.t, 1478185592) │ └─TableScan_36 2000.00 cop table:dt, range:[0,+inf], keep order:false └─IndexLookUp_17 970.00 root - ├─IndexScan_14 1.00 cop table:rr, index:aid, dic, range: decided by [dt.aid dt.dic], keep order:false - └─Selection_16 970.00 cop eq(rr.pt, "ios"), gt(rr.t, 1478185592) + ├─IndexScan_14 1.00 cop table:rr, index:aid, dic, range: decided by [test.dt.aid test.dt.dic], keep order:false + └─Selection_16 970.00 cop eq(test.rr.pt, "ios"), gt(test.rr.t, 1478185592) └─TableScan_15 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 diff --git a/cmd/explaintest/r/explain_easy.result b/cmd/explaintest/r/explain_easy.result index abbd582403637..b75ee616c0bd6 100644 --- a/cmd/explaintest/r/explain_easy.result +++ b/cmd/explaintest/r/explain_easy.result @@ -10,13 +10,13 @@ set @@session.tidb_opt_agg_push_down = 1; explain select * from t3 where exists (select s.a from t3 s having sum(s.a) = t3.a ); id count task operator info Projection_12 8000.00 root test.t3.a, test.t3.b, test.t3.c, test.t3.d -└─HashLeftJoin_13 8000.00 root semi join, inner:StreamAgg_29, equal:[eq(cast(test.t3.a), sel_agg_1)] +└─HashLeftJoin_13 8000.00 root semi join, inner:StreamAgg_29, equal:[eq(cast(test.t3.a), sel_agg_2)] ├─Projection_14 10000.00 root test.t3.a, test.t3.b, test.t3.c, test.t3.d, cast(test.t3.a) │ └─TableReader_16 10000.00 root data:TableScan_15 │ └─TableScan_15 10000.00 cop table:t3, range:[-inf,+inf], keep order:false, stats:pseudo └─StreamAgg_29 1.00 root funcs:sum(col_0) └─TableReader_30 1.00 root data:StreamAgg_21 - └─StreamAgg_21 1.00 cop funcs:sum(s.a) + └─StreamAgg_21 1.00 cop funcs:sum(test.s.a) └─TableScan_28 10000.00 cop table:s, range:[-inf,+inf], keep order:false, stats:pseudo explain select * from t1; id count task operator info @@ -59,12 +59,12 @@ IndexLookUp_9 10.00 root 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 10000.00 root cast(join_agg_0) -└─IndexJoin_14 10000.00 root inner join, inner:TableReader_13, outer key:b.c2, inner key:a.c1 +└─IndexJoin_14 10000.00 root inner join, inner:TableReader_13, outer key:test.b.c2, inner key:test.a.c1 ├─TableReader_13 1.00 root data:TableScan_12 - │ └─TableScan_12 1.00 cop table:a, range: decided by [b.c2], keep order:false, stats:pseudo + │ └─TableScan_12 1.00 cop table:a, range: decided by [test.b.c2], keep order:false, stats:pseudo └─HashAgg_21 8000.00 root group by:col_2, funcs:count(col_0), firstrow(col_1) └─TableReader_22 8000.00 root data:HashAgg_17 - └─HashAgg_17 8000.00 cop group by:b.c2, funcs:count(b.c2), firstrow(b.c2) + └─HashAgg_17 8000.00 cop group by:test.b.c2, funcs:count(test.b.c2), firstrow(test.b.c2) └─TableScan_20 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 @@ -98,11 +98,11 @@ explain select (select count(1) k from t1 s where s.c1 = t1.c1 having k != 0) fr id count task operator info Projection_13 10000.00 root k └─Projection_14 10000.00 root test.t1.c1, ifnull(5_col_0, 0) - └─MergeJoin_15 10000.00 root left outer join, left key:test.t1.c1, right key:s.c1 + └─MergeJoin_15 10000.00 root left outer join, left key:test.t1.c1, right key:test.s.c1 ├─TableReader_18 10000.00 root data:TableScan_17 │ └─TableScan_17 10000.00 cop table:t1, range:[-inf,+inf], keep order:true, stats:pseudo └─Selection_19 8000.00 root ne(k, 0) - └─Projection_20 10000.00 root 1, s.c1 + └─Projection_20 10000.00 root 1, test.s.c1 └─TableReader_22 10000.00 root data:TableScan_21 └─TableScan_21 10000.00 cop table:s, range:[-inf,+inf], keep order:true, stats:pseudo explain select * from information_schema.columns; @@ -276,12 +276,12 @@ Projection_11 10000.00 root 9_aux_0 ├─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) - └─IndexJoin_44 10000.00 root inner join, inner:TableReader_43, outer key:s.a, inner key:t1.a + └─IndexJoin_44 10000.00 root inner join, inner:TableReader_43, outer key:test.s.a, inner key:test.t1.a ├─TableReader_37 1.00 root data:TableScan_36 - │ └─TableScan_36 1.00 cop table:s, range: decided by [eq(s.a, test.t.a)], keep order:false, stats:pseudo + │ └─TableScan_36 1.00 cop table:s, range: decided by [eq(test.s.a, test.t.a)], keep order:false, stats:pseudo └─TableReader_43 0.80 root data:Selection_42 - └─Selection_42 0.80 cop eq(t1.a, test.t.a) - └─TableScan_41 1.00 cop table:t1, range: decided by [s.a], keep order:false, stats:pseudo + └─Selection_42 0.80 cop eq(test.t1.a, test.t.a) + └─TableScan_41 1.00 cop table:t1, range: decided by [test.s.a], 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.a = t1.a) from t; id count task operator info Projection_11 10000.00 root 9_aux_0 @@ -289,11 +289,11 @@ Projection_11 10000.00 root 9_aux_0 ├─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) - └─IndexJoin_32 10000.00 root inner join, inner:TableReader_31, outer key:s.a, inner key:t1.a + └─IndexJoin_32 10000.00 root inner join, inner:TableReader_31, outer key:test.s.a, inner key:test.t1.a ├─IndexReader_27 10000.00 root index:IndexScan_26 - │ └─IndexScan_26 10000.00 cop table:s, index:b, range: decided by [eq(s.b, test.t.a)], keep order:false, stats:pseudo + │ └─IndexScan_26 10000.00 cop table:s, index:b, range: decided by [eq(test.s.b, test.t.a)], keep order:false, stats:pseudo └─TableReader_31 1.00 root data:TableScan_30 - └─TableScan_30 1.00 cop table:t1, range: decided by [s.a], keep order:false, stats:pseudo + └─TableScan_30 1.00 cop table:t1, range: decided by [test.s.a], 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 9_aux_0 @@ -301,12 +301,12 @@ Projection_11 10000.00 root 9_aux_0 ├─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) - └─IndexJoin_33 10000.00 root inner join, inner:TableReader_32, outer key:s.c, inner key:t1.a + └─IndexJoin_33 10000.00 root inner join, inner:TableReader_32, outer key:test.s.c, inner key:test.t1.a ├─IndexLookUp_28 10000.00 root - │ ├─IndexScan_26 10000.00 cop table:s, index:b, range: decided by [eq(s.b, test.t.a)], keep order:false, stats:pseudo + │ ├─IndexScan_26 10000.00 cop table:s, index:b, range: decided by [eq(test.s.b, test.t.a)], keep order:false, stats:pseudo │ └─TableScan_27 10000.00 cop table:t, keep order:false, stats:pseudo └─TableReader_32 1.00 root data:TableScan_31 - └─TableScan_31 1.00 cop table:t1, range: decided by [s.c], keep order:false, stats:pseudo + └─TableScan_31 1.00 cop table:t1, range: decided by [test.s.c], 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; @@ -316,13 +316,13 @@ Projection_11 5.00 root 9_aux_0 ├─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) - └─IndexJoin_49 2.40 root inner join, inner:TableReader_48, outer key:s.a, inner key:t1.a + └─IndexJoin_49 2.40 root inner join, inner:TableReader_48, outer key:test.s.a, inner key:test.t1.a ├─IndexReader_41 2.40 root index:Selection_40 │ └─Selection_40 2.40 cop eq(3, test.t.a) │ └─IndexScan_39 3.00 cop table:s, index:b, range:[3,3], keep order:false └─TableReader_48 0.80 root data:Selection_47 └─Selection_47 0.80 cop eq(3, test.t.a) - └─TableScan_46 1.00 cop table:t1, range: decided by [s.a], keep order:false + └─TableScan_46 1.00 cop table:t1, range: decided by [test.s.a], keep order:false 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 9_aux_0 @@ -330,13 +330,13 @@ Projection_10 5.00 root 9_aux_0 ├─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) - └─IndexJoin_43 2.40 root left outer join, inner:TableReader_42, outer key:s.a, inner key:t1.a + └─IndexJoin_43 2.40 root left outer join, inner:TableReader_42, outer key:test.s.a, inner key:test.t1.a ├─IndexReader_35 2.40 root index:Selection_34 │ └─Selection_34 2.40 cop eq(3, test.t.a) │ └─IndexScan_33 3.00 cop table:s, index:b, range:[3,3], keep order:false └─TableReader_42 0.80 root data:Selection_41 └─Selection_41 0.80 cop eq(3, test.t.a) - └─TableScan_40 1.00 cop table:t1, range: decided by [s.a], keep order:false + └─TableScan_40 1.00 cop table:t1, range: decided by [test.s.a], keep order:false 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 9_aux_0 @@ -344,10 +344,10 @@ Projection_10 5.00 root 9_aux_0 ├─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) - └─IndexJoin_43 2.40 root right outer join, inner:TableReader_42, outer key:t1.a, inner key:s.a + └─IndexJoin_43 2.40 root right outer join, inner:TableReader_42, outer key:test.t1.a, inner key:test.s.a ├─TableReader_42 0.80 root data:Selection_41 │ └─Selection_41 0.80 cop eq(3, test.t.a) - │ └─TableScan_40 1.00 cop table:s, range: decided by [t1.a], keep order:false + │ └─TableScan_40 1.00 cop table:s, range: decided by [test.t1.a], keep order:false └─IndexReader_35 2.40 root index:Selection_34 └─Selection_34 2.40 cop eq(3, test.t.a) └─IndexScan_33 3.00 cop table:t1, index:b, range:[3,3], keep order:false @@ -396,10 +396,10 @@ id count task operator info TableDual_5 0.00 root rows:0 explain select * from t t1 join t t2 where t1.b = t2.b and t2.b is null; id count task operator info -Projection_7 12.50 root t1.a, t1.b, t2.a, t2.b -└─HashRightJoin_9 12.50 root inner join, inner:TableReader_12, equal:[eq(t2.b, t1.b)] +Projection_7 12.50 root test.t1.a, test.t1.b, test.t2.a, test.t2.b +└─HashRightJoin_9 12.50 root inner join, inner:TableReader_12, equal:[eq(test.t2.b, test.t1.b)] ├─TableReader_12 10.00 root data:Selection_11 - │ └─Selection_11 10.00 cop isnull(t2.b) + │ └─Selection_11 10.00 cop isnull(test.t2.b) │ └─TableScan_10 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo └─TableReader_14 10000.00 root data:TableScan_13 └─TableScan_13 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo diff --git a/cmd/explaintest/r/explain_easy_stats.result b/cmd/explaintest/r/explain_easy_stats.result index 6e05d521f9033..e8f1b7ea26957 100644 --- a/cmd/explaintest/r/explain_easy_stats.result +++ b/cmd/explaintest/r/explain_easy_stats.result @@ -13,13 +13,13 @@ set @@session.tidb_opt_agg_push_down = 1; explain select * from t3 where exists (select s.a from t3 s having sum(s.a) = t3.a ); id count task operator info Projection_12 1600.00 root test.t3.a, test.t3.b, test.t3.c, test.t3.d -└─HashLeftJoin_13 1600.00 root semi join, inner:StreamAgg_29, equal:[eq(cast(test.t3.a), sel_agg_1)] +└─HashLeftJoin_13 1600.00 root semi join, inner:StreamAgg_29, equal:[eq(cast(test.t3.a), sel_agg_2)] ├─Projection_14 2000.00 root test.t3.a, test.t3.b, test.t3.c, test.t3.d, cast(test.t3.a) │ └─TableReader_16 2000.00 root data:TableScan_15 │ └─TableScan_15 2000.00 cop table:t3, range:[-inf,+inf], keep order:false └─StreamAgg_29 1.00 root funcs:sum(col_0) └─TableReader_30 1.00 root data:StreamAgg_21 - └─StreamAgg_21 1.00 cop funcs:sum(s.a) + └─StreamAgg_21 1.00 cop funcs:sum(test.s.a) └─TableScan_28 2000.00 cop table:s, range:[-inf,+inf], keep order:false explain select * from t1; id count task operator info @@ -65,12 +65,12 @@ IndexLookUp_9 0.00 root 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(join_agg_0) -└─IndexJoin_14 1985.00 root inner join, inner:TableReader_13, outer key:b.c2, inner key:a.c1 +└─IndexJoin_14 1985.00 root inner join, inner:TableReader_13, outer key:test.b.c2, inner key:test.a.c1 ├─TableReader_13 1.00 root data:TableScan_12 - │ └─TableScan_12 1.00 cop table:a, range: decided by [b.c2], keep order:false + │ └─TableScan_12 1.00 cop table:a, range: decided by [test.b.c2], keep order:false └─HashAgg_21 1985.00 root group by:col_2, funcs:count(col_0), firstrow(col_1) └─TableReader_22 1985.00 root data:HashAgg_17 - └─HashAgg_17 1985.00 cop group by:b.c2, funcs:count(b.c2), firstrow(b.c2) + └─HashAgg_17 1985.00 cop group by:test.b.c2, funcs:count(test.b.c2), firstrow(test.b.c2) └─TableScan_20 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 diff --git a/cmd/explaintest/r/select.result b/cmd/explaintest/r/select.result index 88976590bd186..71d59dd5cacbc 100644 --- a/cmd/explaintest/r/select.result +++ b/cmd/explaintest/r/select.result @@ -309,13 +309,13 @@ drop table if exists t; create table t (id int primary key, a int, b int); explain select * from (t t1 left join t t2 on t1.a = t2.a) left join (t t3 left join t t4 on t3.a = t4.a) on t2.b = 1; id count task operator info -HashLeftJoin_10 156250000.00 root left outer join, inner:HashLeftJoin_16, left cond:[eq(t2.b, 1)] -├─HashLeftJoin_11 12500.00 root left outer join, inner:TableReader_15, equal:[eq(t1.a, t2.a)] +HashLeftJoin_10 156250000.00 root left outer join, inner:HashLeftJoin_16, left cond:[eq(test.t2.b, 1)] +├─HashLeftJoin_11 12500.00 root left outer join, inner:TableReader_15, equal:[eq(test.t1.a, test.t2.a)] │ ├─TableReader_13 10000.00 root data:TableScan_12 │ │ └─TableScan_12 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo │ └─TableReader_15 10000.00 root data:TableScan_14 │ └─TableScan_14 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo -└─HashLeftJoin_16 12500.00 root left outer join, inner:TableReader_20, equal:[eq(t3.a, t4.a)] +└─HashLeftJoin_16 12500.00 root left outer join, inner:TableReader_20, equal:[eq(test.t3.a, test.t4.a)] ├─TableReader_18 10000.00 root data:TableScan_17 │ └─TableScan_17 10000.00 cop table:t3, range:[-inf,+inf], keep order:false, stats:pseudo └─TableReader_20 10000.00 root data:TableScan_19 @@ -336,22 +336,22 @@ drop table if exists t; create table t(a int, b int); explain select a != any (select a from t t2) from t t1; id count task operator info -Projection_9 10000.00 root and(or(or(gt(col_count, 1), ne(t1.a, col_firstrow)), if(ne(agg_col_sum, 0), NULL, 0)), and(ne(agg_col_cnt, 0), if(isnull(t1.a), NULL, 1))) +Projection_9 10000.00 root and(or(or(gt(col_count, 1), ne(test.t1.a, col_firstrow)), if(ne(agg_col_sum, 0), NULL, 0)), and(ne(agg_col_cnt, 0), if(isnull(test.t1.a), NULL, 1))) └─HashLeftJoin_10 10000.00 root inner join, inner:StreamAgg_17 ├─TableReader_13 10000.00 root data:TableScan_12 │ └─TableScan_12 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo └─StreamAgg_17 1.00 root funcs:firstrow(col_0), count(distinct col_1), sum(col_2), count(1) - └─Projection_27 10000.00 root t2.a, t2.a, cast(isnull(t2.a)) + └─Projection_27 10000.00 root test.t2.a, test.t2.a, cast(isnull(test.t2.a)) └─TableReader_24 10000.00 root data:TableScan_23 └─TableScan_23 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo explain select a = all (select a from t t2) from t t1; id count task operator info -Projection_9 10000.00 root or(and(and(le(col_count, 1), eq(t1.a, col_firstrow)), if(ne(agg_col_sum, 0), NULL, 1)), or(eq(agg_col_cnt, 0), if(isnull(t1.a), NULL, 0))) +Projection_9 10000.00 root or(and(and(le(col_count, 1), eq(test.t1.a, col_firstrow)), if(ne(agg_col_sum, 0), NULL, 1)), or(eq(agg_col_cnt, 0), if(isnull(test.t1.a), NULL, 0))) └─HashLeftJoin_10 10000.00 root inner join, inner:StreamAgg_17 ├─TableReader_13 10000.00 root data:TableScan_12 │ └─TableScan_12 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo └─StreamAgg_17 1.00 root funcs:firstrow(col_0), count(distinct col_1), sum(col_2), count(1) - └─Projection_27 10000.00 root t2.a, t2.a, cast(isnull(t2.a)) + └─Projection_27 10000.00 root test.t2.a, test.t2.a, cast(isnull(test.t2.a)) └─TableReader_24 10000.00 root data:TableScan_23 └─TableScan_23 10000.00 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo drop table if exists t; @@ -371,7 +371,7 @@ Projection_9 10000.00 root 6_aux_0 explain select a in (select a+b from t t2 where t2.b = t1.b) from t t1; id count task operator info Projection_7 10000.00 root 6_aux_0 -└─HashLeftJoin_8 10000.00 root left outer semi join, inner:TableReader_12, equal:[eq(t1.b, t2.b)], other cond:eq(t1.a, plus(t2.a, t2.b)) +└─HashLeftJoin_8 10000.00 root left outer semi join, inner:TableReader_12, equal:[eq(test.t1.b, test.t2.b)], other cond:eq(test.t1.a, plus(test.t2.a, test.t2.b)) ├─TableReader_10 10000.00 root data:TableScan_9 │ └─TableScan_9 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo └─TableReader_12 10000.00 root data:TableScan_11 @@ -381,7 +381,7 @@ create table t(a int not null, b int); explain select a in (select a from t t2 where t2.b = t1.b) from t t1; id count task operator info Projection_7 10000.00 root 6_aux_0 -└─HashLeftJoin_8 10000.00 root left outer semi join, inner:TableReader_12, equal:[eq(t1.b, t2.b) eq(t1.a, t2.a)] +└─HashLeftJoin_8 10000.00 root left outer semi join, inner:TableReader_12, equal:[eq(test.t1.b, test.t2.b) eq(test.t1.a, test.t2.a)] ├─TableReader_10 10000.00 root data:TableScan_9 │ └─TableScan_9 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo └─TableReader_12 10000.00 root data:TableScan_11 diff --git a/cmd/explaintest/r/subquery.result b/cmd/explaintest/r/subquery.result index 2596bc5ae4208..b864a04d55ce6 100644 --- a/cmd/explaintest/r/subquery.result +++ b/cmd/explaintest/r/subquery.result @@ -20,8 +20,8 @@ Projection_11 5.00 root 9_aux_0 ├─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) - └─IndexJoin_23 0.50 root inner join, inner:TableReader_22, outer key:s.a, inner key:t1.a + └─IndexJoin_23 0.50 root inner join, inner:TableReader_22, outer key:test.s.a, inner key:test.t1.a ├─IndexReader_27 1.00 root index:IndexScan_26 - │ └─IndexScan_26 1.00 cop table:s, index:b, c, d, range: decided by [eq(s.b, 1) eq(s.c, 1) eq(s.d, test.t.a)], keep order:false + │ └─IndexScan_26 1.00 cop table:s, index:b, c, d, range: decided by [eq(test.s.b, 1) eq(test.s.c, 1) eq(test.s.d, test.t.a)], keep order:false └─TableReader_22 1.00 root data:TableScan_21 - └─TableScan_21 1.00 cop table:t1, range: decided by [s.a], keep order:false + └─TableScan_21 1.00 cop table:t1, range: decided by [test.s.a], keep order:false diff --git a/cmd/explaintest/r/topn_push_down.result b/cmd/explaintest/r/topn_push_down.result index 6b5ee3ff229fe..81828661b0fa3 100644 --- a/cmd/explaintest/r/topn_push_down.result +++ b/cmd/explaintest/r/topn_push_down.result @@ -167,22 +167,22 @@ te.expect_time BETWEEN '2018-04-23 00:00:00.0' AND '2018-04-23 23:59:59.0' ORDER BY te.expect_time asc LIMIT 0, 5; id count task operator info -Projection_12 0.00 root te.expect_time -└─Limit_18 0.00 root offset:0, count:5 - └─IndexJoin_100 0.00 root left outer join, inner:IndexReader_99, outer key:tr.id, inner key:p.relate_id - ├─TopN_103 0.00 root te.expect_time:asc, offset:0, count:5 - │ └─IndexJoin_34 0.00 root inner join, inner:IndexLookUp_33, outer key:tr.id, inner key:te.trade_id - │ ├─IndexLookUp_82 0.00 root - │ │ ├─Selection_80 0.00 cop eq(tr.business_type, 18), in(tr.trade_type, 1) - │ │ │ └─IndexScan_78 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_81 0.00 cop eq(tr.brand_identy, 32314), eq(tr.domain_type, 2) - │ │ └─TableScan_79 0.00 cop table:tr, keep order:false, stats:pseudo - │ └─IndexLookUp_33 250.00 root - │ ├─IndexScan_30 10.00 cop table:te, index:trade_id, range: decided by [tr.id], keep order:false, stats:pseudo - │ └─Selection_32 250.00 cop ge(te.expect_time, 2018-04-23 00:00:00.000000), le(te.expect_time, 2018-04-23 23:59:59.000000) - │ └─TableScan_31 10.00 cop table:te, keep order:false, stats:pseudo - └─IndexReader_99 10.00 root index:IndexScan_98 - └─IndexScan_98 10.00 cop table:p, index:relate_id, range: decided by [tr.id], keep order:false, stats:pseudo +Projection_13 0.00 root test.te.expected_time +└─Limit_19 0.00 root offset:0, count:5 + └─IndexJoin_101 0.00 root left outer join, inner:IndexReader_100, outer key:test.tr.id, inner key:test.p.relate_id + ├─TopN_104 0.00 root test.te.expect_time:asc, offset:0, count:5 + │ └─IndexJoin_35 0.00 root inner join, inner:IndexLookUp_34, outer key:test.tr.id, inner key:test.te.trade_id + │ ├─IndexLookUp_83 0.00 root + │ │ ├─Selection_81 0.00 cop eq(test.tr.business_type, 18), in(test.tr.trade_type, 1) + │ │ │ └─IndexScan_79 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_82 0.00 cop eq(test.tr.brand_identy, 32314), eq(test.tr.domain_type, 2) + │ │ └─TableScan_80 0.00 cop table:tr, keep order:false, stats:pseudo + │ └─IndexLookUp_34 250.00 root + │ ├─IndexScan_31 10.00 cop table:te, index:trade_id, range: decided by [test.tr.id], keep order:false, stats:pseudo + │ └─Selection_33 250.00 cop ge(test.te.expect_time, 2018-04-23 00:00:00.000000), le(test.te.expect_time, 2018-04-23 23:59:59.000000) + │ └─TableScan_32 10.00 cop table:te, keep order:false, stats:pseudo + └─IndexReader_100 10.00 root index:IndexScan_99 + └─IndexScan_99 10.00 cop table:p, index:relate_id, range: decided by [test.tr.id], keep order:false, stats:pseudo desc select 1 as a from dual order by a limit 1; id count task operator info Projection_6 1.00 root 1 @@ -203,7 +203,7 @@ Apply_14 10000.00 root semi join, inner:Limit_17, equal:[eq(test.t1.a, test.t2.a └─TableScan_20 1.25 cop table:t2, range:[-inf,+inf], keep order:false, stats:pseudo desc select * from t1 where t1.a in (select a from (select t2.a as a, t1.b as b from t2 where t2.b > t1.b) x order by b limit 1); id count task operator info -Apply_16 10000.00 root semi join, inner:Projection_19, equal:[eq(test.t1.a, x.a)] +Apply_16 10000.00 root semi join, inner:Projection_19, equal:[eq(test.t1.a, test.x.a)] ├─TableReader_18 10000.00 root data:TableScan_17 │ └─TableScan_17 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo └─Projection_19 1.00 root test.t2.a, test.t1.b @@ -217,24 +217,24 @@ 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 -└─IndexJoin_15 5.00 root inner join, inner:IndexReader_14, outer key:t1.a, inner key:t2.a +└─IndexJoin_15 5.00 root inner join, inner:IndexReader_14, outer key:test.t1.a, inner key:test.t2.a ├─TableReader_17 4.00 root data:TableScan_16 │ └─TableScan_16 4.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo └─IndexReader_14 10.00 root index:IndexScan_13 - └─IndexScan_13 10.00 cop table:t2, index:a, range: decided by [t1.a], keep order:false, stats:pseudo + └─IndexScan_13 10.00 cop table:t2, index:a, range: decided by [test.t1.a], 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(t2.a) - └─IndexJoin_17 5.00 root left outer join, inner:IndexReader_16, outer key:t1.a, inner key:t2.a +└─Selection_13 5.00 root isnull(test.t2.a) + └─IndexJoin_17 5.00 root left outer join, inner:IndexReader_16, outer key:test.t1.a, inner key:test.t2.a ├─TableReader_19 4.00 root data:TableScan_18 │ └─TableScan_18 4.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo └─IndexReader_16 10.00 root index:IndexScan_15 - └─IndexScan_15 10.00 cop table:t2, index:a, range: decided by [t1.a], keep order:false, stats:pseudo + └─IndexScan_15 10.00 cop table:t2, index:a, range: decided by [test.t1.a], 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 -└─MergeJoin_12 5.00 root inner join, left key:t1.a, right key:t2.a +└─MergeJoin_12 5.00 root inner join, left key:test.t1.a, right key:test.t2.a ├─IndexReader_14 4.00 root index:IndexScan_13 │ └─IndexScan_13 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:true, stats:pseudo └─IndexReader_16 4.00 root index:IndexScan_15 @@ -242,8 +242,8 @@ Limit_11 5.00 root offset:0, count:5 explain select /*+ TIDB_SMJ(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(t2.a) - └─MergeJoin_14 5.00 root left outer join, left key:t1.a, right key:t2.a +└─Selection_13 5.00 root isnull(test.t2.a) + └─MergeJoin_14 5.00 root left outer join, left key:test.t1.a, right key:test.t2.a ├─IndexReader_16 4.00 root index:IndexScan_15 │ └─IndexScan_15 4.00 cop table:t1, index:a, range:[NULL,+inf], keep order:true, stats:pseudo └─IndexReader_18 4.00 root index:IndexScan_17 @@ -251,7 +251,7 @@ 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_19 5.00 root inner join, inner:TableReader_24, equal:[eq(t1.a, t2.a)] +└─HashLeftJoin_19 5.00 root inner join, inner:TableReader_24, equal:[eq(test.t1.a, test.t2.a)] ├─TableReader_22 4.00 root data:TableScan_21 │ └─TableScan_21 4.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo └─TableReader_24 10000.00 root data:TableScan_23 @@ -259,8 +259,8 @@ Limit_11 5.00 root offset:0, count:5 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(t2.a) - └─HashLeftJoin_18 5.00 root left outer join, inner:TableReader_22, equal:[eq(t1.a, t2.a)] +└─Selection_13 5.00 root isnull(test.t2.a) + └─HashLeftJoin_18 5.00 root left outer join, inner:TableReader_22, equal:[eq(test.t1.a, test.t2.a)] ├─TableReader_20 4.00 root data:TableScan_19 │ └─TableScan_19 4.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo └─TableReader_22 10000.00 root data:TableScan_21 diff --git a/cmd/explaintest/r/tpch.result b/cmd/explaintest/r/tpch.result index 7b5dc9c6235f5..d934dbf9d1e6f 100644 --- a/cmd/explaintest/r/tpch.result +++ b/cmd/explaintest/r/tpch.result @@ -444,14 +444,14 @@ supp_nation, cust_nation, l_year; id count task operator info -Sort_22 768.91 root shipping.supp_nation:asc, shipping.cust_nation:asc, shipping.l_year:asc -└─Projection_24 768.91 root shipping.supp_nation, shipping.cust_nation, shipping.l_year, 14_col_0 - └─HashAgg_27 768.91 root group by:shipping.cust_nation, shipping.l_year, shipping.supp_nation, funcs:sum(shipping.volume), firstrow(shipping.supp_nation), firstrow(shipping.cust_nation), firstrow(shipping.l_year) - └─Projection_28 584459.32 root n1.n_name, n2.n_name, extract("YEAR", tpch.lineitem.l_shipdate), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)) - └─HashLeftJoin_33 584459.32 root inner join, inner:TableReader_85, equal:[eq(tpch.customer.c_nationkey, n2.n_nationkey)], other cond:or(and(eq(n1.n_name, "JAPAN"), eq(n2.n_name, "INDIA")), and(eq(n1.n_name, "INDIA"), eq(n2.n_name, "JAPAN"))) +Sort_22 768.91 root tpch.shipping.supp_nation:asc, tpch.shipping.cust_nation:asc, shipping.l_year:asc +└─Projection_24 768.91 root tpch.shipping.supp_nation, tpch.shipping.cust_nation, shipping.l_year, 14_col_0 + └─HashAgg_27 768.91 root group by:shipping.l_year, tpch.shipping.cust_nation, tpch.shipping.supp_nation, funcs:sum(shipping.volume), firstrow(tpch.shipping.supp_nation), firstrow(tpch.shipping.cust_nation), firstrow(shipping.l_year) + └─Projection_28 584459.32 root tpch.n1.n_name, tpch.n2.n_name, extract("YEAR", tpch.lineitem.l_shipdate), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)) + └─HashLeftJoin_33 584459.32 root inner join, inner:TableReader_85, equal:[eq(tpch.customer.c_nationkey, tpch.n2.n_nationkey)], other cond:or(and(eq(tpch.n1.n_name, "JAPAN"), eq(tpch.n2.n_name, "INDIA")), and(eq(tpch.n1.n_name, "INDIA"), eq(tpch.n2.n_name, "JAPAN"))) ├─IndexJoin_37 7305741.46 root inner join, inner:TableReader_36, outer key:tpch.orders.o_custkey, inner key:tpch.customer.c_custkey │ ├─IndexJoin_43 7305741.46 root inner join, inner:TableReader_42, outer key:tpch.lineitem.l_orderkey, inner key:tpch.orders.o_orderkey - │ │ ├─HashLeftJoin_64 7305741.46 root inner join, inner:TableReader_78, equal:[eq(tpch.supplier.s_nationkey, n1.n_nationkey)] + │ │ ├─HashLeftJoin_64 7305741.46 root inner join, inner:TableReader_78, equal:[eq(tpch.supplier.s_nationkey, tpch.n1.n_nationkey)] │ │ │ ├─HashLeftJoin_69 91321768.29 root inner join, inner:TableReader_75, equal:[eq(tpch.lineitem.l_suppkey, tpch.supplier.s_suppkey)] │ │ │ │ ├─TableReader_73 91321768.29 root data:Selection_72 │ │ │ │ │ └─Selection_72 91321768.29 cop ge(tpch.lineitem.l_shipdate, 1995-01-01 00:00:00.000000), le(tpch.lineitem.l_shipdate, 1996-12-31 00:00:00.000000) @@ -459,14 +459,14 @@ Sort_22 768.91 root shipping.supp_nation:asc, shipping.cust_nation:asc, shipping │ │ │ │ └─TableReader_75 500000.00 root data:TableScan_74 │ │ │ │ └─TableScan_74 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false │ │ │ └─TableReader_78 2.00 root data:Selection_77 - │ │ │ └─Selection_77 2.00 cop or(eq(n1.n_name, "JAPAN"), eq(n1.n_name, "INDIA")) + │ │ │ └─Selection_77 2.00 cop or(eq(tpch.n1.n_name, "JAPAN"), eq(tpch.n1.n_name, "INDIA")) │ │ │ └─TableScan_76 25.00 cop table:n1, range:[-inf,+inf], keep order:false │ │ └─TableReader_42 1.00 root data:TableScan_41 │ │ └─TableScan_41 1.00 cop table:orders, range: decided by [tpch.lineitem.l_orderkey], keep order:false │ └─TableReader_36 1.00 root data:TableScan_35 │ └─TableScan_35 1.00 cop table:customer, range: decided by [tpch.orders.o_custkey], keep order:false └─TableReader_85 2.00 root data:Selection_84 - └─Selection_84 2.00 cop or(eq(n2.n_name, "INDIA"), eq(n2.n_name, "JAPAN")) + └─Selection_84 2.00 cop or(eq(tpch.n2.n_name, "INDIA"), eq(tpch.n2.n_name, "JAPAN")) └─TableScan_83 25.00 cop table:n2, range:[-inf,+inf], keep order:false /* Q8 National Market Share Query @@ -519,12 +519,12 @@ id count task operator info Sort_28 718.01 root all_nations.o_year:asc └─Projection_30 718.01 root all_nations.o_year, div(18_col_0, 18_col_1) └─HashAgg_33 718.01 root group by:col_3, funcs:sum(col_0), sum(col_1), firstrow(col_2) - └─Projection_105 112469.62 root case(eq(all_nations.nation, "INDIA"), all_nations.volume, 0), all_nations.volume, all_nations.o_year, all_nations.o_year - └─Projection_34 112469.62 root extract("YEAR", tpch.orders.o_orderdate), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), n2.n_name - └─HashLeftJoin_39 112469.62 root inner join, inner:TableReader_103, equal:[eq(n1.n_regionkey, tpch.region.r_regionkey)] - ├─HashLeftJoin_44 562348.12 root inner join, inner:TableReader_100, equal:[eq(tpch.customer.c_nationkey, n1.n_nationkey)] + └─Projection_105 112469.62 root case(eq(tpch.all_nations.nation, "INDIA"), all_nations.volume, 0), all_nations.volume, all_nations.o_year, all_nations.o_year + └─Projection_34 112469.62 root extract("YEAR", tpch.orders.o_orderdate), mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), tpch.n2.n_name + └─HashLeftJoin_39 112469.62 root inner join, inner:TableReader_103, equal:[eq(tpch.n1.n_regionkey, tpch.region.r_regionkey)] + ├─HashLeftJoin_44 562348.12 root inner join, inner:TableReader_100, equal:[eq(tpch.customer.c_nationkey, tpch.n1.n_nationkey)] │ ├─IndexJoin_48 562348.12 root inner join, inner:TableReader_47, outer key:tpch.orders.o_custkey, inner key:tpch.customer.c_custkey - │ │ ├─HashLeftJoin_54 562348.12 root inner join, inner:TableReader_96, equal:[eq(tpch.supplier.s_nationkey, n2.n_nationkey)] + │ │ ├─HashLeftJoin_54 562348.12 root inner join, inner:TableReader_96, equal:[eq(tpch.supplier.s_nationkey, tpch.n2.n_nationkey)] │ │ │ ├─IndexJoin_58 562348.12 root inner join, inner:TableReader_57, outer key:tpch.lineitem.l_suppkey, inner key:tpch.supplier.s_suppkey │ │ │ │ ├─HashLeftJoin_65 562348.12 root inner join, inner:TableReader_92, equal:[eq(tpch.lineitem.l_partkey, tpch.part.p_partkey)] │ │ │ │ │ ├─IndexJoin_71 90661378.61 root inner join, inner:IndexLookUp_70, outer key:tpch.orders.o_orderkey, inner key:tpch.lineitem.l_orderkey @@ -592,9 +592,9 @@ order by nation, o_year desc; id count task operator info -Sort_22 2406.00 root profit.nation:asc, profit.o_year:desc -└─Projection_23 2406.00 root profit.nation, profit.o_year, 14_col_0 - └─HashAgg_26 2406.00 root group by:profit.nation, profit.o_year, funcs:sum(profit.amount), firstrow(profit.nation), firstrow(profit.o_year) +Sort_22 2406.00 root tpch.profit.nation:asc, profit.o_year:desc +└─Projection_23 2406.00 root tpch.profit.nation, profit.o_year, 14_col_0 + └─HashAgg_26 2406.00 root group by:profit.o_year, tpch.profit.nation, funcs:sum(profit.amount), firstrow(tpch.profit.nation), firstrow(profit.o_year) └─Projection_27 971049283.51 root tpch.nation.n_name, extract("YEAR", tpch.orders.o_orderdate), minus(mul(tpch.lineitem.l_extendedprice, minus(1, tpch.lineitem.l_discount)), mul(tpch.partsupp.ps_supplycost, tpch.lineitem.l_quantity)) └─MergeJoin_28 971049283.51 root inner join, left key:tpch.lineitem.l_orderkey, right key:tpch.orders.o_orderkey ├─IndexJoin_37 971049283.51 root inner join, inner:IndexLookUp_36, outer key:tpch.lineitem.l_suppkey, tpch.lineitem.l_partkey, inner key:tpch.partsupp.ps_suppkey, tpch.partsupp.ps_partkey @@ -1224,17 +1224,17 @@ Projection_25 100.00 root tpch.supplier.s_name, 17_col_0 └─TopN_28 100.00 root 17_col_0:desc, tpch.supplier.s_name:asc, offset:0, count:100 └─HashAgg_31 320000.00 root group by:tpch.supplier.s_name, funcs:count(1), firstrow(tpch.supplier.s_name) └─Selection_32 3786715.90 root not(16_aux_0) - └─IndexJoin_38 4733394.87 root left outer semi join, inner:IndexLookUp_37, outer key:l1.l_orderkey, inner key:l3.l_orderkey, other cond:ne(l3.l_suppkey, l1.l_suppkey) - ├─IndexJoin_82 4733394.87 root semi join, inner:IndexLookUp_81, outer key:l1.l_orderkey, inner key:l2.l_orderkey, other cond:ne(l2.l_suppkey, l1.l_suppkey), ne(l2.l_suppkey, tpch.supplier.s_suppkey) + └─IndexJoin_38 4733394.87 root left outer semi join, inner:IndexLookUp_37, outer key:tpch.l1.l_orderkey, inner key:tpch.l3.l_orderkey, other cond:ne(tpch.l3.l_suppkey, tpch.l1.l_suppkey) + ├─IndexJoin_82 4733394.87 root semi join, inner:IndexLookUp_81, outer key:tpch.l1.l_orderkey, inner key:tpch.l2.l_orderkey, other cond:ne(tpch.l2.l_suppkey, tpch.l1.l_suppkey), ne(tpch.l2.l_suppkey, tpch.supplier.s_suppkey) │ ├─HashLeftJoin_88 5916743.59 root inner join, inner:TableReader_117, equal:[eq(tpch.supplier.s_nationkey, tpch.nation.n_nationkey)] - │ │ ├─HashLeftJoin_93 147918589.81 root inner join, inner:TableReader_114, equal:[eq(l1.l_suppkey, tpch.supplier.s_suppkey)] - │ │ │ ├─IndexJoin_100 147918589.81 root inner join, inner:IndexLookUp_99, outer key:tpch.orders.o_orderkey, inner key:l1.l_orderkey + │ │ ├─HashLeftJoin_93 147918589.81 root inner join, inner:TableReader_114, equal:[eq(tpch.l1.l_suppkey, tpch.supplier.s_suppkey)] + │ │ │ ├─IndexJoin_100 147918589.81 root inner join, inner:IndexLookUp_99, outer key:tpch.orders.o_orderkey, inner key:tpch.l1.l_orderkey │ │ │ │ ├─TableReader_109 36517371.00 root data:Selection_108 │ │ │ │ │ └─Selection_108 36517371.00 cop eq(tpch.orders.o_orderstatus, "F") │ │ │ │ │ └─TableScan_107 75000000.00 cop table:orders, range:[-inf,+inf], keep order:false │ │ │ │ └─IndexLookUp_99 240004648.80 root │ │ │ │ ├─IndexScan_96 1.00 cop table:l1, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.orders.o_orderkey], keep order:false - │ │ │ │ └─Selection_98 240004648.80 cop gt(l1.l_receiptdate, l1.l_commitdate) + │ │ │ │ └─Selection_98 240004648.80 cop gt(tpch.l1.l_receiptdate, tpch.l1.l_commitdate) │ │ │ │ └─TableScan_97 1.00 cop table:lineitem, keep order:false │ │ │ └─TableReader_114 500000.00 root data:TableScan_113 │ │ │ └─TableScan_113 500000.00 cop table:supplier, range:[-inf,+inf], keep order:false @@ -1242,11 +1242,11 @@ Projection_25 100.00 root tpch.supplier.s_name, 17_col_0 │ │ └─Selection_116 1.00 cop eq(tpch.nation.n_name, "EGYPT") │ │ └─TableScan_115 25.00 cop table:nation, range:[-inf,+inf], keep order:false │ └─IndexLookUp_81 1.00 root - │ ├─IndexScan_79 1.00 cop table:l2, index:L_ORDERKEY, L_LINENUMBER, range: decided by [l1.l_orderkey], keep order:false + │ ├─IndexScan_79 1.00 cop table:l2, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.l1.l_orderkey], keep order:false │ └─TableScan_80 1.00 cop table:lineitem, keep order:false └─IndexLookUp_37 240004648.80 root - ├─IndexScan_34 1.00 cop table:l3, index:L_ORDERKEY, L_LINENUMBER, range: decided by [l1.l_orderkey], keep order:false - └─Selection_36 240004648.80 cop gt(l3.l_receiptdate, l3.l_commitdate) + ├─IndexScan_34 1.00 cop table:l3, index:L_ORDERKEY, L_LINENUMBER, range: decided by [tpch.l1.l_orderkey], keep order:false + └─Selection_36 240004648.80 cop gt(tpch.l3.l_receiptdate, tpch.l3.l_commitdate) └─TableScan_35 1.00 cop table:lineitem, keep order:false /* Q22 Global Sales Opportunity Query @@ -1297,7 +1297,7 @@ cntrycode; id count task operator info Sort_32 1.00 root custsale.cntrycode:asc └─Projection_34 1.00 root custsale.cntrycode, 28_col_0, 28_col_1 - └─HashAgg_37 1.00 root group by:custsale.cntrycode, funcs:count(1), sum(custsale.c_acctbal), firstrow(custsale.cntrycode) + └─HashAgg_37 1.00 root group by:custsale.cntrycode, funcs:count(1), sum(tpch.custsale.c_acctbal), firstrow(custsale.cntrycode) └─Projection_38 0.00 root substring(tpch.customer.c_phone, 1, 2), tpch.customer.c_acctbal └─Selection_39 0.00 root not(26_aux_0) └─HashLeftJoin_40 0.00 root left outer semi join, inner:TableReader_46, equal:[eq(tpch.customer.c_custkey, tpch.orders.o_custkey)] diff --git a/executor/merge_join_test.go b/executor/merge_join_test.go index ccf21c60ffd78..de9f89fda1e9b 100644 --- a/executor/merge_join_test.go +++ b/executor/merge_join_test.go @@ -336,7 +336,7 @@ func (s *testSuite) TestMergeJoin(c *C) { tk.MustExec("create table t(a int)") tk.MustExec("insert into t value(1),(2)") tk.MustQuery("explain select /*+ TIDB_SMJ(t1, t2) */ * from t t1 join t t2 order by t1.a, t2.a").Check(testkit.Rows( - "Sort_6 100000000.00 root t1.a:asc, t2.a:asc", + "Sort_6 100000000.00 root test.t1.a:asc, test.t2.a:asc", "└─MergeJoin_9 100000000.00 root inner join", " ├─TableReader_11 10000.00 root data:TableScan_10", " │ └─TableScan_10 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo", diff --git a/planner/core/cbo_test.go b/planner/core/cbo_test.go index 86d44dba9fa0a..5e66f17bf74f4 100644 --- a/planner/core/cbo_test.go +++ b/planner/core/cbo_test.go @@ -661,12 +661,12 @@ func (s *testAnalyzeSuite) TestCorrelatedEstimation(c *C) { " ├─TableReader_15 10.00 root data:TableScan_14", " │ └─TableScan_14 10.00 cop table:t, range:[-inf,+inf], keep order:false", " └─StreamAgg_20 1.00 root funcs:count(1)", - " └─HashLeftJoin_21 1.00 root inner join, inner:TableReader_28, equal:[eq(s.a, t1.a)]", + " └─HashLeftJoin_21 1.00 root inner join, inner:TableReader_28, equal:[eq(test.s.a, test.t1.a)]", " ├─TableReader_25 1.00 root data:Selection_24", - " │ └─Selection_24 1.00 cop eq(s.a, test.t.a)", + " │ └─Selection_24 1.00 cop eq(test.s.a, test.t.a)", " │ └─TableScan_23 10.00 cop table:s, range:[-inf,+inf], keep order:false", " └─TableReader_28 1.00 root data:Selection_27", - " └─Selection_27 1.00 cop eq(t1.a, test.t.a)", + " └─Selection_27 1.00 cop eq(test.t1.a, test.t.a)", " └─TableScan_26 10.00 cop table:t1, range:[-inf,+inf], keep order:false", )) tk.MustQuery("explain select (select concat(t1.a, \",\", t1.b) from t t1 where t1.a=t.a and t1.c=t.c) from t"). @@ -676,10 +676,10 @@ func (s *testAnalyzeSuite) TestCorrelatedEstimation(c *C) { " ├─TableReader_12 10.00 root data:TableScan_11", " │ └─TableScan_11 10.00 cop table:t, range:[-inf,+inf], keep order:false", " └─MaxOneRow_13 1.00 root ", - " └─Projection_14 0.10 root concat(cast(t1.a), \",\", cast(t1.b))", + " └─Projection_14 0.10 root concat(cast(test.t1.a), \",\", cast(test.t1.b))", " └─IndexLookUp_21 0.10 root ", - " ├─IndexScan_18 1.00 cop table:t1, index:c, range: decided by [eq(t1.c, test.t.c)], keep order:false", - " └─Selection_20 0.10 cop eq(t1.a, test.t.a)", + " ├─IndexScan_18 1.00 cop table:t1, index:c, range: decided by [eq(test.t1.c, test.t.c)], keep order:false", + " └─Selection_20 0.10 cop eq(test.t1.a, test.t.a)", " └─TableScan_19 1.00 cop table:t, keep order:false", )) } diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 9a6cb8dc520d1..02f0f4bded97e 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -153,7 +153,6 @@ func (b *planBuilder) buildResultSetNode(node ast.ResultSetNode) (p LogicalPlan, col.OrigTblName = col.TblName if x.AsName.L != "" { col.TblName = x.AsName - col.DBName = model.NewCIStr("") } } // Duplicate column name in one table is not allowed. diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index a548235777cdd..9ec7e2a437d5b 100644 --- a/planner/core/logical_plan_test.go +++ b/planner/core/logical_plan_test.go @@ -293,7 +293,7 @@ func (s *testPlanSuite) TestPredicatePushDown(c *C) { }{ { sql: "select count(*) from t a, t b where a.a = b.a", - best: "Join{DataScan(a)->DataScan(b)}(a.a,b.a)->Aggr(count(1))->Projection", + best: "Join{DataScan(a)->DataScan(b)}(test.a.a,test.b.a)->Aggr(count(1))->Projection", }, { sql: "select a from (select a from t where d = 0) k where k.a = 5", @@ -313,31 +313,31 @@ func (s *testPlanSuite) TestPredicatePushDown(c *C) { }, { sql: "select * from t ta, t tb where (ta.d, ta.a) = (tb.b, tb.c)", - best: "Join{DataScan(ta)->DataScan(tb)}(ta.d,tb.b)(ta.a,tb.c)->Projection", + best: "Join{DataScan(ta)->DataScan(tb)}(test.ta.d,test.tb.b)(test.ta.a,test.tb.c)->Projection", }, { sql: "select * from t t1, t t2 where t1.a = t2.b and t2.b > 0 and t1.a = t1.c and t1.d like 'abc' and t2.d = t1.d", - best: "Join{DataScan(t2)->Sel([like(cast(t2.d), abc, 92)])->DataScan(t1)->Sel([like(cast(t1.d), abc, 92)])}(t2.b,t1.a)(t2.d,t1.d)->Projection", + best: "Join{DataScan(t2)->Sel([like(cast(test.t2.d), abc, 92)])->DataScan(t1)->Sel([like(cast(test.t1.d), abc, 92)])}(test.t2.b,test.t1.a)(test.t2.d,test.t1.d)->Projection", }, { sql: "select * from t ta join t tb on ta.d = tb.d and ta.d > 1 where tb.a = 0", - best: "Join{DataScan(ta)->DataScan(tb)}(ta.d,tb.d)->Projection", + best: "Join{DataScan(ta)->DataScan(tb)}(test.ta.d,test.tb.d)->Projection", }, { sql: "select * from t ta join t tb on ta.d = tb.d where ta.d > 1 and tb.a = 0", - best: "Join{DataScan(ta)->DataScan(tb)}(ta.d,tb.d)->Projection", + best: "Join{DataScan(ta)->DataScan(tb)}(test.ta.d,test.tb.d)->Projection", }, { sql: "select * from t ta left outer join t tb on ta.d = tb.d and ta.d > 1 where tb.a = 0", - best: "Join{DataScan(ta)->DataScan(tb)}(ta.d,tb.d)->Projection", + best: "Join{DataScan(ta)->DataScan(tb)}(test.ta.d,test.tb.d)->Projection", }, { sql: "select * from t ta right outer join t tb on ta.d = tb.d and ta.a > 1 where tb.a = 0", - best: "Join{DataScan(ta)->DataScan(tb)}(ta.d,tb.d)->Projection", + best: "Join{DataScan(ta)->DataScan(tb)}(test.ta.d,test.tb.d)->Projection", }, { sql: "select * from t ta left outer join t tb on ta.d = tb.d and ta.a > 1 where ta.d = 0", - best: "Join{DataScan(ta)->DataScan(tb)}(ta.d,tb.d)->Projection", + best: "Join{DataScan(ta)->DataScan(tb)}(test.ta.d,test.tb.d)->Projection", }, { sql: "select * from t ta left outer join t tb on ta.d = tb.d and ta.a > 1 where tb.d = 0", @@ -345,31 +345,31 @@ func (s *testPlanSuite) TestPredicatePushDown(c *C) { }, { sql: "select * from t ta left outer join t tb on ta.d = tb.d and ta.a > 1 where tb.c is not null and tb.c = 0 and ifnull(tb.d, 1)", - best: "Join{DataScan(ta)->DataScan(tb)}(ta.d,tb.d)->Projection", + best: "Join{DataScan(ta)->DataScan(tb)}(test.ta.d,test.tb.d)->Projection", }, { sql: "select * from t ta left outer join t tb on ta.a = tb.a left outer join t tc on tb.b = tc.b where tc.c > 0", - best: "Join{Join{DataScan(ta)->DataScan(tb)}(ta.a,tb.a)->DataScan(tc)}(tb.b,tc.b)->Projection", + best: "Join{Join{DataScan(ta)->DataScan(tb)}(test.ta.a,test.tb.a)->DataScan(tc)}(test.tb.b,test.tc.b)->Projection", }, { sql: "select * from t ta left outer join t tb on ta.a = tb.a left outer join t tc on tc.b = ta.b where tb.c > 0", - best: "Join{Join{DataScan(ta)->DataScan(tb)}(ta.a,tb.a)->DataScan(tc)}(ta.b,tc.b)->Projection", + best: "Join{Join{DataScan(ta)->DataScan(tb)}(test.ta.a,test.tb.a)->DataScan(tc)}(test.ta.b,test.tc.b)->Projection", }, { sql: "select * from t as ta left outer join (t as tb left join t as tc on tc.b = tb.b) on tb.a = ta.a where tc.c > 0", - best: "Join{DataScan(ta)->Join{DataScan(tb)->DataScan(tc)}(tb.b,tc.b)}(ta.a,tb.a)->Projection", + best: "Join{DataScan(ta)->Join{DataScan(tb)->DataScan(tc)}(test.tb.b,test.tc.b)}(test.ta.a,test.tb.a)->Projection", }, { sql: "select * from ( t as ta left outer join t as tb on ta.a = tb.a) join ( t as tc left join t as td on tc.b = td.b) on ta.c = td.c where tb.c = 2 and td.a = 1", - best: "Join{Join{DataScan(ta)->DataScan(tb)}(ta.a,tb.a)->Join{DataScan(tc)->DataScan(td)}(tc.b,td.b)}(ta.c,td.c)->Projection", + best: "Join{Join{DataScan(ta)->DataScan(tb)}(test.ta.a,test.tb.a)->Join{DataScan(tc)->DataScan(td)}(test.tc.b,test.td.b)}(test.ta.c,test.td.c)->Projection", }, { sql: "select * from t ta left outer join (t tb left outer join t tc on tc.b = tb.b) on tb.a = ta.a and tc.c = ta.c where tc.d > 0 or ta.d > 0", - best: "Join{DataScan(ta)->Join{DataScan(tb)->DataScan(tc)}(tb.b,tc.b)}(ta.a,tb.a)(ta.c,tc.c)->Sel([or(gt(tc.d, 0), gt(ta.d, 0))])->Projection", + best: "Join{DataScan(ta)->Join{DataScan(tb)->DataScan(tc)}(test.tb.b,test.tc.b)}(test.ta.a,test.tb.a)(test.ta.c,test.tc.c)->Sel([or(gt(test.tc.d, 0), gt(test.ta.d, 0))])->Projection", }, { sql: "select * from t ta left outer join t tb on ta.d = tb.d and ta.a > 1 where ifnull(tb.d, null) or tb.d is null", - best: "Join{DataScan(ta)->DataScan(tb)}(ta.d,tb.d)->Sel([or(ifnull(tb.d, ), isnull(tb.d))])->Projection", + best: "Join{DataScan(ta)->DataScan(tb)}(test.ta.d,test.tb.d)->Sel([or(ifnull(test.tb.d, ), isnull(test.tb.d))])->Projection", }, { sql: "select a, d from (select * from t union all select * from t union all select * from t) z where a < 10", @@ -378,22 +378,21 @@ func (s *testPlanSuite) TestPredicatePushDown(c *C) { { sql: "select (select count(*) from t where t.a = k.a) from t k", best: "Apply{DataScan(k)->DataScan(t)->Aggr(count(1))->Projection->MaxOneRow}->Projection", - }, - { + }, { sql: "select a from t where exists(select 1 from t as x where x.a < t.a)", best: "Join{DataScan(t)->DataScan(x)}->Projection", }, { sql: "select a from t where exists(select 1 from t as x where x.a = t.a and t.a < 1 and x.a < 1)", - best: "Join{DataScan(t)->DataScan(x)}(test.t.a,x.a)->Projection", + best: "Join{DataScan(t)->DataScan(x)}(test.t.a,test.x.a)->Projection", }, { sql: "select a from t where exists(select 1 from t as x where x.a = t.a and x.a < 1) and a < 1", - best: "Join{DataScan(t)->DataScan(x)}(test.t.a,x.a)->Projection", + best: "Join{DataScan(t)->DataScan(x)}(test.t.a,test.x.a)->Projection", }, { sql: "select a from t where exists(select 1 from t as x where x.a = t.a) and exists(select 1 from t as x where x.a = t.a)", - best: "Join{Join{DataScan(t)->DataScan(x)}(test.t.a,x.a)->DataScan(x)}(test.t.a,x.a)->Projection", + best: "Join{Join{DataScan(t)->DataScan(x)}(test.t.a,test.x.a)->DataScan(x)}(test.t.a,test.x.a)->Projection", }, { sql: "select * from (select a, b, sum(c) as s from t group by a, b) k where k.a > k.b * 2 + 1", @@ -405,7 +404,7 @@ func (s *testPlanSuite) TestPredicatePushDown(c *C) { }, { sql: "select * from (select k.a, sum(k.s) as ss from (select a, sum(b) as s from t group by a) k group by k.a) l where l.a > 2", - best: "DataScan(t)->Aggr(sum(test.t.b),firstrow(test.t.a))->Projection->Aggr(sum(k.s),firstrow(k.a))->Projection->Projection", + best: "DataScan(t)->Aggr(sum(test.t.b),firstrow(test.t.a))->Projection->Aggr(sum(k.s),firstrow(test.k.a))->Projection->Projection", }, { sql: "select * from (select a, sum(b) as s from t group by a) k where a > s", @@ -417,7 +416,7 @@ func (s *testPlanSuite) TestPredicatePushDown(c *C) { }, { sql: "select * from (select a, sum(b) as s from t group by a having 1 = 0) k where a > 1", - best: "Dual->Sel([gt(k.a, 1)])->Projection", + best: "Dual->Sel([gt(test.k.a, 1)])->Projection", }, { sql: "select a, count(a) cnt from t group by a having cnt < 1", @@ -426,7 +425,7 @@ func (s *testPlanSuite) TestPredicatePushDown(c *C) { // issue #3873 { sql: "select t1.a, t2.a from t as t1 left join t as t2 on t1.a = t2.a where t1.a < 1.0", - best: "Join{DataScan(t1)->DataScan(t2)}(t1.a,t2.a)->Projection", + best: "Join{DataScan(t1)->DataScan(t2)}(test.t1.a,test.t2.a)->Projection", }, // issue #7728 { @@ -434,7 +433,7 @@ func (s *testPlanSuite) TestPredicatePushDown(c *C) { best: "Dual->Projection", }, } - for _, ca := range tests { + for ith, ca := range tests { comment := Commentf("for %s", ca.sql) stmt, err := s.ParseOneStmt(ca.sql, "", "") c.Assert(err, IsNil, comment) @@ -442,7 +441,7 @@ func (s *testPlanSuite) TestPredicatePushDown(c *C) { c.Assert(err, IsNil) p, err = logicalOptimize(flagPredicatePushDown|flagDecorrelate|flagPrunColumns, p.(LogicalPlan)) c.Assert(err, IsNil) - c.Assert(ToString(p), Equals, ca.best, Commentf("for %s", ca.sql)) + c.Assert(ToString(p), Equals, ca.best, Commentf("for %s %d", ca.sql, ith)) } } @@ -466,34 +465,34 @@ func (s *testPlanSuite) TestJoinPredicatePushDown(c *C) { }, { sql: "select * from t as t1 join t as t2 on t1.b = t2.b where (t1.a=1 and t2.a=1) or (t1.a=2 and t2.a=2)", - left: "[or(eq(t1.a, 1), eq(t1.a, 2))]", - right: "[or(eq(t2.a, 1), eq(t2.a, 2))]", + left: "[or(eq(test.t1.a, 1), eq(test.t1.a, 2))]", + right: "[or(eq(test.t2.a, 1), eq(test.t2.a, 2))]", }, { sql: "select * from t as t1 join t as t2 on t1.b = t2.b where (t1.c=1 and (t1.a=3 or t2.a=3)) or (t1.a=2 and t2.a=2)", - left: "[or(eq(t1.c, 1), eq(t1.a, 2))]", + left: "[or(eq(test.t1.c, 1), eq(test.t1.a, 2))]", right: "[]", }, { sql: "select * from t as t1 join t as t2 on t1.b = t2.b where (t1.c=1 and ((t1.a=3 and t2.a=3) or (t1.a=4 and t2.a=4)))", - left: "[eq(t1.c, 1) or(eq(t1.a, 3), eq(t1.a, 4))]", - right: "[or(eq(t2.a, 3), eq(t2.a, 4))]", + left: "[eq(test.t1.c, 1) or(eq(test.t1.a, 3), eq(test.t1.a, 4))]", + right: "[or(eq(test.t2.a, 3), eq(test.t2.a, 4))]", }, { sql: "select * from t as t1 join t as t2 on t1.b = t2.b where (t1.a>1 and t1.a < 3 and t2.a=1) or (t1.a=2 and t2.a=2)", - left: "[or(and(gt(t1.a, 1), lt(t1.a, 3)), eq(t1.a, 2))]", - right: "[or(eq(t2.a, 1), eq(t2.a, 2))]", + left: "[or(and(gt(test.t1.a, 1), lt(test.t1.a, 3)), eq(test.t1.a, 2))]", + right: "[or(eq(test.t2.a, 1), eq(test.t2.a, 2))]", }, { sql: "select * from t as t1 join t as t2 on t1.b = t2.b and ((t1.a=1 and t2.a=1) or (t1.a=2 and t2.a=2))", - left: "[or(eq(t1.a, 1), eq(t1.a, 2))]", - right: "[or(eq(t2.a, 1), eq(t2.a, 2))]", + left: "[or(eq(test.t1.a, 1), eq(test.t1.a, 2))]", + right: "[or(eq(test.t2.a, 1), eq(test.t2.a, 2))]", }, // issue #7628, left join { sql: "select * from t as t1 left join t as t2 on t1.b = t2.b and ((t1.a=1 and t2.a=1) or (t1.a=2 and t2.a=2))", left: "[]", - right: "[or(eq(t2.a, 1), eq(t2.a, 2))]", + right: "[or(eq(test.t2.a, 1), eq(test.t2.a, 2))]", }, { sql: "select * from t as t1 left join t as t2 on t1.b = t2.b and t1.a > t2.a", @@ -513,12 +512,12 @@ func (s *testPlanSuite) TestJoinPredicatePushDown(c *C) { { sql: "select * from t as t1 left join t as t2 on t1.b = t2.b and ((t2.c=1 and (t1.a=3 or t2.a=3)) or (t1.a=2 and t2.a=2))", left: "[]", - right: "[or(eq(t2.c, 1), eq(t2.a, 2))]", + right: "[or(eq(test.t2.c, 1), eq(test.t2.a, 2))]", }, { sql: "select * from t as t1 left join t as t2 on t1.b = t2.b and ((t1.c=1 and ((t1.a=3 and t2.a=3) or (t1.a=4 and t2.a=4))) or (t1.a=2 and t2.a=2))", left: "[]", - right: "[or(or(eq(t2.a, 3), eq(t2.a, 4)), eq(t2.a, 2))]", + right: "[or(or(eq(test.t2.a, 3), eq(test.t2.a, 4)), eq(test.t2.a, 2))]", }, } for _, ca := range tests { @@ -555,20 +554,20 @@ func (s *testPlanSuite) TestOuterWherePredicatePushDown(c *C) { // issue #7628, left join with where condition { sql: "select * from t as t1 left join t as t2 on t1.b = t2.b where (t1.a=1 and t2.a is null) or (t1.a=2 and t2.a=2)", - sel: "[or(and(eq(t1.a, 1), isnull(t2.a)), and(eq(t1.a, 2), eq(t2.a, 2)))]", - left: "[or(eq(t1.a, 1), eq(t1.a, 2))]", + sel: "[or(and(eq(test.t1.a, 1), isnull(test.t2.a)), and(eq(test.t1.a, 2), eq(test.t2.a, 2)))]", + left: "[or(eq(test.t1.a, 1), eq(test.t1.a, 2))]", right: "[]", }, { sql: "select * from t as t1 left join t as t2 on t1.b = t2.b where (t1.c=1 and (t1.a=3 or t2.a=3)) or (t1.a=2 and t2.a=2)", - sel: "[or(and(eq(t1.c, 1), or(eq(t1.a, 3), eq(t2.a, 3))), and(eq(t1.a, 2), eq(t2.a, 2)))]", - left: "[or(eq(t1.c, 1), eq(t1.a, 2))]", + sel: "[or(and(eq(test.t1.c, 1), or(eq(test.t1.a, 3), eq(test.t2.a, 3))), and(eq(test.t1.a, 2), eq(test.t2.a, 2)))]", + left: "[or(eq(test.t1.c, 1), eq(test.t1.a, 2))]", right: "[]", }, { sql: "select * from t as t1 left join t as t2 on t1.b = t2.b where (t1.c=1 and ((t1.a=3 and t2.a=3) or (t1.a=4 and t2.a=4))) or (t1.a=2 and t2.a is null)", - sel: "[or(and(eq(t1.c, 1), or(and(eq(t1.a, 3), eq(t2.a, 3)), and(eq(t1.a, 4), eq(t2.a, 4)))), and(eq(t1.a, 2), isnull(t2.a)))]", - left: "[or(and(eq(t1.c, 1), or(eq(t1.a, 3), eq(t1.a, 4))), eq(t1.a, 2))]", + sel: "[or(and(eq(test.t1.c, 1), or(and(eq(test.t1.a, 3), eq(test.t2.a, 3)), and(eq(test.t1.a, 4), eq(test.t2.a, 4)))), and(eq(test.t1.a, 2), isnull(test.t2.a)))]", + left: "[or(and(eq(test.t1.c, 1), or(eq(test.t1.a, 3), eq(test.t1.a, 4))), eq(test.t1.a, 2))]", right: "[]", }, } @@ -608,32 +607,32 @@ func (s *testPlanSuite) TestSimplifyOuterJoin(c *C) { }{ { sql: "select * from t t1 left join t t2 on t1.b = t2.b where t1.c > 1 or t2.c > 1;", - best: "Join{DataScan(t1)->DataScan(t2)}(t1.b,t2.b)->Sel([or(gt(t1.c, 1), gt(t2.c, 1))])->Projection", + best: "Join{DataScan(t1)->DataScan(t2)}(test.t1.b,test.t2.b)->Sel([or(gt(test.t1.c, 1), gt(test.t2.c, 1))])->Projection", joinType: "left outer join", }, { sql: "select * from t t1 left join t t2 on t1.b = t2.b where t1.c > 1 and t2.c > 1;", - best: "Join{DataScan(t1)->DataScan(t2)}(t1.b,t2.b)->Projection", + best: "Join{DataScan(t1)->DataScan(t2)}(test.t1.b,test.t2.b)->Projection", joinType: "inner join", }, { sql: "select * from t t1 left join t t2 on t1.b = t2.b where not (t1.c > 1 or t2.c > 1);", - best: "Join{DataScan(t1)->DataScan(t2)}(t1.b,t2.b)->Projection", + best: "Join{DataScan(t1)->DataScan(t2)}(test.t1.b,test.t2.b)->Projection", joinType: "inner join", }, { sql: "select * from t t1 left join t t2 on t1.b = t2.b where not (t1.c > 1 and t2.c > 1);", - best: "Join{DataScan(t1)->DataScan(t2)}(t1.b,t2.b)->Sel([not(and(le(t1.c, 1), le(t2.c, 1)))])->Projection", + best: "Join{DataScan(t1)->DataScan(t2)}(test.t1.b,test.t2.b)->Sel([not(and(le(test.t1.c, 1), le(test.t2.c, 1)))])->Projection", joinType: "left outer join", }, { sql: "select * from t t1 left join t t2 on t1.b > 1 where t1.c = t2.c;", - best: "Join{DataScan(t1)->DataScan(t2)}(t1.c,t2.c)->Projection", + best: "Join{DataScan(t1)->DataScan(t2)}(test.t1.c,test.t2.c)->Projection", joinType: "inner join", }, { sql: "select * from t t1 left join t t2 on true where t1.b <=> t2.b;", - best: "Join{DataScan(t1)->DataScan(t2)}->Sel([nulleq(t1.b, t2.b)])->Projection", + best: "Join{DataScan(t1)->DataScan(t2)}->Sel([nulleq(test.t1.b, test.t2.b)])->Projection", joinType: "left outer join", }, } @@ -788,72 +787,72 @@ func (s *testPlanSuite) TestSubquery(c *C) { { // This will be resolved as in sub query. sql: "select * from t where 10 in (select b from t s where s.a = t.a)", - best: "Join{DataScan(t)->DataScan(s)}(test.t.a,s.a)->Projection", + best: "Join{DataScan(t)->DataScan(s)}(test.t.a,test.s.a)->Projection", }, { sql: "select count(c) ,(select b from t s where s.a = t.a) from t", - best: "Join{DataScan(t)->Aggr(count(test.t.c),firstrow(test.t.a))->DataScan(s)}(test.t.a,s.a)->Projection->Projection", + best: "Join{DataScan(t)->Aggr(count(test.t.c),firstrow(test.t.a))->DataScan(s)}(test.t.a,test.s.a)->Projection->Projection", }, { sql: "select count(c) ,(select count(s.b) from t s where s.a = t.a) from t", - best: "Join{DataScan(t)->Aggr(count(test.t.c),firstrow(test.t.a))->DataScan(s)}(test.t.a,s.a)->Aggr(firstrow(2_col_0),firstrow(test.t.a),count(s.b))->Projection->Projection", + best: "Join{DataScan(t)->Aggr(count(test.t.c),firstrow(test.t.a))->DataScan(s)}(test.t.a,test.s.a)->Aggr(firstrow(2_col_0),firstrow(test.t.a),count(test.s.b))->Projection->Projection", }, { // Semi-join with agg cannot decorrelate. sql: "select t.c in (select count(s.b) from t s where s.a = t.a) from t", - best: "Apply{DataScan(t)->DataScan(s)->Sel([eq(s.a, test.t.a)])->Aggr(count(s.b))}->Projection", + best: "Apply{DataScan(t)->DataScan(s)->Sel([eq(test.s.a, test.t.a)])->Aggr(count(test.s.b))}->Projection", }, { sql: "select (select count(s.b) k from t s where s.a = t.a having k != 0) from t", - best: "Join{DataScan(t)->DataScan(s)->Aggr(count(s.b),firstrow(s.a))}(test.t.a,s.a)->Projection->Projection->Projection", + best: "Join{DataScan(t)->DataScan(s)->Aggr(count(test.s.b),firstrow(test.s.a))}(test.t.a,test.s.a)->Projection->Projection->Projection", }, { sql: "select (select count(s.b) k from t s where s.a = t1.a) from t t1, t t2", - best: "Join{Join{DataScan(t1)->DataScan(t2)}->DataScan(s)->Aggr(count(s.b),firstrow(s.a))}(t1.a,s.a)->Projection->Projection->Projection", + best: "Join{Join{DataScan(t1)->DataScan(t2)}->DataScan(s)->Aggr(count(test.s.b),firstrow(test.s.a))}(test.t1.a,test.s.a)->Projection->Projection->Projection", }, { sql: "select (select count(1) k from t s where s.a = t.a having k != 0) from t", - best: "Join{DataScan(t)->DataScan(s)->Aggr(count(1),firstrow(s.a))}(test.t.a,s.a)->Projection->Projection->Projection", + best: "Join{DataScan(t)->DataScan(s)->Aggr(count(1),firstrow(test.s.a))}(test.t.a,test.s.a)->Projection->Projection->Projection", }, { sql: "select a from t where a in (select a from t s group by t.b)", - best: "Join{DataScan(t)->DataScan(s)->Aggr(firstrow(s.a))->Projection}(test.t.a,s.a)->Projection", + best: "Join{DataScan(t)->DataScan(s)->Aggr(firstrow(test.s.a))->Projection}(test.t.a,test.s.a)->Projection", }, { // This will be resolved as in sub query. sql: "select * from t where 10 in (((select b from t s where s.a = t.a)))", - best: "Join{DataScan(t)->DataScan(s)}(test.t.a,s.a)->Projection", + best: "Join{DataScan(t)->DataScan(s)}(test.t.a,test.s.a)->Projection", }, { // This will be resolved as in function. sql: "select * from t where 10 in (((select b from t s where s.a = t.a)), 10)", - best: "Join{DataScan(t)->DataScan(s)}(test.t.a,s.a)->Projection->Sel([in(10, s.b, 10)])->Projection", + best: "Join{DataScan(t)->DataScan(s)}(test.t.a,test.s.a)->Projection->Sel([in(10, test.s.b, 10)])->Projection", }, { sql: "select * from t where exists (select s.a from t s having sum(s.a) = t.a )", - best: "Join{DataScan(t)->DataScan(s)->Aggr(sum(s.a))->Projection}->Projection", + best: "Join{DataScan(t)->DataScan(s)->Aggr(sum(test.s.a))->Projection}->Projection", }, { // Test MaxOneRow for limit. sql: "select (select * from (select b from t limit 1) x where x.b = t1.b) from t t1", - best: "Join{DataScan(t1)->DataScan(t)->Projection->Limit}(t1.b,x.b)->Projection->Projection", + best: "Join{DataScan(t1)->DataScan(t)->Projection->Limit}(test.t1.b,test.x.b)->Projection->Projection", }, { // Test Nested sub query. sql: "select * from t where exists (select s.a from t s where s.c in (select c from t as k where k.d = s.d) having sum(s.a) = t.a )", - best: "Join{DataScan(t)->Join{DataScan(s)->DataScan(k)}(s.d,k.d)(s.c,k.c)->Aggr(sum(s.a))->Projection}->Projection", + best: "Join{DataScan(t)->Join{DataScan(s)->DataScan(k)}(test.s.d,test.k.d)(test.s.c,test.k.c)->Aggr(sum(test.s.a))->Projection}->Projection", }, { sql: "select t1.b from t t1 where t1.b = (select max(t2.a) from t t2 where t1.b=t2.b)", - best: "Join{DataScan(t1)->DataScan(t2)->Aggr(max(t2.a),firstrow(t2.b))}(t1.b,t2.b)->Projection->Sel([eq(t1.b, max(t2.a))])->Projection", + best: "Join{DataScan(t1)->DataScan(t2)->Aggr(max(test.t2.a),firstrow(test.t2.b))}(test.t1.b,test.t2.b)->Projection->Sel([eq(test.t1.b, max(t2.a))])->Projection", }, { sql: "select t1.b from t t1 where t1.b = (select avg(t2.a) from t t2 where t1.g=t2.g and (t1.b = 4 or t2.b = 2))", - best: "Apply{DataScan(t1)->DataScan(t2)->Sel([eq(t1.g, t2.g) or(eq(t1.b, 4), eq(t2.b, 2))])->Aggr(avg(t2.a))}->Projection->Sel([eq(cast(t1.b), avg(t2.a))])->Projection", + best: "Apply{DataScan(t1)->DataScan(t2)->Sel([eq(test.t1.g, test.t2.g) or(eq(test.t1.b, 4), eq(test.t2.b, 2))])->Aggr(avg(test.t2.a))}->Projection->Sel([eq(cast(test.t1.b), avg(t2.a))])->Projection", }, } - for _, ca := range tests { + for ith, ca := range tests { comment := Commentf("for %s", ca.sql) stmt, err := s.ParseOneStmt(ca.sql, "", "") c.Assert(err, IsNil, comment) @@ -865,7 +864,7 @@ func (s *testPlanSuite) TestSubquery(c *C) { p, err = logicalOptimize(flagBuildKeyInfo|flagDecorrelate|flagPrunColumns, lp) c.Assert(err, IsNil) } - c.Assert(ToString(p), Equals, ca.best, Commentf("for %s", ca.sql)) + c.Assert(ToString(p), Equals, ca.best, Commentf("for %s %d", ca.sql, ith)) } } @@ -974,15 +973,15 @@ func (s *testPlanSuite) TestJoinReOrder(c *C) { }{ { sql: "select * from t t1, t t2, t t3, t t4, t t5, t t6 where t1.a = t2.b and t2.a = t3.b and t3.c = t4.a and t4.d = t2.c and t5.d = t6.d", - best: "Join{Join{Join{Join{DataScan(t1)->DataScan(t2)}(t1.a,t2.b)->DataScan(t3)}(t2.a,t3.b)->DataScan(t4)}(t3.c,t4.a)(t2.c,t4.d)->Join{DataScan(t5)->DataScan(t6)}(t5.d,t6.d)}->Projection", + best: "Join{Join{Join{Join{DataScan(t1)->DataScan(t2)}(test.t1.a,test.t2.b)->DataScan(t3)}(test.t2.a,test.t3.b)->DataScan(t4)}(test.t3.c,test.t4.a)(test.t2.c,test.t4.d)->Join{DataScan(t5)->DataScan(t6)}(test.t5.d,test.t6.d)}->Projection", }, { sql: "select * from t t1, t t2, t t3, t t4, t t5, t t6, t t7, t t8 where t1.a = t8.a", - best: "Join{Join{Join{Join{DataScan(t1)->DataScan(t8)}(t1.a,t8.a)->DataScan(t2)}->Join{DataScan(t3)->DataScan(t4)}}->Join{Join{DataScan(t5)->DataScan(t6)}->DataScan(t7)}}->Projection", + best: "Join{Join{Join{Join{DataScan(t1)->DataScan(t8)}(test.t1.a,test.t8.a)->DataScan(t2)}->Join{DataScan(t3)->DataScan(t4)}}->Join{Join{DataScan(t5)->DataScan(t6)}->DataScan(t7)}}->Projection", }, { sql: "select * from t t1, t t2, t t3, t t4, t t5 where t1.a = t5.a and t5.a = t4.a and t4.a = t3.a and t3.a = t2.a and t2.a = t1.a and t1.a = t3.a and t2.a = t4.a and t5.b < 8", - best: "Join{Join{Join{Join{DataScan(t5)->DataScan(t1)}(t5.a,t1.a)->DataScan(t2)}(t1.a,t2.a)->DataScan(t3)}(t2.a,t3.a)(t1.a,t3.a)->DataScan(t4)}(t5.a,t4.a)(t3.a,t4.a)(t2.a,t4.a)->Projection", + best: "Join{Join{Join{Join{DataScan(t5)->DataScan(t1)}(test.t5.a,test.t1.a)->DataScan(t2)}(test.t1.a,test.t2.a)->DataScan(t3)}(test.t2.a,test.t3.a)(test.t1.a,test.t3.a)->DataScan(t4)}(test.t5.a,test.t4.a)(test.t3.a,test.t4.a)(test.t2.a,test.t4.a)->Projection", }, { sql: "select * from t t1, t t2, t t3, t t4, t t5 where t1.a = t5.a and t5.a = t4.a and t4.a = t3.a and t3.a = t2.a and t2.a = t1.a and t1.a = t3.a and t2.a = t4.a and t3.b = 1 and t4.a = 1", @@ -990,7 +989,7 @@ func (s *testPlanSuite) TestJoinReOrder(c *C) { }, { sql: "select * from t o where o.b in (select t3.c from t t1, t t2, t t3 where t1.a = t3.a and t2.a = t3.a and t2.a = o.a)", - best: "Apply{DataScan(o)->Join{Join{DataScan(t2)->DataScan(t3)}(t2.a,t3.a)->DataScan(t1)}(t3.a,t1.a)->Projection}->Projection", + best: "Apply{DataScan(o)->Join{Join{DataScan(t2)->DataScan(t3)}(test.t2.a,test.t3.a)->DataScan(t1)}(test.t3.a,test.t1.a)->Projection}->Projection", }, { sql: "select * from t o where o.b in (select t3.c from t t1, t t2, t t3 where t1.a = t3.a and t2.a = t3.a and t2.a = o.a and t1.a = 1)", @@ -1026,47 +1025,47 @@ func (s *testPlanSuite) TestEagerAggregation(c *C) { }, { sql: "select sum(a.a) from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->Aggr(sum(a.a),firstrow(a.c))->DataScan(b)}(a.c,b.c)->Aggr(sum(join_agg_0))->Projection", + best: "Join{DataScan(a)->Aggr(sum(test.a.a),firstrow(test.a.c))->DataScan(b)}(test.a.c,test.b.c)->Aggr(sum(join_agg_0))->Projection", }, { sql: "select sum(b.a) from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->DataScan(b)->Aggr(sum(b.a),firstrow(b.c))}(a.c,b.c)->Aggr(sum(join_agg_0))->Projection", + best: "Join{DataScan(a)->DataScan(b)->Aggr(sum(test.b.a),firstrow(test.b.c))}(test.a.c,test.b.c)->Aggr(sum(join_agg_0))->Projection", }, { sql: "select sum(b.a), a.a from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->DataScan(b)->Aggr(sum(b.a),firstrow(b.c))}(a.c,b.c)->Aggr(sum(join_agg_0),firstrow(a.a))->Projection", + best: "Join{DataScan(a)->DataScan(b)->Aggr(sum(test.b.a),firstrow(test.b.c))}(test.a.c,test.b.c)->Aggr(sum(join_agg_0),firstrow(test.a.a))->Projection", }, { sql: "select sum(a.a), b.a from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->Aggr(sum(a.a),firstrow(a.c))->DataScan(b)}(a.c,b.c)->Aggr(sum(join_agg_0),firstrow(b.a))->Projection", + best: "Join{DataScan(a)->Aggr(sum(test.a.a),firstrow(test.a.c))->DataScan(b)}(test.a.c,test.b.c)->Aggr(sum(join_agg_0),firstrow(test.b.a))->Projection", }, { sql: "select sum(a.a), sum(b.a) from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->DataScan(b)}(a.c,b.c)->Aggr(sum(a.a),sum(b.a))->Projection", + best: "Join{DataScan(a)->DataScan(b)}(test.a.c,test.b.c)->Aggr(sum(test.a.a),sum(test.b.a))->Projection", }, { sql: "select sum(a.a), max(b.a) from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->Aggr(sum(a.a),firstrow(a.c))->DataScan(b)}(a.c,b.c)->Aggr(sum(join_agg_0),max(b.a))->Projection", + best: "Join{DataScan(a)->Aggr(sum(test.a.a),firstrow(test.a.c))->DataScan(b)}(test.a.c,test.b.c)->Aggr(sum(join_agg_0),max(test.b.a))->Projection", }, { sql: "select max(a.a), sum(b.a) from t a, t b where a.c = b.c", - best: "Join{DataScan(a)->DataScan(b)->Aggr(sum(b.a),firstrow(b.c))}(a.c,b.c)->Aggr(max(a.a),sum(join_agg_0))->Projection", + best: "Join{DataScan(a)->DataScan(b)->Aggr(sum(test.b.a),firstrow(test.b.c))}(test.a.c,test.b.c)->Aggr(max(test.a.a),sum(join_agg_0))->Projection", }, { sql: "select sum(a.a) from t a, t b, t c where a.c = b.c and b.c = c.c", - best: "Join{Join{DataScan(a)->DataScan(b)}(a.c,b.c)->DataScan(c)}(b.c,c.c)->Aggr(sum(a.a))->Projection", + best: "Join{Join{DataScan(a)->DataScan(b)}(test.a.c,test.b.c)->DataScan(c)}(test.b.c,test.c.c)->Aggr(sum(test.a.a))->Projection", }, { sql: "select sum(b.a) from t a left join t b on a.c = b.c", - best: "Join{DataScan(a)->DataScan(b)->Aggr(sum(b.a),firstrow(b.c))}(a.c,b.c)->Aggr(sum(join_agg_0))->Projection", + best: "Join{DataScan(a)->DataScan(b)->Aggr(sum(test.b.a),firstrow(test.b.c))}(test.a.c,test.b.c)->Aggr(sum(join_agg_0))->Projection", }, { sql: "select sum(a.a) from t a left join t b on a.c = b.c", - best: "Join{DataScan(a)->Aggr(sum(a.a),firstrow(a.c))->DataScan(b)}(a.c,b.c)->Aggr(sum(join_agg_0))->Projection", + best: "Join{DataScan(a)->Aggr(sum(test.a.a),firstrow(test.a.c))->DataScan(b)}(test.a.c,test.b.c)->Aggr(sum(join_agg_0))->Projection", }, { sql: "select sum(a.a) from t a right join t b on a.c = b.c", - best: "Join{DataScan(a)->Aggr(sum(a.a),firstrow(a.c))->DataScan(b)}(a.c,b.c)->Aggr(sum(join_agg_0))->Projection", + best: "Join{DataScan(a)->Aggr(sum(test.a.a),firstrow(test.a.c))->DataScan(b)}(test.a.c,test.b.c)->Aggr(sum(join_agg_0))->Projection", }, { sql: "select sum(a) from (select * from t) x", @@ -1074,15 +1073,15 @@ func (s *testPlanSuite) TestEagerAggregation(c *C) { }, { sql: "select sum(c1) from (select c c1, d c2 from t a union all select a c1, b c2 from t b union all select b c1, e c2 from t c) x group by c2", - best: "UnionAll{DataScan(a)->Projection->Aggr(sum(a.c1),firstrow(a.c2))->DataScan(b)->Projection->Aggr(sum(b.c1),firstrow(b.c2))->DataScan(c)->Projection->Aggr(sum(c.c1),firstrow(c.c2))}->Aggr(sum(join_agg_0))->Projection", + best: "UnionAll{DataScan(a)->Projection->Aggr(sum(test.a.c1),firstrow(test.a.c2))->DataScan(b)->Projection->Aggr(sum(test.b.c1),firstrow(test.b.c2))->DataScan(c)->Projection->Aggr(sum(test.c.c1),firstrow(test.c.c2))}->Aggr(sum(join_agg_0))->Projection", }, { sql: "select max(a.b), max(b.b) from t a join t b on a.c = b.c group by a.a", - best: "Join{DataScan(a)->DataScan(b)->Aggr(max(b.b),firstrow(b.c))}(a.c,b.c)->Projection->Projection", + best: "Join{DataScan(a)->DataScan(b)->Aggr(max(test.b.b),firstrow(test.b.c))}(test.a.c,test.b.c)->Projection->Projection", }, { sql: "select max(a.b), max(b.b) from t a join t b on a.a = b.a group by a.c", - best: "Join{DataScan(a)->DataScan(b)}(a.a,b.a)->Aggr(max(a.b),max(b.b))->Projection", + best: "Join{DataScan(a)->DataScan(b)}(test.a.a,test.b.a)->Aggr(max(test.a.b),max(test.b.b))->Projection", }, { sql: "select max(c.b) from (select * from t a union all select * from t b) c group by c.a", @@ -1090,11 +1089,11 @@ func (s *testPlanSuite) TestEagerAggregation(c *C) { }, { sql: "select max(a.c) from t a join t b on a.a=b.a and a.b=b.b group by a.b", - best: "Join{DataScan(a)->DataScan(b)}(a.a,b.a)(a.b,b.b)->Aggr(max(a.c))->Projection", + best: "Join{DataScan(a)->DataScan(b)}(test.a.a,test.b.a)(test.a.b,test.b.b)->Aggr(max(test.a.c))->Projection", }, } s.ctx.GetSessionVars().AllowAggPushDown = true - for _, tt := range tests { + for ith, tt := range tests { comment := Commentf("for %s", tt.sql) stmt, err := s.ParseOneStmt(tt.sql, "", "") c.Assert(err, IsNil, comment) @@ -1103,7 +1102,7 @@ func (s *testPlanSuite) TestEagerAggregation(c *C) { c.Assert(err, IsNil) p, err = logicalOptimize(flagBuildKeyInfo|flagPredicatePushDown|flagPrunColumns|flagAggregationOptimize, p.(LogicalPlan)) c.Assert(err, IsNil) - c.Assert(ToString(p), Equals, tt.best, Commentf("for %s", tt.sql)) + c.Assert(ToString(p), Equals, tt.best, Commentf("for %s %d", tt.sql, ith)) } s.ctx.GetSessionVars().AllowAggPushDown = false } @@ -1479,10 +1478,10 @@ func (s *testPlanSuite) TestUniqueKeyInfo(c *C) { { sql: "select * from t t1 join t t2 on t1.a = t2.e", ans: map[int][][]string{ - 1: {{"t1.f"}, {"t1.f", "t1.g"}, {"t1.a"}}, - 2: {{"t2.f"}, {"t2.f", "t2.g"}, {"t2.a"}}, - 3: {{"t2.f"}, {"t2.f", "t2.g"}, {"t2.a"}}, - 4: {{"t2.f"}, {"t2.f", "t2.g"}, {"t2.a"}}, + 1: {{"test.t1.f"}, {"test.t1.f", "test.t1.g"}, {"test.t1.a"}}, + 2: {{"test.t2.f"}, {"test.t2.f", "test.t2.g"}, {"test.t2.a"}}, + 3: {{"test.t2.f"}, {"test.t2.f", "test.t2.g"}, {"test.t2.a"}}, + 4: {{"test.t2.f"}, {"test.t2.f", "test.t2.g"}, {"test.t2.a"}}, }, }, { @@ -1498,15 +1497,15 @@ func (s *testPlanSuite) TestUniqueKeyInfo(c *C) { { sql: "select * from t t1 left join t t2 on t1.a = t2.a", ans: map[int][][]string{ - 1: {{"t1.f"}, {"t1.f", "t1.g"}, {"t1.a"}}, - 2: {{"t2.f"}, {"t2.f", "t2.g"}, {"t2.a"}}, - 3: {{"t1.f"}, {"t1.f", "t1.g"}, {"t1.a"}}, - 4: {{"t1.f"}, {"t1.f", "t1.g"}, {"t1.a"}}, + 1: {{"test.t1.f"}, {"test.t1.f", "test.t1.g"}, {"test.t1.a"}}, + 2: {{"test.t2.f"}, {"test.t2.f", "test.t2.g"}, {"test.t2.a"}}, + 3: {{"test.t1.f"}, {"test.t1.f", "test.t1.g"}, {"test.t1.a"}}, + 4: {{"test.t1.f"}, {"test.t1.f", "test.t1.g"}, {"test.t1.a"}}, }, }, } - for _, tt := range tests { - comment := Commentf("for %s", tt.sql) + for ith, tt := range tests { + comment := Commentf("for %s %d", tt.sql, ith) stmt, err := s.ParseOneStmt(tt.sql, "", "") c.Assert(err, IsNil, comment) @@ -1534,7 +1533,7 @@ func (s *testPlanSuite) TestAggPrune(c *C) { }, { sql: "select t1.a, count(t2.b) from t t1, t t2 where t1.a = t2.a group by t1.a", - best: "Join{DataScan(t1)->DataScan(t2)}(t1.a,t2.a)->Projection->Projection", + best: "Join{DataScan(t1)->DataScan(t2)}(test.t1.a,test.t2.a)->Projection->Projection", }, { sql: "select tt.a, sum(tt.b) from (select a, b from t) tt group by tt.a", @@ -1902,67 +1901,67 @@ func (s *testPlanSuite) TestTopNPushDown(c *C) { // Test TopN + Left Join + Proj. { sql: "select * from t left outer join t s on t.a = s.a order by t.a limit 5", - best: "Join{DataScan(t)->TopN([test.t.a],0,5)->DataScan(s)}(test.t.a,s.a)->TopN([test.t.a],0,5)->Projection", + best: "Join{DataScan(t)->TopN([test.t.a],0,5)->DataScan(s)}(test.t.a,test.s.a)->TopN([test.t.a],0,5)->Projection", }, // Test TopN + Left Join + Proj. { sql: "select * from t left outer join t s on t.a = s.a order by t.a limit 5, 5", - best: "Join{DataScan(t)->TopN([test.t.a],0,10)->DataScan(s)}(test.t.a,s.a)->TopN([test.t.a],5,5)->Projection", + best: "Join{DataScan(t)->TopN([test.t.a],0,10)->DataScan(s)}(test.t.a,test.s.a)->TopN([test.t.a],5,5)->Projection", }, // Test Limit + Left Join + Proj. { sql: "select * from t left outer join t s on t.a = s.a limit 5", - best: "Join{DataScan(t)->Limit->DataScan(s)}(test.t.a,s.a)->Limit->Projection", + best: "Join{DataScan(t)->Limit->DataScan(s)}(test.t.a,test.s.a)->Limit->Projection", }, // Test Limit + Left Join Apply + Proj. { sql: "select (select s.a from t s where t.a = s.a) from t limit 5", - best: "Join{DataScan(t)->Limit->DataScan(s)}(test.t.a,s.a)->Limit->Projection", + best: "Join{DataScan(t)->Limit->DataScan(s)}(test.t.a,test.s.a)->Limit->Projection", }, // Test TopN + Left Join Apply + Proj. { sql: "select (select s.a from t s where t.a = s.a) from t order by t.a limit 5", - best: "Join{DataScan(t)->TopN([test.t.a],0,5)->DataScan(s)}(test.t.a,s.a)->TopN([test.t.a],0,5)->Projection", + best: "Join{DataScan(t)->TopN([test.t.a],0,5)->DataScan(s)}(test.t.a,test.s.a)->TopN([test.t.a],0,5)->Projection", }, // Test TopN + Left Semi Join Apply + Proj. { sql: "select exists (select s.a from t s where t.a = s.a) from t order by t.a limit 5", - best: "Join{DataScan(t)->TopN([test.t.a],0,5)->DataScan(s)}(test.t.a,s.a)->TopN([test.t.a],0,5)->Projection", + best: "Join{DataScan(t)->TopN([test.t.a],0,5)->DataScan(s)}(test.t.a,test.s.a)->TopN([test.t.a],0,5)->Projection", }, // Test TopN + Semi Join Apply + Proj. { sql: "select * from t where exists (select s.a from t s where t.a = s.a) order by t.a limit 5", - best: "Join{DataScan(t)->DataScan(s)}(test.t.a,s.a)->TopN([test.t.a],0,5)->Projection", + best: "Join{DataScan(t)->DataScan(s)}(test.t.a,test.s.a)->TopN([test.t.a],0,5)->Projection", }, // Test TopN + Right Join + Proj. { sql: "select * from t right outer join t s on t.a = s.a order by s.a limit 5", - best: "Join{DataScan(t)->DataScan(s)->TopN([s.a],0,5)}(test.t.a,s.a)->TopN([s.a],0,5)->Projection", + best: "Join{DataScan(t)->DataScan(s)->TopN([test.s.a],0,5)}(test.t.a,test.s.a)->TopN([test.s.a],0,5)->Projection", }, // Test Limit + Right Join + Proj. { sql: "select * from t right outer join t s on t.a = s.a order by s.a,t.b limit 5", - best: "Join{DataScan(t)->DataScan(s)}(test.t.a,s.a)->TopN([s.a test.t.b],0,5)->Projection", + best: "Join{DataScan(t)->DataScan(s)}(test.t.a,test.s.a)->TopN([test.s.a test.t.b],0,5)->Projection", }, // Test TopN + UA + Proj. { sql: "select * from t union all (select * from t s) order by a,b limit 5", - best: "UnionAll{DataScan(t)->TopN([test.t.a test.t.b],0,5)->Projection->DataScan(s)->TopN([s.a s.b],0,5)->Projection}->TopN([a b],0,5)", + best: "UnionAll{DataScan(t)->TopN([test.t.a test.t.b],0,5)->Projection->DataScan(s)->TopN([test.s.a test.s.b],0,5)->Projection}->TopN([a b],0,5)", }, // Test TopN + UA + Proj. { sql: "select * from t union all (select * from t s) order by a,b limit 5, 5", - best: "UnionAll{DataScan(t)->TopN([test.t.a test.t.b],0,10)->Projection->DataScan(s)->TopN([s.a s.b],0,10)->Projection}->TopN([a b],5,5)", + best: "UnionAll{DataScan(t)->TopN([test.t.a test.t.b],0,10)->Projection->DataScan(s)->TopN([test.s.a test.s.b],0,10)->Projection}->TopN([a b],5,5)", }, // Test Limit + UA + Proj + Sort. { sql: "select * from t union all (select * from t s order by a) limit 5", - best: "UnionAll{DataScan(t)->Limit->Projection->DataScan(s)->TopN([s.a],0,5)->Projection}->Limit", + best: "UnionAll{DataScan(t)->Limit->Projection->DataScan(s)->TopN([test.s.a],0,5)->Projection}->Limit", }, // Test `ByItem` containing column from both sides. { sql: "select ifnull(t1.b, t2.a) from t t1 left join t t2 on t1.e=t2.e order by ifnull(t1.b, t2.a) limit 5", - best: "Join{DataScan(t1)->DataScan(t2)}(t1.e,t2.e)->TopN([ifnull(t1.b, t2.a)],0,5)->Projection->Projection", + best: "Join{DataScan(t1)->DataScan(t2)}(test.t1.e,test.t2.e)->TopN([ifnull(test.t1.b, test.t2.a)],0,5)->Projection->Projection", }, } for i, tt := range tests { diff --git a/planner/core/physical_plan_test.go b/planner/core/physical_plan_test.go index e0904336d8fa8..458fe62fba065 100644 --- a/planner/core/physical_plan_test.go +++ b/planner/core/physical_plan_test.go @@ -187,7 +187,7 @@ func (s *testPlanSuite) TestDAGPlanBuilderSimpleCase(c *C) { }, { sql: "select * from (select * from t use index() order by b) t left join t t1 on t.a=t1.a limit 10", - best: "IndexJoin{TableReader(Table(t)->TopN([test.t.b],0,10))->TopN([test.t.b],0,10)->TableReader(Table(t))}(test.t.a,t1.a)->Limit", + best: "IndexJoin{TableReader(Table(t)->TopN([test.t.b],0,10))->TopN([test.t.b],0,10)->TableReader(Table(t))}(test.t.a,test.t1.a)->Limit", }, // Test embedded ORDER BY which imposes on different number of columns than outer query. { @@ -231,195 +231,195 @@ func (s *testPlanSuite) TestDAGPlanBuilderJoin(c *C) { }{ { sql: "select * from t t1 join t t2 on t1.a = t2.c_str", - best: "LeftHashJoin{TableReader(Table(t))->Projection->TableReader(Table(t))->Projection}(cast(t1.a),cast(t2.c_str))->Projection", + best: "LeftHashJoin{TableReader(Table(t))->Projection->TableReader(Table(t))->Projection}(cast(test.t1.a),cast(test.t2.c_str))->Projection", }, { sql: "select * from t t1 join t t2 on t1.b = t2.a", - best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.b,t2.a)", + best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.b,test.t2.a)", }, { sql: "select * from t t1 join t t2 on t1.a = t2.a join t t3 on t1.a = t3.a", - best: "MergeInnerJoin{MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)->TableReader(Table(t))}(t1.a,t3.a)", + best: "MergeInnerJoin{MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)->TableReader(Table(t))}(test.t1.a,test.t3.a)", }, { sql: "select * from t t1 join t t2 on t1.a = t2.a join t t3 on t1.b = t3.a", - best: "LeftHashJoin{MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)->TableReader(Table(t))}(t1.b,t3.a)", + best: "LeftHashJoin{MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)->TableReader(Table(t))}(test.t1.b,test.t3.a)", }, { sql: "select * from t t1 join t t2 on t1.b = t2.a order by t1.a", - best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.b,t2.a)->Sort", + best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.b,test.t2.a)->Sort", }, { sql: "select * from t t1 join t t2 on t1.b = t2.a order by t1.a limit 1", - best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.b,t2.a)->Limit", + best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.b,test.t2.a)->Limit", }, // Test hash join's hint. { sql: "select /*+ TIDB_HJ(t1, t2) */ * from t t1 join t t2 on t1.b = t2.a order by t1.a limit 1", - best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.b,t2.a)->TopN([t1.a],0,1)", + best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.b,test.t2.a)->TopN([test.t1.a],0,1)", }, { sql: "select * from t t1 left join t t2 on t1.b = t2.a where 1 = 1 limit 1", - best: "IndexJoin{TableReader(Table(t)->Limit)->Limit->TableReader(Table(t))}(t1.b,t2.a)->Limit", + best: "IndexJoin{TableReader(Table(t)->Limit)->Limit->TableReader(Table(t))}(test.t1.b,test.t2.a)->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: "IndexJoin{IndexLookUp(Index(t.c_d_e)[[1 1 1,1 1 1]], Table(t))->TableReader(Table(t))}(t1.b,t2.a)->TopN([t1.a],0,1)", + best: "IndexJoin{IndexLookUp(Index(t.c_d_e)[[1 1 1,1 1 1]], Table(t))->TableReader(Table(t))}(test.t1.b,test.t2.a)->TopN([test.t1.a],0,1)", }, { sql: "select * from t t1 join t t2 on t1.b = t2.b join t t3 on t1.b = t3.b", - best: "LeftHashJoin{LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.b,t2.b)->TableReader(Table(t))}(t1.b,t3.b)", + best: "LeftHashJoin{LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.b,test.t2.b)->TableReader(Table(t))}(test.t1.b,test.t3.b)", }, { sql: "select * from t t1 join t t2 on t1.a = t2.a order by t1.a", - best: "MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)", + best: "MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)", }, { sql: "select * from t t1 left outer join t t2 on t1.a = t2.a right outer join t t3 on t1.a = t3.a", - best: "MergeRightOuterJoin{MergeLeftOuterJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)->TableReader(Table(t))}(t1.a,t3.a)", + best: "MergeRightOuterJoin{MergeLeftOuterJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)->TableReader(Table(t))}(test.t1.a,test.t3.a)", }, { 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: "LeftHashJoin{IndexJoin{TableReader(Table(t)->Sel([eq(t1.b, 1)]))->TableReader(Table(t))}(t1.a,t2.a)->IndexLookUp(Index(t.c_d_e)[[1,1]], Table(t))}(t1.a,t3.a)", + best: "LeftHashJoin{IndexJoin{TableReader(Table(t)->Sel([eq(test.t1.b, 1)]))->TableReader(Table(t))}(test.t1.a,test.t2.a)->IndexLookUp(Index(t.c_d_e)[[1,1]], Table(t))}(test.t1.a,test.t3.a)", }, { sql: "select * from t where t.c in (select b from t s where s.a = t.a)", - best: "MergeSemiJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t.a,s.a)", + best: "MergeSemiJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t.a,test.s.a)", }, { sql: "select t.c in (select b from t s where s.a = t.a) from t", - best: "MergeLeftOuterSemiJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t.a,s.a)->Projection", + best: "MergeLeftOuterSemiJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t.a,test.s.a)->Projection", }, // Test Single Merge Join. // Merge Join now enforce a sort. { sql: "select /*+ TIDB_SMJ(t1,t2)*/ * from t t1, t t2 where t1.a = t2.b", - best: "MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))->Sort}(t1.a,t2.b)", + best: "MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))->Sort}(test.t1.a,test.t2.b)", }, { sql: "select /*+ TIDB_SMJ(t1,t2)*/ * from t t1, t t2 where t1.a = t2.a", - best: "MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)", + best: "MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)", }, // Test Single Merge Join + Sort. { sql: "select /*+ TIDB_SMJ(t1,t2)*/ * from t t1, t t2 where t1.a = t2.a order by t2.a", - best: "MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)", + best: "MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)", }, { sql: "select /*+ TIDB_SMJ(t1,t2)*/ * from t t1, t t2 where t1.b = t2.b order by t2.a", - best: "MergeInnerJoin{TableReader(Table(t))->Sort->TableReader(Table(t))->Sort}(t1.b,t2.b)->Sort", + best: "MergeInnerJoin{TableReader(Table(t))->Sort->TableReader(Table(t))->Sort}(test.t1.b,test.t2.b)->Sort", }, // Test Single Merge Join + Sort + desc. { sql: "select /*+ TIDB_SMJ(t1,t2)*/ * from t t1, t t2 where t1.a = t2.a order by t2.a desc", - best: "MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)", + best: "MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)", }, { sql: "select /*+ TIDB_SMJ(t1,t2)*/ * from t t1, t t2 where t1.b = t2.b order by t2.b desc", - best: "MergeInnerJoin{TableReader(Table(t))->Sort->TableReader(Table(t))->Sort}(t1.b,t2.b)", + best: "MergeInnerJoin{TableReader(Table(t))->Sort->TableReader(Table(t))->Sort}(test.t1.b,test.t2.b)", }, // Test Multi Merge Join. { sql: "select /*+ TIDB_SMJ(t1,t2,t3)*/ * from t t1, t t2, t t3 where t1.a = t2.a and t2.a = t3.a", - best: "MergeInnerJoin{MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)->TableReader(Table(t))}(t2.a,t3.a)", + best: "MergeInnerJoin{MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)->TableReader(Table(t))}(test.t2.a,test.t3.a)", }, { sql: "select /*+ TIDB_SMJ(t1,t2,t3)*/ * from t t1, t t2, t t3 where t1.a = t2.b and t2.a = t3.b", - best: "MergeInnerJoin{MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))->Sort}(t1.a,t2.b)->Sort->TableReader(Table(t))->Sort}(t2.a,t3.b)", + best: "MergeInnerJoin{MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))->Sort}(test.t1.a,test.t2.b)->Sort->TableReader(Table(t))->Sort}(test.t2.a,test.t3.b)", }, // Test Multi Merge Join with multi keys. // TODO: More tests should be added. { sql: "select /*+ TIDB_SMJ(t1,t2,t3)*/ * from t t1, t t2, t t3 where t1.c = t2.c and t1.d = t2.d and t3.c = t1.c and t3.d = t1.d", - best: "MergeInnerJoin{MergeInnerJoin{IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(t1.c,t2.c)(t1.d,t2.d)->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(t1.c,t3.c)(t1.d,t3.d)", + best: "MergeInnerJoin{MergeInnerJoin{IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(test.t1.c,test.t2.c)(test.t1.d,test.t2.d)->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(test.t1.c,test.t3.c)(test.t1.d,test.t3.d)", }, { sql: "select /*+ TIDB_SMJ(t1,t2,t3)*/ * from t t1, t t2, t t3 where t1.c = t2.c and t1.d = t2.d and t3.c = t1.c and t3.d = t1.d order by t1.c", - best: "MergeInnerJoin{MergeInnerJoin{IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(t1.c,t2.c)(t1.d,t2.d)->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(t1.c,t3.c)(t1.d,t3.d)", + best: "MergeInnerJoin{MergeInnerJoin{IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(test.t1.c,test.t2.c)(test.t1.d,test.t2.d)->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(test.t1.c,test.t3.c)(test.t1.d,test.t3.d)", }, // Test Multi Merge Join + Outer Join. { sql: "select /*+ TIDB_SMJ(t1,t2,t3)*/ * from t t1 left outer join t t2 on t1.a = t2.a left outer join t t3 on t2.a = t3.a", - best: "MergeLeftOuterJoin{MergeLeftOuterJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)->TableReader(Table(t))}(t2.a,t3.a)", + best: "MergeLeftOuterJoin{MergeLeftOuterJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)->TableReader(Table(t))}(test.t2.a,test.t3.a)", }, { sql: "select /*+ TIDB_SMJ(t1,t2,t3)*/ * from t t1 left outer join t t2 on t1.a = t2.a left outer join t t3 on t1.a = t3.a", - best: "MergeLeftOuterJoin{MergeLeftOuterJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)->TableReader(Table(t))}(t1.a,t3.a)", + best: "MergeLeftOuterJoin{MergeLeftOuterJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)->TableReader(Table(t))}(test.t1.a,test.t3.a)", }, // Test Index Join + TableScan. { sql: "select /*+ TIDB_INLJ(t1, t2) */ * from t t1, t t2 where t1.a = t2.a", - best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)", + best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)", }, // Test Index Join + DoubleRead. { sql: "select /*+ TIDB_INLJ(t1, t2) */ * from t t1, t t2 where t1.a = t2.c", - best: "IndexJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(t1.a,t2.c)", + best: "IndexJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(test.t1.a,test.t2.c)", }, // Test Index Join + SingleRead. { sql: "select /*+ TIDB_INLJ(t1, t2) */ t1.a , t2.a from t t1, t t2 where t1.a = t2.c", - best: "IndexJoin{TableReader(Table(t))->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(t1.a,t2.c)->Projection", + best: "IndexJoin{TableReader(Table(t))->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(test.t1.a,test.t2.c)->Projection", }, // Test Index Join + Order by. { sql: "select /*+ TIDB_INLJ(t1, t2) */ t1.a, t2.a from t t1, t t2 where t1.a = t2.a order by t1.c", - best: "IndexJoin{IndexReader(Index(t.c_d_e)[[NULL,+inf]])->TableReader(Table(t))}(t1.a,t2.a)->Projection", + best: "IndexJoin{IndexReader(Index(t.c_d_e)[[NULL,+inf]])->TableReader(Table(t))}(test.t1.a,test.t2.a)->Projection", }, // Test Index Join + Order by. { sql: "select /*+ TIDB_INLJ(t1, t2) */ t1.a, t2.a from t t1, t t2 where t1.a = t2.a order by t2.c", - best: "IndexJoin{TableReader(Table(t))->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(t2.a,t1.a)->Projection", + best: "IndexJoin{TableReader(Table(t))->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(test.t2.a,test.t1.a)->Projection", }, // Test Index Join + TableScan + Rotate. { sql: "select /*+ TIDB_INLJ(t1) */ t1.a , t2.a from t t1, t t2 where t1.a = t2.c", - best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(t2.c,t1.a)->Projection", + best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t2.c,test.t1.a)->Projection", }, // Test Index Join + OuterJoin + TableScan. { sql: "select /*+ TIDB_INLJ(t1, t2) */ * from t t1 left outer join t t2 on t1.a = t2.a and t2.b < 1", - best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t)->Sel([lt(t2.b, 1)]))}(t1.a,t2.a)", + best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t)->Sel([lt(test.t2.b, 1)]))}(test.t1.a,test.t2.a)", }, { sql: "select /*+ TIDB_INLJ(t1, t2) */ * from t t1 join t t2 on t1.d=t2.d and t2.c = 1", - best: "IndexJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(t1.d,t2.d)", + best: "IndexJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(test.t1.d,test.t2.d)", }, // Test Index Join failed. { sql: "select /*+ TIDB_INLJ(t1, t2) */ * from t t1 left outer join t t2 on t1.a = t2.b", - best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.b)", + best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.b)", }, // Test Index Join failed. { sql: "select /*+ TIDB_INLJ(t2) */ * from t t1 right outer join t t2 on t1.a = t2.b", - best: "RightHashJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.b)", + best: "RightHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.b)", }, // Test Semi Join hint success. { sql: "select /*+ TIDB_INLJ(t2) */ * from t t1 where t1.a in (select a from t t2)", - best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)", + best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)", }, // Test Semi Join hint fail. { sql: "select /*+ TIDB_INLJ(t1) */ * from t t1 where t1.a in (select a from t t2)", - best: "MergeSemiJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)", + best: "MergeSemiJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)", }, { sql: "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.c=t2.c and t1.f=t2.f", - best: "IndexJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(t1.c,t2.c)", + best: "IndexJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(test.t1.c,test.t2.c)", }, { sql: "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.a = t2.a and t1.f=t2.f", - best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)", + best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)", }, { sql: "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.f=t2.f and t1.a=t2.a", - best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)", + best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)", }, { sql: "select /*+ TIDB_INLJ(t2) */ * from t t1 join t t2 where t1.a=t2.a and t2.a in (1, 2)", - best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t)->Sel([in(t2.a, 1, 2)]))}(t1.a,t2.a)", + best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t)->Sel([in(test.t2.a, 1, 2)]))}(test.t1.a,test.t2.a)", }, } for i, tt := range tests { @@ -453,11 +453,11 @@ func (s *testPlanSuite) TestDAGPlanBuilderSubquery(c *C) { // Test join key with cast. { sql: "select * from t where exists (select s.a from t s having sum(s.a) = t.a )", - best: "LeftHashJoin{TableReader(Table(t))->Projection->TableReader(Table(t)->StreamAgg)->StreamAgg}(cast(test.t.a),sel_agg_1)->Projection", + best: "LeftHashJoin{TableReader(Table(t))->Projection->TableReader(Table(t)->StreamAgg)->StreamAgg}(cast(test.t.a),sel_agg_2)->Projection", }, { sql: "select * from t where exists (select s.a from t s having sum(s.a) = t.a ) order by t.a", - best: "LeftHashJoin{TableReader(Table(t))->Projection->TableReader(Table(t)->StreamAgg)->StreamAgg}(cast(test.t.a),sel_agg_1)->Projection->Sort", + best: "LeftHashJoin{TableReader(Table(t))->Projection->TableReader(Table(t)->StreamAgg)->StreamAgg}(cast(test.t.a),sel_agg_2)->Projection->Sort", }, // FIXME: Report error by resolver. //{ @@ -466,12 +466,12 @@ func (s *testPlanSuite) TestDAGPlanBuilderSubquery(c *C) { //}, { sql: "select * from t where a in (select s.a from t s) order by t.a", - best: "MergeSemiJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t.a,s.a)", + best: "MergeSemiJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t.a,test.s.a)", }, // Test Nested sub query. { sql: "select * from t where exists (select s.a from t s where s.c in (select c from t as k where k.d = s.d) having sum(s.a) = t.a )", - best: "LeftHashJoin{TableReader(Table(t))->Projection->MergeSemiJoin{IndexReader(Index(t.c_d_e)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(s.c,k.c)(s.d,k.d)->Projection->StreamAgg}(cast(test.t.a),sel_agg_1)->Projection", + best: "LeftHashJoin{TableReader(Table(t))->Projection->MergeSemiJoin{IndexReader(Index(t.c_d_e)[[NULL,+inf]])->IndexReader(Index(t.c_d_e)[[NULL,+inf]])}(test.s.c,test.k.c)(test.s.d,test.k.d)->Projection->StreamAgg}(cast(test.t.a),sel_agg_2)->Projection", }, // Test Semi Join + Order by. { @@ -481,15 +481,15 @@ func (s *testPlanSuite) TestDAGPlanBuilderSubquery(c *C) { // Test Apply. { sql: "select t.c in (select count(*) from t s , t t1 where s.a = t.a and s.a = t1.a) from t", - best: "Apply{TableReader(Table(t))->IndexJoin{TableReader(Table(t))->TableReader(Table(t)->Sel([eq(t1.a, test.t.a)]))}(s.a,t1.a)->StreamAgg}->Projection", + best: "Apply{TableReader(Table(t))->IndexJoin{TableReader(Table(t))->TableReader(Table(t)->Sel([eq(test.t1.a, test.t.a)]))}(test.s.a,test.t1.a)->StreamAgg}->Projection", }, { sql: "select (select count(*) from t s , t t1 where s.a = t.a and s.a = t1.a) from t", - best: "LeftHashJoin{TableReader(Table(t))->MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(s.a,t1.a)->StreamAgg}(test.t.a,s.a)->Projection->Projection", + best: "LeftHashJoin{TableReader(Table(t))->MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(test.s.a,test.t1.a)->StreamAgg}(test.t.a,test.s.a)->Projection->Projection", }, { sql: "select (select count(*) from t s , t t1 where s.a = t.a and s.a = t1.a) from t order by t.a", - best: "LeftHashJoin{TableReader(Table(t))->MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(s.a,t1.a)->StreamAgg}(test.t.a,s.a)->Projection->Sort->Projection", + best: "LeftHashJoin{TableReader(Table(t))->MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(test.s.a,test.t1.a)->StreamAgg}(test.t.a,test.s.a)->Projection->Sort->Projection", }, } for _, tt := range tests { @@ -522,15 +522,15 @@ func (s *testPlanSuite) TestDAGPlanTopN(c *C) { }{ { sql: "select * from t t1 left join t t2 on t1.b = t2.b left join t t3 on t2.b = t3.b order by t1.a limit 1", - best: "LeftHashJoin{LeftHashJoin{TableReader(Table(t)->Limit)->Limit->TableReader(Table(t))}(t1.b,t2.b)->TopN([t1.a],0,1)->TableReader(Table(t))}(t2.b,t3.b)->TopN([t1.a],0,1)", + best: "LeftHashJoin{LeftHashJoin{TableReader(Table(t)->Limit)->Limit->TableReader(Table(t))}(test.t1.b,test.t2.b)->TopN([test.t1.a],0,1)->TableReader(Table(t))}(test.t2.b,test.t3.b)->TopN([test.t1.a],0,1)", }, { sql: "select * from t t1 left join t t2 on t1.b = t2.b left join t t3 on t2.b = t3.b order by t1.b limit 1", - best: "LeftHashJoin{LeftHashJoin{TableReader(Table(t)->TopN([t1.b],0,1))->TopN([t1.b],0,1)->TableReader(Table(t))}(t1.b,t2.b)->TopN([t1.b],0,1)->TableReader(Table(t))}(t2.b,t3.b)->TopN([t1.b],0,1)", + best: "LeftHashJoin{LeftHashJoin{TableReader(Table(t)->TopN([test.t1.b],0,1))->TopN([test.t1.b],0,1)->TableReader(Table(t))}(test.t1.b,test.t2.b)->TopN([test.t1.b],0,1)->TableReader(Table(t))}(test.t2.b,test.t3.b)->TopN([test.t1.b],0,1)", }, { sql: "select * from t t1 left join t t2 on t1.b = t2.b left join t t3 on t2.b = t3.b limit 1", - best: "LeftHashJoin{LeftHashJoin{TableReader(Table(t)->Limit)->Limit->TableReader(Table(t))}(t1.b,t2.b)->Limit->TableReader(Table(t))}(t2.b,t3.b)->Limit", + best: "LeftHashJoin{LeftHashJoin{TableReader(Table(t)->Limit)->Limit->TableReader(Table(t))}(test.t1.b,test.t2.b)->Limit->TableReader(Table(t))}(test.t2.b,test.t3.b)->Limit", }, { sql: "select * from t where b = 1 and c = 1 order by c limit 1", @@ -598,19 +598,19 @@ func (s *testPlanSuite) TestDAGPlanBuilderBasePhysicalPlan(c *C) { // Test join hint for delete and update { sql: "delete /*+ TIDB_INLJ(t1, t2) */ t1 from t t1, t t2 where t1.c=t2.c", - best: "IndexJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(t1.c,t2.c)->Delete", + best: "IndexJoin{TableReader(Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(test.t1.c,test.t2.c)->Delete", }, { sql: "delete /*+ TIDB_SMJ(t1, t2) */ from t1 using t t1, t t2 where t1.c=t2.c", - best: "MergeInnerJoin{IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(t1.c,t2.c)->Delete", + best: "MergeInnerJoin{IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(test.t1.c,test.t2.c)->Delete", }, { sql: "update /*+ TIDB_SMJ(t1, t2) */ t t1, t t2 set t1.a=1, t2.a=1 where t1.a=t2.a", - best: "MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)->Update", + best: "MergeInnerJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)->Update", }, { sql: "update /*+ TIDB_HJ(t1, t2) */ t t1, t t2 set t1.a=1, t2.a=1 where t1.a=t2.a", - best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)->Update", + best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)->Update", }, // Test complex delete. { @@ -863,7 +863,7 @@ func (s *testPlanSuite) TestDAGPlanBuilderAgg(c *C) { }, { sql: "select (select count(1) k from t s where s.a = t.a having k != 0) from t", - best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t)->StreamAgg)->StreamAgg->Sel([ne(k, 0)])}(test.t.a,s.a)->Projection->Projection", + best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t)->StreamAgg)->StreamAgg->Sel([ne(k, 0)])}(test.t.a,test.s.a)->Projection->Projection", }, // Test stream agg with multi group by columns. { @@ -915,16 +915,16 @@ func (s *testPlanSuite) TestDAGPlanBuilderAgg(c *C) { // Test merge join + stream agg { sql: "select sum(a.g), sum(b.g) from t a join t b on a.g = b.g group by a.g", - best: "MergeInnerJoin{IndexReader(Index(t.g)[[NULL,+inf]])->IndexReader(Index(t.g)[[NULL,+inf]])}(a.g,b.g)->Projection->StreamAgg", + best: "MergeInnerJoin{IndexReader(Index(t.g)[[NULL,+inf]])->IndexReader(Index(t.g)[[NULL,+inf]])}(test.a.g,test.b.g)->Projection->StreamAgg", }, // Test index join + stream agg { sql: "select /*+ tidb_inlj(a,b) */ sum(a.g), sum(b.g) from t a join t b on a.g = b.g and a.g > 60 group by a.g order by a.g limit 1", - best: "IndexJoin{IndexReader(Index(t.g)[(60,+inf]])->IndexReader(Index(t.g)[[NULL,+inf]]->Sel([gt(b.g, 60)]))}(a.g,b.g)->Projection->StreamAgg->Limit->Projection", + best: "IndexJoin{IndexReader(Index(t.g)[(60,+inf]])->IndexReader(Index(t.g)[[NULL,+inf]]->Sel([gt(test.b.g, 60)]))}(test.a.g,test.b.g)->Projection->StreamAgg->Limit->Projection", }, { sql: "select sum(a.g), sum(b.g) from t a join t b on a.g = b.g and a.a>5 group by a.g order by a.g limit 1", - best: "IndexJoin{IndexReader(Index(t.g)[[NULL,+inf]]->Sel([gt(a.a, 5)]))->IndexReader(Index(t.g)[[NULL,+inf]])}(a.g,b.g)->Projection->StreamAgg->Limit->Projection", + best: "IndexJoin{IndexReader(Index(t.g)[[NULL,+inf]]->Sel([gt(test.a.a, 5)]))->IndexReader(Index(t.g)[[NULL,+inf]])}(test.a.g,test.b.g)->Projection->StreamAgg->Limit->Projection", }, { sql: "select sum(d) from t", @@ -1230,7 +1230,7 @@ func (s *testPlanSuite) TestAggEliminater(c *C) { // If inner is not a data source, we can still do transformation. { sql: "select max(a) from (select t1.a from t t1 join t t2 on t1.a=t2.a) t", - best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(t1.a,t2.a)->Limit->StreamAgg", + best: "IndexJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.a)->Limit->StreamAgg", }, } diff --git a/session/session_test.go b/session/session_test.go index 7b7fc125d594c..4c1744387a4b9 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -2364,6 +2364,29 @@ func (s *testSessionSuite) TestUpdatePrivilege(c *C) { []byte(""), []byte("")), IsTrue) tk1.MustExec("use weperk") tk1.MustExec("update tb_wehub_server a set a.active_count=a.active_count+1,a.used_count=a.used_count+1 where id=1") + + tk.MustExec("create database service") + tk.MustExec("create database report") + tk.MustExec(`CREATE TABLE service.t1 ( + id int(11) DEFAULT NULL, + a bigint(20) NOT NULL, + b text DEFAULT NULL, + PRIMARY KEY (a) +)`) + tk.MustExec(`CREATE TABLE report.t2 ( + a bigint(20) DEFAULT NULL, + c bigint(20) NOT NULL +)`) + tk.MustExec("grant all privileges on service.* to weperk") + tk.MustExec("grant all privileges on report.* to weperk") + tk1.Se.GetSessionVars().CurrentDB = "" + tk1.MustExec(`update service.t1 s, +report.t2 t +set s.a = t.a +WHERE +s.a = t.a +and t.c >= 1 and t.c <= 10000 +and s.b !='xx';`) } func (s *testSessionSuite) TestTxnGoString(c *C) {