From 57fa70a90d62222578a8f050a0ba24547d91327c Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Thu, 20 May 2021 10:28:20 +0800 Subject: [PATCH] planner: remove some risky cache operations in the plan builder (#23354) (#23537) --- cmd/explaintest/r/explain_easy.result | 338 +++++++++--------- cmd/explaintest/r/explain_easy_stats.result | 48 +-- cmd/explaintest/r/select.result | 66 ++-- cmd/explaintest/r/subquery.result | 20 +- cmd/explaintest/r/tpch.result | 28 +- executor/merge_join_test.go | 12 +- executor/testdata/agg_suite_out.json | 52 +-- executor/testdata/executor_suite_out.json | 66 ++-- .../testdata/integration_suite_out.json | 84 ++--- .../cascades/testdata/stringer_suite_out.json | 24 +- planner/core/integration_test.go | 8 + planner/core/logical_plan_builder.go | 30 +- planner/core/planbuilder.go | 20 +- planner/core/testdata/analyze_suite_out.json | 58 +-- .../core/testdata/integration_suite_out.json | 18 +- planner/core/testdata/plan_suite_out.json | 4 +- .../testdata/plan_suite_unexported_out.json | 12 +- util/ranger/testdata/ranger_suite_out.json | 20 +- 18 files changed, 443 insertions(+), 465 deletions(-) diff --git a/cmd/explaintest/r/explain_easy.result b/cmd/explaintest/r/explain_easy.result index 2b86d21eabe32..bfe64629a70a8 100644 --- a/cmd/explaintest/r/explain_easy.result +++ b/cmd/explaintest/r/explain_easy.result @@ -90,13 +90,13 @@ Selection_6 0.33 root gt(test.t1.c2, 1) └─Point_Get_5 1.00 root table:t1 handle:1 explain select sum(t1.c1 in (select c1 from t2)) from t1; id estRows task access object operator info -StreamAgg_9 1.00 root funcs:sum(Column#10)->Column#8 -└─Projection_20 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10 - └─HashJoin_19 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, test.t2.c1) - ├─IndexReader_18(Build) 10000.00 root index:IndexFullScan_17 - │ └─IndexFullScan_17 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo - └─TableReader_12(Probe) 10000.00 root data:TableFullScan_11 - └─TableFullScan_11 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +StreamAgg_10 1.00 root funcs:sum(Column#13)->Column#11 +└─Projection_21 10000.00 root cast(Column#10, decimal(65,0) BINARY)->Column#13 + └─HashJoin_20 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, test.t2.c1) + ├─IndexReader_19(Build) 10000.00 root index:IndexFullScan_18 + │ └─IndexFullScan_18 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo + └─TableReader_13(Probe) 10000.00 root data:TableFullScan_12 + └─TableFullScan_12 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select c1 from t1 where c1 in (select c2 from t2); id estRows task access object operator info HashJoin_15 9990.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] @@ -108,27 +108,27 @@ HashJoin_15 9990.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] └─TableFullScan_27 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select (select count(1) k from t1 s where s.c1 = t1.c1 having k != 0) from t1; id estRows task access object operator info -Projection_12 10000.00 root ifnull(Column#7, 0)->Column#7 -└─MergeJoin_13 10000.00 root left outer join, left key:test.t1.c1, right key:test.t1.c1 - ├─Projection_18(Build) 8000.00 root 1->Column#7, test.t1.c1 - │ └─TableReader_20 10000.00 root data:TableFullScan_19 - │ └─TableFullScan_19 10000.00 cop[tikv] table:s keep order:true, stats:pseudo - └─TableReader_17(Probe) 10000.00 root data:TableFullScan_16 - └─TableFullScan_16 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo +Projection_13 10000.00 root ifnull(Column#10, 0)->Column#10 +└─MergeJoin_14 10000.00 root left outer join, left key:test.t1.c1, right key:test.t1.c1 + ├─Projection_19(Build) 8000.00 root 1->Column#10, test.t1.c1 + │ └─TableReader_21 10000.00 root data:TableFullScan_20 + │ └─TableFullScan_20 10000.00 cop[tikv] table:s keep order:true, stats:pseudo + └─TableReader_18(Probe) 10000.00 root data:TableFullScan_17 + └─TableFullScan_17 10000.00 cop[tikv] table:t1 keep order:true, stats:pseudo explain select * from information_schema.columns; id estRows task access object operator info MemTableScan_4 10000.00 root table:COLUMNS explain select c2 = (select c2 from t2 where t1.c1 = t2.c1 order by c1 limit 1) from t1; id estRows task access object operator info -Projection_12 10000.00 root eq(test.t1.c2, test.t2.c2)->Column#8 -└─Apply_14 10000.00 root CARTESIAN left outer join - ├─TableReader_16(Build) 10000.00 root data:TableFullScan_15 - │ └─TableFullScan_15 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo - └─Projection_43(Probe) 1.00 root test.t2.c1, test.t2.c2 - └─IndexLookUp_42 1.00 root limit embedded(offset:0, count:1) - ├─Limit_41(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_39 1.00 cop[tikv] table:t2, index:c1(c1) range: decided by [eq(test.t1.c1, test.t2.c1)], keep order:true, stats:pseudo - └─TableRowIDScan_40(Probe) 1.00 cop[tikv] table:t2 keep order:false, stats:pseudo +Projection_13 10000.00 root eq(test.t1.c2, test.t2.c2)->Column#11 +└─Apply_15 10000.00 root CARTESIAN left outer join + ├─TableReader_17(Build) 10000.00 root data:TableFullScan_16 + │ └─TableFullScan_16 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─Projection_44(Probe) 1.00 root test.t2.c1, test.t2.c2 + └─IndexLookUp_43 1.00 root limit embedded(offset:0, count:1) + ├─Limit_42(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_40 1.00 cop[tikv] table:t2, index:c1(c1) range: decided by [eq(test.t1.c1, test.t2.c1)], keep order:true, stats:pseudo + └─TableRowIDScan_41(Probe) 1.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain select * from t1 order by c1 desc limit 1; id estRows task access object operator info Limit_10 1.00 root offset:0, count:1 @@ -222,83 +222,83 @@ StreamAgg_8 1.00 root funcs:count(1)->Column#5 set @@session.tidb_opt_insubq_to_join_and_agg=0; explain select sum(t1.c1 in (select c1 from t2)) from t1; id estRows task access object operator info -StreamAgg_9 1.00 root funcs:sum(Column#10)->Column#8 -└─Projection_20 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10 - └─HashJoin_19 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, test.t2.c1) - ├─IndexReader_18(Build) 10000.00 root index:IndexFullScan_17 - │ └─IndexFullScan_17 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo - └─TableReader_12(Probe) 10000.00 root data:TableFullScan_11 - └─TableFullScan_11 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +StreamAgg_10 1.00 root funcs:sum(Column#13)->Column#11 +└─Projection_21 10000.00 root cast(Column#10, decimal(65,0) BINARY)->Column#13 + └─HashJoin_20 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, test.t2.c1) + ├─IndexReader_19(Build) 10000.00 root index:IndexFullScan_18 + │ └─IndexFullScan_18 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo + └─TableReader_13(Probe) 10000.00 root data:TableFullScan_12 + └─TableFullScan_12 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select 1 in (select c2 from t2) from t1; id estRows task access object operator info -HashJoin_7 10000.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2.c2) -├─TableReader_13(Build) 10000.00 root data:TableFullScan_12 -│ └─TableFullScan_12 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─TableReader_9(Probe) 10000.00 root data:TableFullScan_8 - └─TableFullScan_8 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +HashJoin_8 10000.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2.c2) +├─TableReader_14(Build) 10000.00 root data:TableFullScan_13 +│ └─TableFullScan_13 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +└─TableReader_10(Probe) 10000.00 root data:TableFullScan_9 + └─TableFullScan_9 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select sum(6 in (select c2 from t2)) from t1; id estRows task access object operator info -StreamAgg_9 1.00 root funcs:sum(Column#10)->Column#8 -└─Projection_18 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10 - └─HashJoin_17 10000.00 root CARTESIAN left outer semi join, other cond:eq(6, test.t2.c2) - ├─TableReader_16(Build) 10000.00 root data:TableFullScan_15 - │ └─TableFullScan_15 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo - └─TableReader_12(Probe) 10000.00 root data:TableFullScan_11 - └─TableFullScan_11 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +StreamAgg_10 1.00 root funcs:sum(Column#13)->Column#11 +└─Projection_19 10000.00 root cast(Column#10, decimal(65,0) BINARY)->Column#13 + └─HashJoin_18 10000.00 root CARTESIAN left outer semi join, other cond:eq(6, test.t2.c2) + ├─TableReader_17(Build) 10000.00 root data:TableFullScan_16 + │ └─TableFullScan_16 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo + └─TableReader_13(Probe) 10000.00 root data:TableFullScan_12 + └─TableFullScan_12 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format="dot" select sum(t1.c1 in (select c1 from t2)) from t1; dot contents -digraph StreamAgg_9 { -subgraph cluster9{ +digraph StreamAgg_10 { +subgraph cluster10{ node [style=filled, color=lightgrey] color=black label = "root" -"StreamAgg_9" -> "Projection_20" -"Projection_20" -> "HashJoin_19" -"HashJoin_19" -> "TableReader_12" -"HashJoin_19" -> "IndexReader_18" +"StreamAgg_10" -> "Projection_21" +"Projection_21" -> "HashJoin_20" +"HashJoin_20" -> "TableReader_13" +"HashJoin_20" -> "IndexReader_19" } -subgraph cluster11{ +subgraph cluster12{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableFullScan_11" +"TableFullScan_12" } -subgraph cluster17{ +subgraph cluster18{ node [style=filled, color=lightgrey] color=black label = "cop" -"IndexFullScan_17" +"IndexFullScan_18" } -"TableReader_12" -> "TableFullScan_11" -"IndexReader_18" -> "IndexFullScan_17" +"TableReader_13" -> "TableFullScan_12" +"IndexReader_19" -> "IndexFullScan_18" } explain format="dot" select 1 in (select c2 from t2) from t1; dot contents -digraph HashJoin_7 { -subgraph cluster7{ +digraph HashJoin_8 { +subgraph cluster8{ node [style=filled, color=lightgrey] color=black label = "root" -"HashJoin_7" -> "TableReader_9" -"HashJoin_7" -> "TableReader_13" +"HashJoin_8" -> "TableReader_10" +"HashJoin_8" -> "TableReader_14" } -subgraph cluster8{ +subgraph cluster9{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableFullScan_8" +"TableFullScan_9" } -subgraph cluster12{ +subgraph cluster13{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableFullScan_12" +"TableFullScan_13" } -"TableReader_9" -> "TableFullScan_8" -"TableReader_13" -> "TableFullScan_12" +"TableReader_10" -> "TableFullScan_9" +"TableReader_14" -> "TableFullScan_13" } drop table if exists t1, t2, t3, t4; @@ -306,86 +306,86 @@ drop table if exists t; create table t(a int primary key, b int, c int, index idx(b)); explain select t.c in (select count(*) from t s ignore index(idx), t t1 where s.a = t.a and s.a = t1.a) from t; id estRows task access object operator info -Projection_11 10000.00 root Column#11 -└─Apply_13 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) - ├─TableReader_15(Build) 10000.00 root data:TableFullScan_14 - │ └─TableFullScan_14 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─StreamAgg_17(Probe) 1.00 root funcs:count(1)->Column#10 - └─MergeJoin_41 12.50 root inner join, left key:test.t.a, right key:test.t.a - ├─TableReader_36(Build) 1.00 root data:TableRangeScan_35 - │ └─TableRangeScan_35 1.00 cop[tikv] table:t1 range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo - └─TableReader_34(Probe) 1.00 root data:TableRangeScan_33 - └─TableRangeScan_33 1.00 cop[tikv] table:s range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo +Projection_14 10000.00 root Column#17 +└─Apply_16 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) + ├─TableReader_18(Build) 10000.00 root data:TableFullScan_17 + │ └─TableFullScan_17 10000.00 cop[tikv] table:t keep order:false, stats:pseudo + └─StreamAgg_20(Probe) 1.00 root funcs:count(1)->Column#16 + └─MergeJoin_44 12.50 root inner join, left key:test.t.a, right key:test.t.a + ├─TableReader_39(Build) 1.00 root data:TableRangeScan_38 + │ └─TableRangeScan_38 1.00 cop[tikv] table:t1 range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo + └─TableReader_37(Probe) 1.00 root data:TableRangeScan_36 + └─TableRangeScan_36 1.00 cop[tikv] table:s range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo explain select t.c in (select count(*) from t s use index(idx), t t1 where s.b = t.a and s.a = t1.a) from t; id estRows task access object operator info -Projection_11 10000.00 root Column#11 -└─Apply_13 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) - ├─TableReader_15(Build) 10000.00 root data:TableFullScan_14 - │ └─TableFullScan_14 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─StreamAgg_17(Probe) 1.00 root funcs:count(1)->Column#10 - └─IndexJoin_33 12.50 root inner join, inner:TableReader_32, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) - ├─IndexReader_26(Build) 10.00 root index:IndexRangeScan_25 - │ └─IndexRangeScan_25 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo - └─TableReader_32(Probe) 1.00 root data:TableRangeScan_31 - └─TableRangeScan_31 1.00 cop[tikv] table:t1 range: decided by [test.t.a], keep order:false, stats:pseudo +Projection_14 10000.00 root Column#17 +└─Apply_16 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) + ├─TableReader_18(Build) 10000.00 root data:TableFullScan_17 + │ └─TableFullScan_17 10000.00 cop[tikv] table:t keep order:false, stats:pseudo + └─StreamAgg_20(Probe) 1.00 root funcs:count(1)->Column#16 + └─IndexJoin_36 12.50 root inner join, inner:TableReader_35, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) + ├─IndexReader_29(Build) 10.00 root index:IndexRangeScan_28 + │ └─IndexRangeScan_28 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo + └─TableReader_35(Probe) 1.00 root data:TableRangeScan_34 + └─TableRangeScan_34 1.00 cop[tikv] table:t1 range: decided by [test.t.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 estRows task access object operator info -Projection_11 10000.00 root Column#11 -└─Apply_13 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) - ├─TableReader_15(Build) 10000.00 root data:TableFullScan_14 - │ └─TableFullScan_14 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─StreamAgg_17(Probe) 1.00 root funcs:count(1)->Column#10 - └─IndexJoin_35 12.49 root inner join, inner:TableReader_34, outer key:test.t.c, inner key:test.t.a, equal cond:eq(test.t.c, test.t.a) - ├─IndexLookUp_28(Build) 9.99 root - │ ├─IndexRangeScan_25(Build) 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo - │ └─Selection_27(Probe) 9.99 cop[tikv] not(isnull(test.t.c)) - │ └─TableRowIDScan_26 10.00 cop[tikv] table:s keep order:false, stats:pseudo - └─TableReader_34(Probe) 1.00 root data:TableRangeScan_33 - └─TableRangeScan_33 1.00 cop[tikv] table:t1 range: decided by [test.t.c], keep order:false, stats:pseudo +Projection_14 10000.00 root Column#17 +└─Apply_16 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) + ├─TableReader_18(Build) 10000.00 root data:TableFullScan_17 + │ └─TableFullScan_17 10000.00 cop[tikv] table:t keep order:false, stats:pseudo + └─StreamAgg_20(Probe) 1.00 root funcs:count(1)->Column#16 + └─IndexJoin_38 12.49 root inner join, inner:TableReader_37, outer key:test.t.c, inner key:test.t.a, equal cond:eq(test.t.c, test.t.a) + ├─IndexLookUp_31(Build) 9.99 root + │ ├─IndexRangeScan_28(Build) 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo + │ └─Selection_30(Probe) 9.99 cop[tikv] not(isnull(test.t.c)) + │ └─TableRowIDScan_29 10.00 cop[tikv] table:s keep order:false, stats:pseudo + └─TableReader_37(Probe) 1.00 root data:TableRangeScan_36 + └─TableRangeScan_36 1.00 cop[tikv] table:t1 range: decided by [test.t.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; id estRows task access object operator info -Projection_11 5.00 root Column#11 -└─Apply_13 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) - ├─TableReader_15(Build) 5.00 root data:TableFullScan_14 - │ └─TableFullScan_14 5.00 cop[tikv] table:t keep order:false - └─StreamAgg_17(Probe) 1.00 root funcs:count(1)->Column#10 - └─MergeJoin_49 2.40 root inner join, left key:test.t.a, right key:test.t.a - ├─TableReader_39(Build) 4.00 root data:Selection_38 - │ └─Selection_38 4.00 cop[tikv] eq(3, test.t.a) - │ └─TableFullScan_37 5.00 cop[tikv] table:t1 keep order:true - └─IndexReader_36(Probe) 2.40 root index:Selection_35 - └─Selection_35 2.40 cop[tikv] eq(3, test.t.a) - └─IndexRangeScan_34 3.00 cop[tikv] table:s, index:idx(b) range:[3,3], keep order:true +Projection_14 5.00 root Column#17 +└─Apply_16 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) + ├─TableReader_18(Build) 5.00 root data:TableFullScan_17 + │ └─TableFullScan_17 5.00 cop[tikv] table:t keep order:false + └─StreamAgg_20(Probe) 1.00 root funcs:count(1)->Column#16 + └─MergeJoin_52 2.40 root inner join, left key:test.t.a, right key:test.t.a + ├─TableReader_42(Build) 4.00 root data:Selection_41 + │ └─Selection_41 4.00 cop[tikv] eq(3, test.t.a) + │ └─TableFullScan_40 5.00 cop[tikv] table:t1 keep order:true + └─IndexReader_39(Probe) 2.40 root index:Selection_38 + └─Selection_38 2.40 cop[tikv] eq(3, test.t.a) + └─IndexRangeScan_37 3.00 cop[tikv] table:s, index:idx(b) range:[3,3], keep order:true explain select t.c in (select count(*) from t s left join t t1 on s.a = t1.a where 3 = t.a and s.b = 3) from t; id estRows task access object operator info -Projection_10 5.00 root Column#11 -└─Apply_12 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) - ├─TableReader_14(Build) 5.00 root data:TableFullScan_13 - │ └─TableFullScan_13 5.00 cop[tikv] table:t keep order:false - └─StreamAgg_16(Probe) 1.00 root funcs:count(1)->Column#10 - └─MergeJoin_42 2.40 root left outer join, left key:test.t.a, right key:test.t.a - ├─TableReader_32(Build) 4.00 root data:Selection_31 - │ └─Selection_31 4.00 cop[tikv] eq(3, test.t.a) - │ └─TableFullScan_30 5.00 cop[tikv] table:t1 keep order:true - └─IndexReader_29(Probe) 2.40 root index:Selection_28 - └─Selection_28 2.40 cop[tikv] eq(3, test.t.a) - └─IndexRangeScan_27 3.00 cop[tikv] table:s, index:idx(b) range:[3,3], keep order:true +Projection_13 5.00 root Column#17 +└─Apply_15 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) + ├─TableReader_17(Build) 5.00 root data:TableFullScan_16 + │ └─TableFullScan_16 5.00 cop[tikv] table:t keep order:false + └─StreamAgg_19(Probe) 1.00 root funcs:count(1)->Column#16 + └─MergeJoin_45 2.40 root left outer join, left key:test.t.a, right key:test.t.a + ├─TableReader_35(Build) 4.00 root data:Selection_34 + │ └─Selection_34 4.00 cop[tikv] eq(3, test.t.a) + │ └─TableFullScan_33 5.00 cop[tikv] table:t1 keep order:true + └─IndexReader_32(Probe) 2.40 root index:Selection_31 + └─Selection_31 2.40 cop[tikv] eq(3, test.t.a) + └─IndexRangeScan_30 3.00 cop[tikv] table:s, index:idx(b) range:[3,3], keep order:true explain select t.c in (select count(*) from t s right join t t1 on s.a = t1.a where 3 = t.a and t1.b = 3) from t; id estRows task access object operator info -Projection_10 5.00 root Column#11 -└─Apply_12 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) - ├─TableReader_14(Build) 5.00 root data:TableFullScan_13 - │ └─TableFullScan_13 5.00 cop[tikv] table:t keep order:false - └─StreamAgg_16(Probe) 1.00 root funcs:count(1)->Column#10 - └─MergeJoin_41 2.40 root right outer join, left key:test.t.a, right key:test.t.a - ├─TableReader_28(Build) 4.00 root data:Selection_27 - │ └─Selection_27 4.00 cop[tikv] eq(3, test.t.a) - │ └─TableFullScan_26 5.00 cop[tikv] table:s keep order:true - └─IndexReader_31(Probe) 2.40 root index:Selection_30 - └─Selection_30 2.40 cop[tikv] eq(3, test.t.a) - └─IndexRangeScan_29 3.00 cop[tikv] table:t1, index:idx(b) range:[3,3], keep order:true +Projection_13 5.00 root Column#17 +└─Apply_15 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) + ├─TableReader_17(Build) 5.00 root data:TableFullScan_16 + │ └─TableFullScan_16 5.00 cop[tikv] table:t keep order:false + └─StreamAgg_19(Probe) 1.00 root funcs:count(1)->Column#16 + └─MergeJoin_44 2.40 root right outer join, left key:test.t.a, right key:test.t.a + ├─TableReader_31(Build) 4.00 root data:Selection_30 + │ └─Selection_30 4.00 cop[tikv] eq(3, test.t.a) + │ └─TableFullScan_29 5.00 cop[tikv] table:s keep order:true + └─IndexReader_34(Probe) 2.40 root index:Selection_33 + └─Selection_33 2.40 cop[tikv] eq(3, test.t.a) + └─IndexRangeScan_32 3.00 cop[tikv] table:t1, index:idx(b) range:[3,3], keep order:true drop table if exists t; create table t(a int unsigned); explain select t.a = '123455' from t; @@ -580,20 +580,20 @@ HashJoin_9 2773.61 root inner join, equal:[eq(test.t.nb, test.t.nb)] └─TableFullScan_13 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo explain select ifnull(t.nc, 1) in (select count(*) from t s , t t1 where s.a = t.a and s.a = t1.a) from t; id estRows task access object operator info -Projection_12 10000.00 root Column#14 -└─Apply_14 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.nc, Column#13) - ├─TableReader_16(Build) 10000.00 root data:TableFullScan_15 - │ └─TableFullScan_15 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─HashAgg_17(Probe) 1.00 root funcs:count(Column#15)->Column#13 - └─HashJoin_18 9.99 root inner join, equal:[eq(test.t.a, test.t.a)] - ├─HashAgg_28(Build) 7.99 root group by:test.t.a, funcs:count(Column#16)->Column#15, funcs:firstrow(test.t.a)->test.t.a - │ └─TableReader_29 7.99 root data:HashAgg_23 - │ └─HashAgg_23 7.99 cop[tikv] group by:test.t.a, funcs:count(1)->Column#16 - │ └─Selection_27 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) - │ └─TableFullScan_26 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo - └─TableReader_22(Probe) 9.99 root data:Selection_21 - └─Selection_21 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) - └─TableFullScan_20 10000.00 cop[tikv] table:s keep order:false, stats:pseudo +Projection_15 10000.00 root Column#22 +└─Apply_17 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.nc, Column#21) + ├─TableReader_19(Build) 10000.00 root data:TableFullScan_18 + │ └─TableFullScan_18 10000.00 cop[tikv] table:t keep order:false, stats:pseudo + └─HashAgg_20(Probe) 1.00 root funcs:count(Column#23)->Column#21 + └─HashJoin_21 9.99 root inner join, equal:[eq(test.t.a, test.t.a)] + ├─HashAgg_31(Build) 7.99 root group by:test.t.a, funcs:count(Column#24)->Column#23, funcs:firstrow(test.t.a)->test.t.a + │ └─TableReader_32 7.99 root data:HashAgg_26 + │ └─HashAgg_26 7.99 cop[tikv] group by:test.t.a, funcs:count(1)->Column#24 + │ └─Selection_30 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) + │ └─TableFullScan_29 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader_25(Probe) 9.99 root data:Selection_24 + └─Selection_24 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) + └─TableFullScan_23 10000.00 cop[tikv] table:s keep order:false, stats:pseudo explain select * from t ta left outer join t tb on ta.nb = tb.nb and ta.a > 1 where ifnull(tb.a, 1) or tb.a is null; id estRows task access object operator info Selection_7 10000.00 root or(ifnull(test.t.a, 1), isnull(test.t.a)) @@ -613,20 +613,20 @@ HashJoin_7 8000.00 root right outer join, equal:[eq(test.t.nb, test.t.nb)] └─TableFullScan_12 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo explain select ifnull(t.a, 1) in (select count(*) from t s , t t1 where s.a = t.a and s.a = t1.a) from t; id estRows task access object operator info -Projection_12 10000.00 root Column#14 -└─Apply_14 10000.00 root CARTESIAN left outer semi join, other cond:eq(ifnull(test.t.a, 1), Column#13) - ├─TableReader_16(Build) 10000.00 root data:TableFullScan_15 - │ └─TableFullScan_15 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─HashAgg_17(Probe) 1.00 root funcs:count(Column#15)->Column#13 - └─HashJoin_18 9.99 root inner join, equal:[eq(test.t.a, test.t.a)] - ├─HashAgg_28(Build) 7.99 root group by:test.t.a, funcs:count(Column#16)->Column#15, funcs:firstrow(test.t.a)->test.t.a - │ └─TableReader_29 7.99 root data:HashAgg_23 - │ └─HashAgg_23 7.99 cop[tikv] group by:test.t.a, funcs:count(1)->Column#16 - │ └─Selection_27 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) - │ └─TableFullScan_26 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo - └─TableReader_22(Probe) 9.99 root data:Selection_21 - └─Selection_21 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) - └─TableFullScan_20 10000.00 cop[tikv] table:s keep order:false, stats:pseudo +Projection_15 10000.00 root Column#22 +└─Apply_17 10000.00 root CARTESIAN left outer semi join, other cond:eq(ifnull(test.t.a, 1), Column#21) + ├─TableReader_19(Build) 10000.00 root data:TableFullScan_18 + │ └─TableFullScan_18 10000.00 cop[tikv] table:t keep order:false, stats:pseudo + └─HashAgg_20(Probe) 1.00 root funcs:count(Column#23)->Column#21 + └─HashJoin_21 9.99 root inner join, equal:[eq(test.t.a, test.t.a)] + ├─HashAgg_31(Build) 7.99 root group by:test.t.a, funcs:count(Column#24)->Column#23, funcs:firstrow(test.t.a)->test.t.a + │ └─TableReader_32 7.99 root data:HashAgg_26 + │ └─HashAgg_26 7.99 cop[tikv] group by:test.t.a, funcs:count(1)->Column#24 + │ └─Selection_30 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) + │ └─TableFullScan_29 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo + └─TableReader_25(Probe) 9.99 root data:Selection_24 + └─Selection_24 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) + └─TableFullScan_23 10000.00 cop[tikv] table:s keep order:false, stats:pseudo drop table if exists t; create table t(a int); explain select * from t where _tidb_rowid = 0; @@ -787,15 +787,15 @@ drop table if exists t; create table t(a int, b int); explain select (select count(n.a) from t) from t n; id estRows task access object operator info -Projection_9 1.00 root Column#8 -└─Apply_11 1.00 root CARTESIAN left outer join - ├─StreamAgg_13(Build) 1.00 root funcs:count(test.t.a)->Column#7 - │ └─TableReader_17 10000.00 root data:TableFullScan_16 - │ └─TableFullScan_16 10000.00 cop[tikv] table:n keep order:false, stats:pseudo - └─MaxOneRow_18(Probe) 1.00 root - └─Projection_19 2.00 root Column#7 - └─TableReader_21 2.00 root data:TableFullScan_20 - └─TableFullScan_20 2.00 cop[tikv] table:t keep order:false, stats:pseudo +Projection_10 1.00 root Column#11 +└─Apply_12 1.00 root CARTESIAN left outer join + ├─StreamAgg_14(Build) 1.00 root funcs:count(test.t.a)->Column#7 + │ └─TableReader_18 10000.00 root data:TableFullScan_17 + │ └─TableFullScan_17 10000.00 cop[tikv] table:n keep order:false, stats:pseudo + └─MaxOneRow_19(Probe) 1.00 root + └─Projection_20 2.00 root Column#7 + └─TableReader_22 2.00 root data:TableFullScan_21 + └─TableFullScan_21 2.00 cop[tikv] table:t keep order:false, stats:pseudo explain select (select sum((select count(a)))) from t; id estRows task access object operator info Projection_23 1.00 root Column#7 diff --git a/cmd/explaintest/r/explain_easy_stats.result b/cmd/explaintest/r/explain_easy_stats.result index f401a70299640..e3b04a5090811 100644 --- a/cmd/explaintest/r/explain_easy_stats.result +++ b/cmd/explaintest/r/explain_easy_stats.result @@ -102,15 +102,15 @@ id estRows task access object operator info MemTableScan_4 10000.00 root table:COLUMNS explain select c2 = (select c2 from t2 where t1.c1 = t2.c1 order by c1 limit 1) from t1; id estRows task access object operator info -Projection_12 1999.00 root eq(test.t1.c2, test.t2.c2)->Column#8 -└─Apply_14 1999.00 root CARTESIAN left outer join - ├─TableReader_16(Build) 1999.00 root data:TableFullScan_15 - │ └─TableFullScan_15 1999.00 cop[tikv] table:t1 keep order:false - └─Projection_43(Probe) 1.00 root test.t2.c1, test.t2.c2 - └─IndexLookUp_42 1.00 root limit embedded(offset:0, count:1) - ├─Limit_41(Build) 1.00 cop[tikv] offset:0, count:1 - │ └─IndexRangeScan_39 1.25 cop[tikv] table:t2, index:c1(c1) range: decided by [eq(test.t1.c1, test.t2.c1)], keep order:true - └─TableRowIDScan_40(Probe) 1.00 cop[tikv] table:t2 keep order:false, stats:pseudo +Projection_13 1999.00 root eq(test.t1.c2, test.t2.c2)->Column#11 +└─Apply_15 1999.00 root CARTESIAN left outer join + ├─TableReader_17(Build) 1999.00 root data:TableFullScan_16 + │ └─TableFullScan_16 1999.00 cop[tikv] table:t1 keep order:false + └─Projection_44(Probe) 1.00 root test.t2.c1, test.t2.c2 + └─IndexLookUp_43 1.00 root limit embedded(offset:0, count:1) + ├─Limit_42(Build) 1.00 cop[tikv] offset:0, count:1 + │ └─IndexRangeScan_40 1.25 cop[tikv] table:t2, index:c1(c1) range: decided by [eq(test.t1.c1, test.t2.c1)], keep order:true + └─TableRowIDScan_41(Probe) 1.00 cop[tikv] table:t2 keep order:false, stats:pseudo explain select * from t1 order by c1 desc limit 1; id estRows task access object operator info Limit_10 1.00 root offset:0, count:1 @@ -120,36 +120,36 @@ Limit_10 1.00 root offset:0, count:1 set @@session.tidb_opt_insubq_to_join_and_agg=0; explain select 1 in (select c2 from t2) from t1; id estRows task access object operator info -HashJoin_7 1999.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2.c2) -├─TableReader_13(Build) 1985.00 root data:TableFullScan_12 -│ └─TableFullScan_12 1985.00 cop[tikv] table:t2 keep order:false -└─TableReader_9(Probe) 1999.00 root data:TableFullScan_8 - └─TableFullScan_8 1999.00 cop[tikv] table:t1 keep order:false +HashJoin_8 1999.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2.c2) +├─TableReader_14(Build) 1985.00 root data:TableFullScan_13 +│ └─TableFullScan_13 1985.00 cop[tikv] table:t2 keep order:false +└─TableReader_10(Probe) 1999.00 root data:TableFullScan_9 + └─TableFullScan_9 1999.00 cop[tikv] table:t1 keep order:false explain format="dot" select 1 in (select c2 from t2) from t1; dot contents -digraph HashJoin_7 { -subgraph cluster7{ +digraph HashJoin_8 { +subgraph cluster8{ node [style=filled, color=lightgrey] color=black label = "root" -"HashJoin_7" -> "TableReader_9" -"HashJoin_7" -> "TableReader_13" +"HashJoin_8" -> "TableReader_10" +"HashJoin_8" -> "TableReader_14" } -subgraph cluster8{ +subgraph cluster9{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableFullScan_8" +"TableFullScan_9" } -subgraph cluster12{ +subgraph cluster13{ node [style=filled, color=lightgrey] color=black label = "cop" -"TableFullScan_12" +"TableFullScan_13" } -"TableReader_9" -> "TableFullScan_8" -"TableReader_13" -> "TableFullScan_12" +"TableReader_10" -> "TableFullScan_9" +"TableReader_14" -> "TableFullScan_13" } explain select * from index_prune WHERE a = 1010010404050976781 AND b = 26467085526790 LIMIT 1; diff --git a/cmd/explaintest/r/select.result b/cmd/explaintest/r/select.result index d92b4e9285493..e674c6481f91c 100644 --- a/cmd/explaintest/r/select.result +++ b/cmd/explaintest/r/select.result @@ -382,53 +382,53 @@ 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 estRows task access object operator info -Projection_8 10000.00 root and(or(or(gt(Column#8, 1), ne(test.t.a, Column#7)), if(ne(Column#9, 0), , 0)), and(ne(Column#10, 0), if(isnull(test.t.a), , 1)))->Column#11 -└─HashJoin_9 10000.00 root CARTESIAN inner join - ├─StreamAgg_14(Build) 1.00 root funcs:max(Column#13)->Column#7, funcs:count(distinct Column#14)->Column#8, funcs:sum(Column#15)->Column#9, funcs:count(1)->Column#10 - │ └─Projection_19 10000.00 root test.t.a, test.t.a, cast(isnull(test.t.a), decimal(22,0) BINARY)->Column#15 - │ └─TableReader_18 10000.00 root data:TableFullScan_17 - │ └─TableFullScan_17 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo - └─TableReader_12(Probe) 10000.00 root data:TableFullScan_11 - └─TableFullScan_11 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection_9 10000.00 root and(or(or(gt(Column#11, 1), ne(test.t.a, Column#10)), if(ne(Column#12, 0), , 0)), and(ne(Column#13, 0), if(isnull(test.t.a), , 1)))->Column#14 +└─HashJoin_10 10000.00 root CARTESIAN inner join + ├─StreamAgg_15(Build) 1.00 root funcs:max(Column#16)->Column#10, funcs:count(distinct Column#17)->Column#11, funcs:sum(Column#18)->Column#12, funcs:count(1)->Column#13 + │ └─Projection_20 10000.00 root test.t.a, test.t.a, cast(isnull(test.t.a), decimal(22,0) BINARY)->Column#18 + │ └─TableReader_19 10000.00 root data:TableFullScan_18 + │ └─TableFullScan_18 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo + └─TableReader_13(Probe) 10000.00 root data:TableFullScan_12 + └─TableFullScan_12 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select a = all (select a from t t2) from t t1; id estRows task access object operator info -Projection_8 10000.00 root or(and(and(le(Column#8, 1), eq(test.t.a, Column#7)), if(ne(Column#9, 0), , 1)), or(eq(Column#10, 0), if(isnull(test.t.a), , 0)))->Column#11 -└─HashJoin_9 10000.00 root CARTESIAN inner join - ├─StreamAgg_14(Build) 1.00 root funcs:firstrow(Column#13)->Column#7, funcs:count(distinct Column#14)->Column#8, funcs:sum(Column#15)->Column#9, funcs:count(1)->Column#10 - │ └─Projection_19 10000.00 root test.t.a, test.t.a, cast(isnull(test.t.a), decimal(22,0) BINARY)->Column#15 - │ └─TableReader_18 10000.00 root data:TableFullScan_17 - │ └─TableFullScan_17 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo - └─TableReader_12(Probe) 10000.00 root data:TableFullScan_11 - └─TableFullScan_11 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +Projection_9 10000.00 root or(and(and(le(Column#11, 1), eq(test.t.a, Column#10)), if(ne(Column#12, 0), , 1)), or(eq(Column#13, 0), if(isnull(test.t.a), , 0)))->Column#14 +└─HashJoin_10 10000.00 root CARTESIAN inner join + ├─StreamAgg_15(Build) 1.00 root funcs:firstrow(Column#16)->Column#10, funcs:count(distinct Column#17)->Column#11, funcs:sum(Column#18)->Column#12, funcs:count(1)->Column#13 + │ └─Projection_20 10000.00 root test.t.a, test.t.a, cast(isnull(test.t.a), decimal(22,0) BINARY)->Column#18 + │ └─TableReader_19 10000.00 root data:TableFullScan_18 + │ └─TableFullScan_18 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo + └─TableReader_13(Probe) 10000.00 root data:TableFullScan_12 + └─TableFullScan_12 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo drop table if exists t; create table t(a int, b int); drop table if exists s; create table s(a varchar(20), b varchar(20)); explain select a in (select a from s where s.b = t.b) from t; id estRows task access object operator info -HashJoin_10 10000.00 root left outer semi join, equal:[eq(Column#8, Column#9)], other cond:eq(cast(test.t.a), cast(test.s.a)) -├─Projection_14(Build) 10000.00 root test.s.a, cast(test.s.b, double BINARY)->Column#9 -│ └─TableReader_16 10000.00 root data:TableFullScan_15 -│ └─TableFullScan_15 10000.00 cop[tikv] table:s keep order:false, stats:pseudo -└─Projection_11(Probe) 10000.00 root test.t.a, cast(test.t.b, double BINARY)->Column#8 - └─TableReader_13 10000.00 root data:TableFullScan_12 - └─TableFullScan_12 10000.00 cop[tikv] table:t keep order:false, stats:pseudo +HashJoin_11 10000.00 root left outer semi join, equal:[eq(Column#11, Column#12)], other cond:eq(cast(test.t.a), cast(test.s.a)) +├─Projection_15(Build) 10000.00 root test.s.a, cast(test.s.b, double BINARY)->Column#12 +│ └─TableReader_17 10000.00 root data:TableFullScan_16 +│ └─TableFullScan_16 10000.00 cop[tikv] table:s keep order:false, stats:pseudo +└─Projection_12(Probe) 10000.00 root test.t.a, cast(test.t.b, double BINARY)->Column#11 + └─TableReader_14 10000.00 root data:TableFullScan_13 + └─TableFullScan_13 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain select a in (select a+b from t t2 where t2.b = t1.b) from t t1; id estRows task access object operator info -HashJoin_8 10000.00 root left outer semi join, equal:[eq(test.t.b, test.t.b)], other cond:eq(test.t.a, plus(test.t.a, test.t.b)) -├─TableReader_12(Build) 10000.00 root data:TableFullScan_11 -│ └─TableFullScan_11 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─TableReader_10(Probe) 10000.00 root data:TableFullScan_9 - └─TableFullScan_9 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +HashJoin_9 10000.00 root left outer semi join, equal:[eq(test.t.b, test.t.b)], other cond:eq(test.t.a, plus(test.t.a, test.t.b)) +├─TableReader_13(Build) 10000.00 root data:TableFullScan_12 +│ └─TableFullScan_12 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +└─TableReader_11(Probe) 10000.00 root data:TableFullScan_10 + └─TableFullScan_10 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo drop table t; 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 estRows task access object operator info -HashJoin_8 10000.00 root left outer semi join, equal:[eq(test.t.b, test.t.b) eq(test.t.a, test.t.a)] -├─TableReader_12(Build) 10000.00 root data:TableFullScan_11 -│ └─TableFullScan_11 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo -└─TableReader_10(Probe) 10000.00 root data:TableFullScan_9 - └─TableFullScan_9 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo +HashJoin_9 10000.00 root left outer semi join, equal:[eq(test.t.b, test.t.b) eq(test.t.a, test.t.a)] +├─TableReader_13(Build) 10000.00 root data:TableFullScan_12 +│ └─TableFullScan_12 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo +└─TableReader_11(Probe) 10000.00 root data:TableFullScan_10 + └─TableFullScan_10 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain select 1 from (select sleep(1)) t; id estRows task access object operator info Projection_4 1.00 root 1->Column#2 diff --git a/cmd/explaintest/r/subquery.result b/cmd/explaintest/r/subquery.result index a75ef252a2b9a..0216155cf0e9f 100644 --- a/cmd/explaintest/r/subquery.result +++ b/cmd/explaintest/r/subquery.result @@ -17,16 +17,16 @@ insert into t values(1,1,1,1),(2,2,2,2),(3,2,2,2),(4,2,2,2),(5,2,2,2); analyze table t; explain select t.c in (select count(*) from t s use index(idx), t t1 where s.b = 1 and s.c = 1 and s.d = t.a and s.a = t1.a) from t; id estRows task access object operator info -Projection_11 5.00 root Column#14 -└─Apply_13 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) - ├─TableReader_15(Build) 5.00 root data:TableFullScan_14 - │ └─TableFullScan_14 5.00 cop[tikv] table:t keep order:false - └─StreamAgg_19(Probe) 1.00 root funcs:count(1)->Column#13 - └─IndexJoin_22 0.50 root inner join, inner:TableReader_21, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) - ├─IndexReader_28(Build) 1.00 root index:IndexRangeScan_27 - │ └─IndexRangeScan_27 1.00 cop[tikv] table:s, index:idx(b, c, d) range: decided by [eq(test.t.b, 1) eq(test.t.c, 1) eq(test.t.d, test.t.a)], keep order:false - └─TableReader_21(Probe) 1.00 root data:TableRangeScan_20 - └─TableRangeScan_20 1.00 cop[tikv] table:t1 range: decided by [test.t.a], keep order:false +Projection_14 5.00 root Column#22 +└─Apply_16 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#21) + ├─TableReader_18(Build) 5.00 root data:TableFullScan_17 + │ └─TableFullScan_17 5.00 cop[tikv] table:t keep order:false + └─StreamAgg_22(Probe) 1.00 root funcs:count(1)->Column#21 + └─IndexJoin_25 0.50 root inner join, inner:TableReader_24, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) + ├─IndexReader_31(Build) 1.00 root index:IndexRangeScan_30 + │ └─IndexRangeScan_30 1.00 cop[tikv] table:s, index:idx(b, c, d) range: decided by [eq(test.t.b, 1) eq(test.t.c, 1) eq(test.t.d, test.t.a)], keep order:false + └─TableReader_24(Probe) 1.00 root data:TableRangeScan_23 + └─TableRangeScan_23 1.00 cop[tikv] table:t1 range: decided by [test.t.a], keep order:false drop table if exists t; create table t(a int, b int, c int); explain select a from t t1 where t1.a = (select max(t2.a) from t t2 where t1.b=t2.b and t1.c=t2.b); diff --git a/cmd/explaintest/r/tpch.result b/cmd/explaintest/r/tpch.result index ebf6286a16ac0..26330c4040649 100644 --- a/cmd/explaintest/r/tpch.result +++ b/cmd/explaintest/r/tpch.result @@ -711,20 +711,20 @@ and n_name = 'MOZAMBIQUE' order by value desc; id estRows task access object operator info -Projection_49 1304801.67 root tpch.partsupp.ps_partkey, Column#35 -└─Sort_50 1304801.67 root Column#35:desc - └─Selection_52 1304801.67 root gt(Column#35, NULL) - └─HashAgg_53 1631002.09 root group by:Column#44, funcs:sum(Column#42)->Column#35, funcs:firstrow(Column#43)->tpch.partsupp.ps_partkey - └─Projection_73 1631002.09 root mul(tpch.partsupp.ps_supplycost, cast(tpch.partsupp.ps_availqty, decimal(20,0) BINARY))->Column#42, tpch.partsupp.ps_partkey, tpch.partsupp.ps_partkey - └─HashJoin_56 1631002.09 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] - ├─HashJoin_64(Build) 20000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] - │ ├─TableReader_69(Build) 1.00 root data:Selection_68 - │ │ └─Selection_68 1.00 cop[tikv] eq(tpch.nation.n_name, "MOZAMBIQUE") - │ │ └─TableFullScan_67 25.00 cop[tikv] table:nation keep order:false - │ └─TableReader_66(Probe) 500000.00 root data:TableFullScan_65 - │ └─TableFullScan_65 500000.00 cop[tikv] table:supplier keep order:false - └─TableReader_71(Probe) 40000000.00 root data:TableFullScan_70 - └─TableFullScan_70 40000000.00 cop[tikv] table:partsupp keep order:false +Projection_54 1304801.67 root tpch.partsupp.ps_partkey, Column#35 +└─Sort_55 1304801.67 root Column#35:desc + └─Selection_57 1304801.67 root gt(Column#35, NULL) + └─HashAgg_58 1631002.09 root group by:Column#61, funcs:sum(Column#59)->Column#35, funcs:firstrow(Column#60)->tpch.partsupp.ps_partkey + └─Projection_78 1631002.09 root mul(tpch.partsupp.ps_supplycost, cast(tpch.partsupp.ps_availqty, decimal(20,0) BINARY))->Column#59, tpch.partsupp.ps_partkey, tpch.partsupp.ps_partkey + └─HashJoin_61 1631002.09 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] + ├─HashJoin_69(Build) 20000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] + │ ├─TableReader_74(Build) 1.00 root data:Selection_73 + │ │ └─Selection_73 1.00 cop[tikv] eq(tpch.nation.n_name, "MOZAMBIQUE") + │ │ └─TableFullScan_72 25.00 cop[tikv] table:nation keep order:false + │ └─TableReader_71(Probe) 500000.00 root data:TableFullScan_70 + │ └─TableFullScan_70 500000.00 cop[tikv] table:supplier keep order:false + └─TableReader_76(Probe) 40000000.00 root data:TableFullScan_75 + └─TableFullScan_75 40000000.00 cop[tikv] table:partsupp keep order:false /* Q12 Shipping Modes and Order Priority Query This query determines whether selecting less expensive modes of shipping is negatively affecting the critical-priority diff --git a/executor/merge_join_test.go b/executor/merge_join_test.go index e4f2b73573eee..55eb16620e7e0 100644 --- a/executor/merge_join_test.go +++ b/executor/merge_join_test.go @@ -393,12 +393,12 @@ func (s *testSuite2) TestMergeJoin(c *C) { tk.MustExec("create table s(a int, b int)") tk.MustExec("insert into s values(1,1)") tk.MustQuery("explain select /*+ TIDB_SMJ(t, s) */ a in (select a from s where s.b >= t.b) from t").Check(testkit.Rows( - "Projection_7 10000.00 root Column#7", - "└─MergeJoin_8 10000.00 root left outer semi join, other cond:eq(test.t.a, test.s.a), ge(test.s.b, test.t.b)", - " ├─TableReader_12(Build) 10000.00 root data:TableFullScan_11", - " │ └─TableFullScan_11 10000.00 cop[tikv] table:s keep order:false, stats:pseudo", - " └─TableReader_10(Probe) 10000.00 root data:TableFullScan_9", - " └─TableFullScan_9 10000.00 cop[tikv] table:t keep order:false, stats:pseudo", + "Projection_8 10000.00 root Column#10", + "└─MergeJoin_9 10000.00 root left outer semi join, other cond:eq(test.t.a, test.s.a), ge(test.s.b, test.t.b)", + " ├─TableReader_13(Build) 10000.00 root data:TableFullScan_12", + " │ └─TableFullScan_12 10000.00 cop[tikv] table:s keep order:false, stats:pseudo", + " └─TableReader_11(Probe) 10000.00 root data:TableFullScan_10", + " └─TableFullScan_10 10000.00 cop[tikv] table:t keep order:false, stats:pseudo", )) tk.MustQuery("select /*+ TIDB_SMJ(t, s) */ a in (select a from s where s.b >= t.b) from t").Check(testkit.Rows( "1", diff --git a/executor/testdata/agg_suite_out.json b/executor/testdata/agg_suite_out.json index 6c71b55a30888..6e865514fa124 100644 --- a/executor/testdata/agg_suite_out.json +++ b/executor/testdata/agg_suite_out.json @@ -49,32 +49,32 @@ "Name": "TestIssue12759HashAggCalledByApply", "Cases": [ [ - "Projection_28 1.00 root Column#9, Column#10, Column#11, Column#12", - "└─Apply_30 1.00 root CARTESIAN left outer join", - " ├─Apply_32(Build) 1.00 root CARTESIAN left outer join", - " │ ├─Apply_34(Build) 1.00 root CARTESIAN left outer join", - " │ │ ├─HashAgg_35(Build) 1.00 root funcs:sum(Column#22)->Column#9, funcs:firstrow(Column#23)->test.test.a", - " │ │ │ └─Projection_71 10000.00 root cast(test.test.a, decimal(32,0) BINARY)->Column#22, test.test.a", - " │ │ │ └─TableReader_37 10000.00 root data:TableFullScan_36", - " │ │ │ └─TableFullScan_36 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo", - " │ │ └─Projection_38(Probe) 1.00 root ->Column#10", - " │ │ └─Limit_39 1.00 root offset:0, count:1", - " │ │ └─TableReader_45 1.00 root data:Limit_44", - " │ │ └─Limit_44 1.00 cop[tikv] offset:0, count:1", - " │ │ └─Selection_43 1.00 cop[tikv] eq(test.test.a, test.test.a)", - " │ │ └─TableFullScan_42 1000.00 cop[tikv] table:test keep order:false, stats:pseudo", - " │ └─Projection_49(Probe) 1.00 root ->Column#11", - " │ └─Limit_50 1.00 root offset:0, count:1", - " │ └─TableReader_56 1.00 root data:Limit_55", - " │ └─Limit_55 1.00 cop[tikv] offset:0, count:1", - " │ └─Selection_54 1.00 cop[tikv] eq(test.test.a, test.test.a)", - " │ └─TableFullScan_53 1000.00 cop[tikv] table:test keep order:false, stats:pseudo", - " └─Projection_60(Probe) 1.00 root ->Column#12", - " └─Limit_61 1.00 root offset:0, count:1", - " └─TableReader_67 1.00 root data:Limit_66", - " └─Limit_66 1.00 cop[tikv] offset:0, count:1", - " └─Selection_65 1.00 cop[tikv] eq(test.test.a, test.test.a)", - " └─TableFullScan_64 1000.00 cop[tikv] table:test keep order:false, stats:pseudo" + "Projection_31 1.00 root Column#9, Column#12, Column#15, Column#18", + "└─Apply_33 1.00 root CARTESIAN left outer join", + " ├─Apply_35(Build) 1.00 root CARTESIAN left outer join", + " │ ├─Apply_37(Build) 1.00 root CARTESIAN left outer join", + " │ │ ├─HashAgg_38(Build) 1.00 root funcs:sum(Column#28)->Column#9, funcs:firstrow(Column#29)->test.test.a", + " │ │ │ └─Projection_74 10000.00 root cast(test.test.a, decimal(32,0) BINARY)->Column#28, test.test.a", + " │ │ │ └─TableReader_40 10000.00 root data:TableFullScan_39", + " │ │ │ └─TableFullScan_39 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo", + " │ │ └─Projection_41(Probe) 1.00 root ->Column#12", + " │ │ └─Limit_42 1.00 root offset:0, count:1", + " │ │ └─TableReader_48 1.00 root data:Limit_47", + " │ │ └─Limit_47 1.00 cop[tikv] offset:0, count:1", + " │ │ └─Selection_46 1.00 cop[tikv] eq(test.test.a, test.test.a)", + " │ │ └─TableFullScan_45 1000.00 cop[tikv] table:test keep order:false, stats:pseudo", + " │ └─Projection_52(Probe) 1.00 root ->Column#15", + " │ └─Limit_53 1.00 root offset:0, count:1", + " │ └─TableReader_59 1.00 root data:Limit_58", + " │ └─Limit_58 1.00 cop[tikv] offset:0, count:1", + " │ └─Selection_57 1.00 cop[tikv] eq(test.test.a, test.test.a)", + " │ └─TableFullScan_56 1000.00 cop[tikv] table:test keep order:false, stats:pseudo", + " └─Projection_63(Probe) 1.00 root ->Column#18", + " └─Limit_64 1.00 root offset:0, count:1", + " └─TableReader_70 1.00 root data:Limit_69", + " └─Limit_69 1.00 cop[tikv] offset:0, count:1", + " └─Selection_68 1.00 cop[tikv] eq(test.test.a, test.test.a)", + " └─TableFullScan_67 1000.00 cop[tikv] table:test keep order:false, stats:pseudo" ] ] } diff --git a/executor/testdata/executor_suite_out.json b/executor/testdata/executor_suite_out.json index bb635bc2951f6..891645f0ae5ab 100644 --- a/executor/testdata/executor_suite_out.json +++ b/executor/testdata/executor_suite_out.json @@ -77,30 +77,28 @@ { "SQL": "select t1.c1, t2.c1 from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL", "Plan": [ - "MergeJoin_8 0.00 root inner join, left key:test.t.c1, right key:test.t.c1", - "├─TableDual_24(Build) 0.00 root rows:0", - "└─TableDual_23(Probe) 0.00 root rows:0" + "MergeJoin_8 0.00 root inner join, left key:test.t.c1, right key:test.t.c1", + "├─TableDual_24(Build) 0.00 root rows:0", + "└─TableDual_23(Probe) 0.00 root rows:0" ], - "Res": [ - ] + "Res": null }, { "SQL": "select * from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL", "Plan": [ - "MergeJoin_8 0.00 root inner join, left key:test.t.c1, right key:test.t.c1", - "├─TableDual_26(Build) 0.00 root rows:0", - "└─TableDual_25(Probe) 0.00 root rows:0" + "MergeJoin_8 0.00 root inner join, left key:test.t.c1, right key:test.t.c1", + "├─TableDual_26(Build) 0.00 root rows:0", + "└─TableDual_25(Probe) 0.00 root rows:0" ], - "Res": [ - ] + "Res": null }, { "SQL": "select count(*) from t as t1 inner join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL", "Plan": [ - "StreamAgg_10 1.00 root funcs:count(1)->Column#7", - "└─MergeJoin_11 0.00 root inner join, left key:test.t.c1, right key:test.t.c1", - " ├─TableDual_27(Build) 0.00 root rows:0", - " └─TableDual_26(Probe) 0.00 root rows:0" + "StreamAgg_10 1.00 root funcs:count(1)->Column#7", + "└─MergeJoin_11 0.00 root inner join, left key:test.t.c1, right key:test.t.c1", + " ├─TableDual_27(Build) 0.00 root rows:0", + " └─TableDual_26(Probe) 0.00 root rows:0" ], "Res": [ "0" @@ -109,30 +107,28 @@ { "SQL": "select t1.c1, t2.c1 from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL", "Plan": [ - "MergeJoin_7 0.00 root left outer join, left key:test.t.c1, right key:test.t.c1", - "├─TableDual_17(Build) 0.00 root rows:0", - "└─TableDual_16(Probe) 0.00 root rows:0" + "MergeJoin_7 0.00 root left outer join, left key:test.t.c1, right key:test.t.c1", + "├─TableDual_17(Build) 0.00 root rows:0", + "└─TableDual_16(Probe) 0.00 root rows:0" ], - "Res": [ - ] + "Res": null }, { "SQL": "select * from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL", "Plan": [ - "MergeJoin_7 0.00 root left outer join, left key:test.t.c1, right key:test.t.c1", - "├─TableDual_18(Build) 0.00 root rows:0", - "└─TableDual_17(Probe) 0.00 root rows:0" + "MergeJoin_7 0.00 root left outer join, left key:test.t.c1, right key:test.t.c1", + "├─TableDual_18(Build) 0.00 root rows:0", + "└─TableDual_17(Probe) 0.00 root rows:0" ], - "Res": [ - ] + "Res": null }, { "SQL": "select count(*) from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 != NULL", "Plan": [ - "StreamAgg_9 1.00 root funcs:count(1)->Column#7", - "└─MergeJoin_10 0.00 root left outer join, left key:test.t.c1, right key:test.t.c1", - " ├─TableDual_20(Build) 0.00 root rows:0", - " └─TableDual_19(Probe) 0.00 root rows:0" + "StreamAgg_9 1.00 root funcs:count(1)->Column#7", + "└─MergeJoin_10 0.00 root left outer join, left key:test.t.c1, right key:test.t.c1", + " ├─TableDual_20(Build) 0.00 root rows:0", + " └─TableDual_19(Probe) 0.00 root rows:0" ], "Res": [ "0" @@ -141,13 +137,13 @@ { "SQL": "select * from t as t1 left join t as t2 on t1.c1 = t2.c1 where t1.c1 is not NULL", "Plan": [ - "HashJoin_15 12487.50 root left outer join, equal:[eq(test.t.c1, test.t.c1)]", - "├─TableReader_33(Build) 9990.00 root data:Selection_32", - "│ └─Selection_32 9990.00 cop[tikv] not(isnull(test.t.c1))", - "│ └─TableFullScan_31 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - "└─TableReader_27(Probe) 9990.00 root data:Selection_26", - " └─Selection_26 9990.00 cop[tikv] not(isnull(test.t.c1))", - " └─TableFullScan_25 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + "HashJoin_15 12487.50 root left outer join, equal:[eq(test.t.c1, test.t.c1)]", + "├─TableReader_33(Build) 9990.00 root data:Selection_32", + "│ └─Selection_32 9990.00 cop[tikv] not(isnull(test.t.c1))", + "│ └─TableFullScan_31 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + "└─TableReader_27(Probe) 9990.00 root data:Selection_26", + " └─Selection_26 9990.00 cop[tikv] not(isnull(test.t.c1))", + " └─TableFullScan_25 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" ], "Res": [ "2001 1 2001 1" diff --git a/planner/cascades/testdata/integration_suite_out.json b/planner/cascades/testdata/integration_suite_out.json index af003e8e6bf7f..61b6114e1a44e 100644 --- a/planner/cascades/testdata/integration_suite_out.json +++ b/planner/cascades/testdata/integration_suite_out.json @@ -997,17 +997,17 @@ { "SQL": "select a = (select a from t2 where t1.b = t2.b order by a limit 1) from t1", "Plan": [ - "Projection_18 10000.00 root eq(test.t1.a, test.t2.a)->Column#5", - "└─Apply_20 10000.00 root CARTESIAN left outer join", - " ├─TableReader_21(Build) 10000.00 root data:TableFullScan_22", - " │ └─TableFullScan_22 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─MaxOneRow_23(Probe) 1.00 root ", - " └─Projection_24 1.00 root test.t2.a", - " └─Limit_26 1.00 root offset:0, count:1", - " └─TableReader_34 1.00 root data:Limit_35", - " └─Limit_35 1.00 cop[tikv] offset:0, count:1", - " └─Selection_32 1.00 cop[tikv] eq(test.t1.b, test.t2.b)", - " └─TableFullScan_33 1.00 cop[tikv] table:t2 keep order:true, stats:pseudo" + "Projection_19 10000.00 root eq(test.t1.a, test.t2.a)->Column#7", + "└─Apply_21 10000.00 root CARTESIAN left outer join", + " ├─TableReader_22(Build) 10000.00 root data:TableFullScan_23", + " │ └─TableFullScan_23 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─MaxOneRow_24(Probe) 1.00 root ", + " └─Projection_25 1.00 root test.t2.a", + " └─Limit_27 1.00 root offset:0, count:1", + " └─TableReader_35 1.00 root data:Limit_36", + " └─Limit_36 1.00 cop[tikv] offset:0, count:1", + " └─Selection_33 1.00 cop[tikv] eq(test.t1.b, test.t2.b)", + " └─TableFullScan_34 1.00 cop[tikv] table:t2 keep order:true, stats:pseudo" ], "Result": [ "1", @@ -1019,25 +1019,25 @@ { "SQL": "select sum(a), (select t1.a from t1 where t1.a = t2.a limit 1), (select t1.b from t1 where t1.b = t2.b limit 1) from t2", "Plan": [ - "Projection_28 1.00 root Column#7, test.t1.a, test.t1.b", - "└─Apply_30 1.00 root CARTESIAN left outer join", - " ├─Apply_32(Build) 1.00 root CARTESIAN left outer join", - " │ ├─HashAgg_37(Build) 1.00 root funcs:sum(Column#8)->Column#7, funcs:firstrow(Column#9)->test.t2.a, funcs:firstrow(Column#10)->test.t2.b", - " │ │ └─TableReader_38 1.00 root data:HashAgg_39", - " │ │ └─HashAgg_39 1.00 cop[tikv] funcs:sum(test.t2.a)->Column#8, funcs:firstrow(test.t2.a)->Column#9, funcs:firstrow(test.t2.b)->Column#10", - " │ │ └─TableFullScan_35 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - " │ └─MaxOneRow_40(Probe) 1.00 root ", - " │ └─Limit_41 1.00 root offset:0, count:1", - " │ └─TableReader_42 1.00 root data:Limit_43", - " │ └─Limit_43 1.00 cop[tikv] offset:0, count:1", - " │ └─Selection_44 1.00 cop[tikv] eq(test.t1.a, test.t2.a)", - " │ └─TableFullScan_45 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo", - " └─MaxOneRow_46(Probe) 1.00 root ", - " └─Limit_47 1.00 root offset:0, count:1", - " └─TableReader_48 1.00 root data:Limit_49", - " └─Limit_49 1.00 cop[tikv] offset:0, count:1", - " └─Selection_50 1.00 cop[tikv] eq(test.t1.b, test.t2.b)", - " └─TableFullScan_51 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + "Projection_30 1.00 root Column#7, test.t1.a, test.t1.b", + "└─Apply_32 1.00 root CARTESIAN left outer join", + " ├─Apply_34(Build) 1.00 root CARTESIAN left outer join", + " │ ├─HashAgg_39(Build) 1.00 root funcs:sum(Column#12)->Column#7, funcs:firstrow(Column#13)->test.t2.a, funcs:firstrow(Column#14)->test.t2.b", + " │ │ └─TableReader_40 1.00 root data:HashAgg_41", + " │ │ └─HashAgg_41 1.00 cop[tikv] funcs:sum(test.t2.a)->Column#12, funcs:firstrow(test.t2.a)->Column#13, funcs:firstrow(test.t2.b)->Column#14", + " │ │ └─TableFullScan_37 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " │ └─MaxOneRow_42(Probe) 1.00 root ", + " │ └─Limit_43 1.00 root offset:0, count:1", + " │ └─TableReader_44 1.00 root data:Limit_45", + " │ └─Limit_45 1.00 cop[tikv] offset:0, count:1", + " │ └─Selection_46 1.00 cop[tikv] eq(test.t1.a, test.t2.a)", + " │ └─TableFullScan_47 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─MaxOneRow_48(Probe) 1.00 root ", + " └─Limit_49 1.00 root offset:0, count:1", + " └─TableReader_50 1.00 root data:Limit_51", + " └─Limit_51 1.00 cop[tikv] offset:0, count:1", + " └─Selection_52 1.00 cop[tikv] eq(test.t1.b, test.t2.b)", + " └─TableFullScan_53 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo" ], "Result": [ "6 1 11" @@ -1240,12 +1240,12 @@ { "SQL": "select 1 from (select /*+ HASH_JOIN(t1) */ t1.a in (select t2.a from t2) from t1) x;", "Plan": [ - "Projection_17 10000.00 root 1->Column#8", - "└─HashJoin_18 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.a, test.t2.a)", - " ├─IndexReader_25(Build) 10000.00 root index:IndexFullScan_26", - " │ └─IndexFullScan_26 10000.00 cop[tikv] table:t2, index:idx_a(a) keep order:false, stats:pseudo", - " └─IndexReader_21(Probe) 10000.00 root index:IndexFullScan_22", - " └─IndexFullScan_22 10000.00 cop[tikv] table:t1, index:idx_a(a) keep order:false, stats:pseudo" + "Projection_18 10000.00 root 1->Column#11", + "└─HashJoin_19 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.a, test.t2.a)", + " ├─IndexReader_26(Build) 10000.00 root index:IndexFullScan_27", + " │ └─IndexFullScan_27 10000.00 cop[tikv] table:t2, index:idx_a(a) keep order:false, stats:pseudo", + " └─IndexReader_22(Probe) 10000.00 root index:IndexFullScan_23", + " └─IndexFullScan_23 10000.00 cop[tikv] table:t1, index:idx_a(a) keep order:false, stats:pseudo" ], "Result": [ "1", @@ -1255,12 +1255,12 @@ { "SQL": "select 1 from (select /*+ HASH_JOIN(t1) */ t1.a not in (select t2.a from t2) from t1) x;", "Plan": [ - "Projection_17 10000.00 root 1->Column#8", - "└─HashJoin_18 10000.00 root CARTESIAN anti left outer semi join, other cond:eq(test.t1.a, test.t2.a)", - " ├─IndexReader_25(Build) 10000.00 root index:IndexFullScan_26", - " │ └─IndexFullScan_26 10000.00 cop[tikv] table:t2, index:idx_a(a) keep order:false, stats:pseudo", - " └─IndexReader_21(Probe) 10000.00 root index:IndexFullScan_22", - " └─IndexFullScan_22 10000.00 cop[tikv] table:t1, index:idx_a(a) keep order:false, stats:pseudo" + "Projection_18 10000.00 root 1->Column#11", + "└─HashJoin_19 10000.00 root CARTESIAN anti left outer semi join, other cond:eq(test.t1.a, test.t2.a)", + " ├─IndexReader_26(Build) 10000.00 root index:IndexFullScan_27", + " │ └─IndexFullScan_27 10000.00 cop[tikv] table:t2, index:idx_a(a) keep order:false, stats:pseudo", + " └─IndexReader_22(Probe) 10000.00 root index:IndexFullScan_23", + " └─IndexFullScan_23 10000.00 cop[tikv] table:t1, index:idx_a(a) keep order:false, stats:pseudo" ], "Result": [ "1", diff --git a/planner/cascades/testdata/stringer_suite_out.json b/planner/cascades/testdata/stringer_suite_out.json index dbcc00aec395f..6df5325b30023 100644 --- a/planner/cascades/testdata/stringer_suite_out.json +++ b/planner/cascades/testdata/stringer_suite_out.json @@ -289,28 +289,28 @@ { "SQL": "select a = (select a from t t2 where t1.b = t2.b order by a limit 1) from t t1", "Result": [ - "Group#0 Schema:[Column#25]", - " Projection_3 input:[Group#1], eq(test.t.a, test.t.a)->Column#25", + "Group#0 Schema:[Column#37]", + " Projection_3 input:[Group#1], eq(test.t.a, test.t.a)->Column#37", "Group#1 Schema:[test.t.a,test.t.b,test.t.a]", - " Apply_9 input:[Group#2,Group#3], left outer join", + " Apply_10 input:[Group#2,Group#3], left outer join", "Group#2 Schema:[test.t.a,test.t.b], UniqueKey:[test.t.a]", - " TiKVSingleGather_11 input:[Group#4], table:t1", + " TiKVSingleGather_12 input:[Group#4], table:t1", "Group#4 Schema:[test.t.a,test.t.b], UniqueKey:[test.t.a]", - " TableScan_10 table:t1, pk col:test.t.a", + " TableScan_11 table:t1, pk col:test.t.a", "Group#3 Schema:[test.t.a], UniqueKey:[test.t.a]", - " MaxOneRow_8 input:[Group#5]", + " MaxOneRow_9 input:[Group#5]", "Group#5 Schema:[test.t.a], UniqueKey:[test.t.a]", - " Limit_7 input:[Group#6], offset:0, count:1", + " Limit_8 input:[Group#6], offset:0, count:1", "Group#6 Schema:[test.t.a], UniqueKey:[test.t.a]", - " Sort_6 input:[Group#7], test.t.a:asc", + " Sort_7 input:[Group#7], test.t.a:asc", "Group#7 Schema:[test.t.a], UniqueKey:[test.t.a]", - " Projection_5 input:[Group#8], test.t.a", + " Projection_6 input:[Group#8], test.t.a", "Group#8 Schema:[test.t.a,test.t.b], UniqueKey:[test.t.a]", - " TiKVSingleGather_13 input:[Group#9], table:t2", + " TiKVSingleGather_14 input:[Group#9], table:t2", "Group#9 Schema:[test.t.a,test.t.b], UniqueKey:[test.t.a]", - " Selection_14 input:[Group#10], eq(test.t.b, test.t.b)", + " Selection_15 input:[Group#10], eq(test.t.b, test.t.b)", "Group#10 Schema:[test.t.a,test.t.b], UniqueKey:[test.t.a]", - " TableScan_12 table:t2, pk col:test.t.a" + " TableScan_13 table:t2, pk col:test.t.a" ] } ] diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index e4cf841e47daf..375a425d11912 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -1962,6 +1962,14 @@ func (s *testIntegrationSuite) TestIndexMergeTableFilter(c *C) { )) } +func (s *testIntegrationSuite) TestIssue22850(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t1") + tk.MustExec("CREATE TABLE t1 (a int(11))") + tk.MustQuery("SELECT @v:=(SELECT 1 FROM t1 t2 LEFT JOIN t1 ON t1.a GROUP BY t1.a) FROM t1").Check(testkit.Rows()) // work fine +} + // #22949: test HexLiteral Used in GetVar expr func (s *testIntegrationSuite) TestGetVarExprWithHexLiteral(c *C) { tk := testkit.NewTestKit(c, s.store) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index fd6a3d87d95f2..1ecdfc06c9767 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -311,32 +311,12 @@ func (b *PlanBuilder) buildAggregation(ctx context.Context, p LogicalPlan, aggFu return plan4Agg, aggIndexMap, nil } -func (b *PlanBuilder) buildTableRefsWithCache(ctx context.Context, from *ast.TableRefsClause) (p LogicalPlan, err error) { - return b.buildTableRefs(ctx, from, true) -} - -func (b *PlanBuilder) buildTableRefs(ctx context.Context, from *ast.TableRefsClause, useCache bool) (p LogicalPlan, err error) { +func (b *PlanBuilder) buildTableRefs(ctx context.Context, from *ast.TableRefsClause) (p LogicalPlan, err error) { if from == nil { p = b.buildTableDual() return } - if !useCache { - return b.buildResultSetNode(ctx, from.TableRefs) - } - var ok bool - p, ok = b.cachedResultSetNodes[from.TableRefs] - if ok { - m := b.cachedHandleHelperMap[from.TableRefs] - b.handleHelper.pushMap(m) - return - } - p, err = b.buildResultSetNode(ctx, from.TableRefs) - if err != nil { - return nil, err - } - b.cachedResultSetNodes[from.TableRefs] = p - b.cachedHandleHelperMap[from.TableRefs] = b.handleHelper.tailMap() - return + return b.buildResultSetNode(ctx, from.TableRefs) } func (b *PlanBuilder) buildResultSetNode(ctx context.Context, node ast.ResultSetNode) (p LogicalPlan, err error) { @@ -2036,13 +2016,13 @@ func (r *correlatedAggregateResolver) Enter(n ast.Node) (ast.Node, bool) { // Finally it restore the original SELECT stmt. func (r *correlatedAggregateResolver) resolveSelect(sel *ast.SelectStmt) (err error) { // collect correlated aggregate from sub-queries inside FROM clause. - useCache, err := r.collectFromTableRefs(r.ctx, sel.From) + _, err = r.collectFromTableRefs(r.ctx, sel.From) if err != nil { return err } // we cannot use cache if there are correlated aggregates inside FROM clause, // since the plan we are building now is not correct and need to be rebuild later. - p, err := r.b.buildTableRefs(r.ctx, sel.From, useCache) + p, err := r.b.buildTableRefs(r.ctx, sel.From) if err != nil { return err } @@ -3035,7 +3015,7 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L // For sub-queries, the FROM clause may have already been built in outer query when resolving correlated aggregates. // If the ResultSetNode inside FROM clause has nothing to do with correlated aggregates, we can simply get the // existing ResultSetNode from the cache. - p, err = b.buildTableRefsWithCache(ctx, sel.From) + p, err = b.buildTableRefs(ctx, sel.From) if err != nil { return nil, err } diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 3b2a6193575a5..223fe9c7ecdd2 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -461,10 +461,6 @@ type PlanBuilder struct { // correlatedAggMapper stores columns for correlated aggregates which should be evaluated in outer query. correlatedAggMapper map[*ast.AggregateFuncExpr]*expression.CorrelatedColumn - // cache ResultSetNodes and HandleHelperMap to avoid rebuilding. - cachedResultSetNodes map[*ast.Join]LogicalPlan - cachedHandleHelperMap map[*ast.Join]map[int64][]*expression.Column - // isForUpdateRead should be true in either of the following situations // 1. use `inside insert`, `update`, `delete` or `select for update` statement // 2. isolation level is RC @@ -569,15 +565,13 @@ func NewPlanBuilder(sctx sessionctx.Context, is infoschema.InfoSchema, processor sctx.GetSessionVars().PlannerSelectBlockAsName = make([]ast.HintTable, processor.MaxSelectStmtOffset()+1) } return &PlanBuilder{ - ctx: sctx, - is: is, - colMapper: make(map[*ast.ColumnNameExpr]int), - handleHelper: &handleColHelper{id2HandleMapStack: make([]map[int64][]*expression.Column, 0)}, - hintProcessor: processor, - correlatedAggMapper: make(map[*ast.AggregateFuncExpr]*expression.CorrelatedColumn), - cachedResultSetNodes: make(map[*ast.Join]LogicalPlan), - cachedHandleHelperMap: make(map[*ast.Join]map[int64][]*expression.Column), - isForUpdateRead: sctx.GetSessionVars().IsPessimisticReadConsistency(), + ctx: sctx, + is: is, + colMapper: make(map[*ast.ColumnNameExpr]int), + handleHelper: &handleColHelper{id2HandleMapStack: make([]map[int64][]*expression.Column, 0)}, + hintProcessor: processor, + correlatedAggMapper: make(map[*ast.AggregateFuncExpr]*expression.CorrelatedColumn), + isForUpdateRead: sctx.GetSessionVars().IsPessimisticReadConsistency(), }, savedBlockNames } diff --git a/planner/core/testdata/analyze_suite_out.json b/planner/core/testdata/analyze_suite_out.json index b433510b1d0d8..9717607d878cc 100644 --- a/planner/core/testdata/analyze_suite_out.json +++ b/planner/core/testdata/analyze_suite_out.json @@ -46,14 +46,14 @@ "EXPLAIN SELECT *, t1.a IN (SELECT t2.b FROM t t2) FROM t t1 WHERE t1.b <= 6 ORDER BY t1.a limit 1" ], "Plan": [ - "Limit_17 1.00 root offset:0, count:1", - "└─IndexJoin_62 1.00 root left outer semi join, inner:IndexReader_61, outer key:test.t.a, inner key:test.t.b, equal cond:eq(test.t.a, test.t.b)", - " ├─TopN_25(Build) 1.00 root test.t.a:asc, offset:0, count:1", - " │ └─IndexReader_33 1.00 root index:TopN_32", - " │ └─TopN_32 1.00 cop[tikv] test.t.a:asc, offset:0, count:1", - " │ └─IndexRangeScan_31 6.00 cop[tikv] table:t1, index:idx_bc(b, c) range:[-inf,6], keep order:false", - " └─IndexReader_61(Probe) 1.04 root index:IndexRangeScan_60", - " └─IndexRangeScan_60 1.04 cop[tikv] table:t2, index:idx_bc(b, c) range: decided by [eq(test.t.b, test.t.a)], keep order:false" + "Limit_18 1.00 root offset:0, count:1", + "└─IndexJoin_63 1.00 root left outer semi join, inner:IndexReader_62, outer key:test.t.a, inner key:test.t.b, equal cond:eq(test.t.a, test.t.b)", + " ├─TopN_26(Build) 1.00 root test.t.a:asc, offset:0, count:1", + " │ └─IndexReader_34 1.00 root index:TopN_33", + " │ └─TopN_33 1.00 cop[tikv] test.t.a:asc, offset:0, count:1", + " │ └─IndexRangeScan_32 6.00 cop[tikv] table:t1, index:idx_bc(b, c) range:[-inf,6], keep order:false", + " └─IndexReader_62(Probe) 1.04 root index:IndexRangeScan_61", + " └─IndexRangeScan_61 1.04 cop[tikv] table:t2, index:idx_bc(b, c) range: decided by [eq(test.t.b, test.t.a)], keep order:false" ] }, { @@ -264,29 +264,29 @@ "Name": "TestCorrelatedEstimation", "Cases": [ [ - "Projection_11 10.00 root Column#14", - "└─Apply_13 10.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13)", - " ├─TableReader_15(Build) 10.00 root data:TableFullScan_14", - " │ └─TableFullScan_14 10.00 cop[tikv] table:t keep order:false", - " └─StreamAgg_19(Probe) 1.00 root funcs:count(1)->Column#13", - " └─HashJoin_20 1.00 root inner join, equal:[eq(test.t.a, test.t.a)]", - " ├─TableReader_30(Build) 1.00 root data:Selection_29", - " │ └─Selection_29 1.00 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))", - " │ └─TableFullScan_28 10.00 cop[tikv] table:t1 keep order:false", - " └─TableReader_24(Probe) 1.00 root data:Selection_23", - " └─Selection_23 1.00 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))", - " └─TableFullScan_22 10.00 cop[tikv] table:s keep order:false" + "Projection_14 10.00 root Column#22", + "└─Apply_16 10.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#21)", + " ├─TableReader_18(Build) 10.00 root data:TableFullScan_17", + " │ └─TableFullScan_17 10.00 cop[tikv] table:t keep order:false", + " └─StreamAgg_22(Probe) 1.00 root funcs:count(1)->Column#21", + " └─HashJoin_23 1.00 root inner join, equal:[eq(test.t.a, test.t.a)]", + " ├─TableReader_33(Build) 1.00 root data:Selection_32", + " │ └─Selection_32 1.00 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))", + " │ └─TableFullScan_31 10.00 cop[tikv] table:t1 keep order:false", + " └─TableReader_27(Probe) 1.00 root data:Selection_26", + " └─Selection_26 1.00 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))", + " └─TableFullScan_25 10.00 cop[tikv] table:s keep order:false" ], [ - "Projection_8 10.00 root Column#9", - "└─Apply_10 10.00 root CARTESIAN left outer join", - " ├─TableReader_12(Build) 10.00 root data:TableFullScan_11", - " │ └─TableFullScan_11 10.00 cop[tikv] table:t keep order:false", - " └─MaxOneRow_15(Probe) 1.00 root ", - " └─Projection_16 0.10 root concat(cast(test.t.a, var_string(20)), ,, cast(test.t.b, var_string(20)))->Column#9", - " └─IndexReader_19 0.10 root index:Selection_18", - " └─Selection_18 0.10 cop[tikv] eq(test.t.a, test.t.a)", - " └─IndexRangeScan_17 1.00 cop[tikv] table:t1, index:idx(c, b, a) range: decided by [eq(test.t.c, test.t.c)], keep order:false" + "Projection_9 10.00 root Column#13", + "└─Apply_11 10.00 root CARTESIAN left outer join", + " ├─TableReader_13(Build) 10.00 root data:TableFullScan_12", + " │ └─TableFullScan_12 10.00 cop[tikv] table:t keep order:false", + " └─MaxOneRow_16(Probe) 1.00 root ", + " └─Projection_17 0.10 root concat(cast(test.t.a, var_string(20)), ,, cast(test.t.b, var_string(20)))->Column#13", + " └─IndexReader_20 0.10 root index:Selection_19", + " └─Selection_19 0.10 cop[tikv] eq(test.t.a, test.t.a)", + " └─IndexRangeScan_18 1.00 cop[tikv] table:t1, index:idx(c, b, a) range: decided by [eq(test.t.c, test.t.c)], keep order:false" ] ] }, diff --git a/planner/core/testdata/integration_suite_out.json b/planner/core/testdata/integration_suite_out.json index 6ebc5adc2e922..a15b7bcf4d9d2 100644 --- a/planner/core/testdata/integration_suite_out.json +++ b/planner/core/testdata/integration_suite_out.json @@ -247,15 +247,15 @@ { "SQL": "desc select t1.a from t t1 order by (t1.b = 1 and exists (select 1 from t t2 where t1.b = t2.b)) limit 1", "Plan": [ - "Projection_11 1.00 root test.t.a", - "└─Projection_20 1.00 root test.t.a, test.t.b, Column#8", - " └─TopN_14 1.00 root Column#10:asc, offset:0, count:1", - " └─Projection_21 10000.00 root test.t.a, test.t.b, Column#8, and(eq(test.t.b, 1), Column#8)->Column#10", - " └─HashJoin_15 10000.00 root left outer semi join, equal:[eq(test.t.b, test.t.b)]", - " ├─TableReader_19(Build) 10000.00 root data:TableFullScan_18", - " │ └─TableFullScan_18 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - " └─TableReader_17(Probe) 10000.00 root data:TableFullScan_16", - " └─TableFullScan_16 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + "Projection_12 1.00 root test.t.a", + "└─Projection_21 1.00 root test.t.a, test.t.b, Column#11", + " └─TopN_15 1.00 root Column#13:asc, offset:0, count:1", + " └─Projection_22 10000.00 root test.t.a, test.t.b, Column#11, and(eq(test.t.b, 1), Column#11)->Column#13", + " └─HashJoin_16 10000.00 root left outer semi join, equal:[eq(test.t.b, test.t.b)]", + " ├─TableReader_20(Build) 10000.00 root data:TableFullScan_19", + " │ └─TableFullScan_19 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " └─TableReader_18(Probe) 10000.00 root data:TableFullScan_17", + " └─TableFullScan_17 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" ] }, { diff --git a/planner/core/testdata/plan_suite_out.json b/planner/core/testdata/plan_suite_out.json index 49d1df63a6ba1..61ce5740fcf67 100644 --- a/planner/core/testdata/plan_suite_out.json +++ b/planner/core/testdata/plan_suite_out.json @@ -2087,12 +2087,12 @@ { "SQL": "select 1 from (select /*+ HASH_JOIN(t1) */ t1.a in (select t2.a from t2) from t1) x;", "Plan": "LeftHashJoin{IndexReader(Index(t1.idx_a)[[NULL,+inf]])->IndexReader(Index(t2.idx_a)[[NULL,+inf]])}->Projection", - "Hints": "use_index(@`sel_2` `test`.`t1` `idx_a`), use_index(@`sel_2` `test`.`t2` `idx_a`), hash_join(@`sel_2` `test`.`t1`)" + "Hints": "use_index(@`sel_2` `test`.`t1` `idx_a`), use_index(@`sel_3` `test`.`t2` `idx_a`), hash_join(@`sel_2` `test`.`t1`)" }, { "SQL": "select 1 from (select /*+ HASH_JOIN(t1) */ t1.a not in (select t2.a from t2) from t1) x;", "Plan": "LeftHashJoin{IndexReader(Index(t1.idx_a)[[NULL,+inf]])->IndexReader(Index(t2.idx_a)[[NULL,+inf]])}->Projection", - "Hints": "use_index(@`sel_2` `test`.`t1` `idx_a`), use_index(@`sel_2` `test`.`t2` `idx_a`), hash_join(@`sel_2` `test`.`t1`)" + "Hints": "use_index(@`sel_2` `test`.`t1` `idx_a`), use_index(@`sel_3` `test`.`t2` `idx_a`), hash_join(@`sel_2` `test`.`t1`)" }, { "SQL": "select /*+ INL_JOIN(t1) */ t1.b, t2.b from t1 inner join t2 on t1.a = t2.a;", diff --git a/planner/core/testdata/plan_suite_unexported_out.json b/planner/core/testdata/plan_suite_unexported_out.json index bc5dbe6d230d3..823b87331817d 100644 --- a/planner/core/testdata/plan_suite_unexported_out.json +++ b/planner/core/testdata/plan_suite_unexported_out.json @@ -136,7 +136,7 @@ "Join{DataScan(t)->Limit->DataScan(s)}(test.t.a,test.t.a)->Limit->Projection", "Join{DataScan(t)->TopN([test.t.a],0,5)->DataScan(s)}(test.t.a,test.t.a)->TopN([test.t.a],0,5)->Projection", "Join{DataScan(t)->TopN([test.t.a],0,5)->DataScan(s)}(test.t.a,test.t.a)->TopN([test.t.a],0,5)->Projection", - "Join{DataScan(t)->DataScan(s)}(test.t.a,test.t.a)->TopN([Column#25],0,5)->Projection", + "Join{DataScan(t)->DataScan(s)}(test.t.a,test.t.a)->TopN([Column#37],0,5)->Projection", "Join{DataScan(t)->DataScan(s)}(test.t.a,test.t.a)->TopN([test.t.a],0,5)->Projection", "Join{DataScan(t)->DataScan(s)->TopN([test.t.a],0,5)}(test.t.a,test.t.a)->TopN([test.t.a],0,5)->Projection", "Join{DataScan(t)->DataScan(s)}(test.t.a,test.t.a)->TopN([test.t.a test.t.b],0,5)->Projection", @@ -194,7 +194,7 @@ "TableReader(Table(t))->Window(sum(cast(test.t.a, decimal(65,0) BINARY))->Column#14 over())->Sort->Projection", "TableReader(Table(t))->Window(sum(cast(test.t.a, decimal(65,0) BINARY))->Column#14 over(partition by test.t.a))->Sort->Projection", "TableReader(Table(t)->StreamAgg)->StreamAgg->Window(sum(Column#13)->Column#15 over())->Sort->Projection", - "Apply{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.f)[[NULL,+inf]]->Sel([gt(test.t.a, test.t.a)]))->Window(sum(cast(test.t.a, decimal(65,0) BINARY))->Column#26 over())->MaxOneRow->Sel([Column#26])}->Projection", + "Apply{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.f)[[NULL,+inf]]->Sel([gt(test.t.a, test.t.a)]))->Window(sum(cast(test.t.a, decimal(65,0) BINARY))->Column#38 over())->MaxOneRow->Sel([Column#38])}->Projection", "[planner:3594]You cannot use the alias 'w' of an expression containing a window function in this context.'", "[planner:1247]Reference 'sum_a' not supported (reference to window function)", "[planner:3579]Window name 'w2' is not defined.", @@ -267,7 +267,7 @@ "TableReader(Table(t))->Window(sum(cast(test.t.a, decimal(65,0) BINARY))->Column#14 over())->Sort->Projection", "TableReader(Table(t))->Window(sum(cast(test.t.a, decimal(65,0) BINARY))->Column#14 over(partition by test.t.a))->Sort->Projection", "TableReader(Table(t)->StreamAgg)->StreamAgg->Window(sum(Column#13)->Column#15 over())->Sort->Projection", - "Apply{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.f)[[NULL,+inf]]->Sel([gt(test.t.a, test.t.a)]))->Window(sum(cast(test.t.a, decimal(65,0) BINARY))->Column#26 over())->MaxOneRow->Sel([Column#26])}->Projection", + "Apply{IndexReader(Index(t.f)[[NULL,+inf]])->IndexReader(Index(t.f)[[NULL,+inf]]->Sel([gt(test.t.a, test.t.a)]))->Window(sum(cast(test.t.a, decimal(65,0) BINARY))->Column#38 over())->MaxOneRow->Sel([Column#38])}->Projection", "[planner:3594]You cannot use the alias 'w' of an expression containing a window function in this context.'", "[planner:1247]Reference 'sum_a' not supported (reference to window function)", "[planner:3579]Window name 'w2' is not defined.", @@ -632,7 +632,7 @@ "1": [ "test.t.a" ], - "2": [ + "4": [ "test.t.a", "test.t.b" ] @@ -647,7 +647,7 @@ "test.t.a", "test.t.b" ], - "2": [ + "4": [ "test.t.b" ] }, @@ -655,7 +655,7 @@ "1": [ "test.t.a" ], - "2": [ + "4": [ "test.t.b" ] }, diff --git a/util/ranger/testdata/ranger_suite_out.json b/util/ranger/testdata/ranger_suite_out.json index 1edc5d9169eb5..ad86aaf739f21 100644 --- a/util/ranger/testdata/ranger_suite_out.json +++ b/util/ranger/testdata/ranger_suite_out.json @@ -5,16 +5,16 @@ { "SQL": "explain select t.e in (select count(*) from t s use index(idx), t t1 where s.b = 1 and s.c in (1, 2) and s.d = t.a and s.a = t1.a) from t", "Result": [ - "Projection_11 2.00 root Column#17", - "└─Apply_13 2.00 root CARTESIAN left outer semi join, other cond:eq(test.t.e, Column#16)", - " ├─TableReader_15(Build) 2.00 root data:TableFullScan_14", - " │ └─TableFullScan_14 2.00 cop[tikv] table:t keep order:false", - " └─StreamAgg_17(Probe) 1.00 root funcs:count(1)->Column#16", - " └─IndexJoin_33 2.00 root inner join, inner:TableReader_32, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a)", - " ├─IndexReader_26(Build) 2.00 root index:IndexRangeScan_25", - " │ └─IndexRangeScan_25 2.00 cop[tikv] table:s, index:idx(b, c, d) range: decided by [eq(test.t.b, 1) in(test.t.c, 1, 2) eq(test.t.d, test.t.a)], keep order:false", - " └─TableReader_32(Probe) 1.00 root data:TableRangeScan_31", - " └─TableRangeScan_31 1.00 cop[tikv] table:t1 range: decided by [test.t.a], keep order:false" + "Projection_14 2.00 root Column#27", + "└─Apply_16 2.00 root CARTESIAN left outer semi join, other cond:eq(test.t.e, Column#26)", + " ├─TableReader_18(Build) 2.00 root data:TableFullScan_17", + " │ └─TableFullScan_17 2.00 cop[tikv] table:t keep order:false", + " └─StreamAgg_20(Probe) 1.00 root funcs:count(1)->Column#26", + " └─IndexJoin_36 2.00 root inner join, inner:TableReader_35, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a)", + " ├─IndexReader_29(Build) 2.00 root index:IndexRangeScan_28", + " │ └─IndexRangeScan_28 2.00 cop[tikv] table:s, index:idx(b, c, d) range: decided by [eq(test.t.b, 1) in(test.t.c, 1, 2) eq(test.t.d, test.t.a)], keep order:false", + " └─TableReader_35(Probe) 1.00 root data:TableRangeScan_34", + " └─TableRangeScan_34 1.00 cop[tikv] table:t1 range: decided by [test.t.a], keep order:false" ] }, {