From 090269283c3ab4b7d1c40cf5ba692cb78aca54f0 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Thu, 18 Mar 2021 15:35:11 +0800 Subject: [PATCH 1/5] cherry pick #23354 to release-5.0 Signed-off-by: ti-srebot --- cmd/explaintest/r/explain_easy.result | 122 +++++++++--------- cmd/explaintest/r/explain_easy_stats.result | 22 ++-- cmd/explaintest/r/select.result | 19 ++- cmd/explaintest/r/subquery.result | 6 +- cmd/explaintest/r/tpch.result | 4 +- executor/executor_test.go | 4 +- executor/testdata/agg_suite_out.json | 12 +- .../testdata/integration_suite_out.json | 64 ++++----- .../cascades/testdata/stringer_suite_out.json | 24 ++-- planner/core/integration_test.go | 81 ++++++++++++ planner/core/logical_plan_builder.go | 34 +---- planner/core/planbuilder.go | 19 +-- planner/core/testdata/analyze_suite_out.json | 10 +- .../core/testdata/integration_suite_out.json | 6 +- planner/core/testdata/plan_suite_out.json | 4 +- .../testdata/plan_suite_unexported_out.json | 12 +- planner/core/testdata/stats_suite_out.json | 39 +++--- util/ranger/testdata/ranger_suite_out.json | 6 +- 18 files changed, 275 insertions(+), 213 deletions(-) diff --git a/cmd/explaintest/r/explain_easy.result b/cmd/explaintest/r/explain_easy.result index db055cbeac563..3c1f255066bec 100644 --- a/cmd/explaintest/r/explain_easy.result +++ b/cmd/explaintest/r/explain_easy.result @@ -90,8 +90,8 @@ Selection 0.33 root gt(test.t1.c2, 1) └─Point_Get 1.00 root table:t1 handle:1 explain format = 'brief' select sum(t1.c1 in (select c1 from t2)) from t1; id estRows task access object operator info -StreamAgg 1.00 root funcs:sum(Column#10)->Column#8 -└─Projection 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10 +StreamAgg 1.00 root funcs:sum(Column#13)->Column#11 +└─Projection 10000.00 root cast(Column#10, decimal(65,0) BINARY)->Column#13 └─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, test.t2.c1) ├─IndexReader(Build) 10000.00 root index:IndexFullScan │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo @@ -108,9 +108,9 @@ HashJoin 9990.00 root inner join, equal:[eq(test.t1.c1, test.t2.c2)] └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' 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 10000.00 root ifnull(Column#7, 0)->Column#7 +Projection 10000.00 root ifnull(Column#10, 0)->Column#10 └─MergeJoin 10000.00 root left outer join, left key:test.t1.c1, right key:test.t1.c1 - ├─Projection(Build) 8000.00 root 1->Column#7, test.t1.c1 + ├─Projection(Build) 8000.00 root 1->Column#10, test.t1.c1 │ └─TableReader 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:s keep order:true, stats:pseudo └─TableReader(Probe) 10000.00 root data:TableFullScan @@ -120,7 +120,7 @@ id estRows task access object operator info MemTableScan 10000.00 root table:COLUMNS explain format = 'brief' 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 10000.00 root eq(test.t1.c2, test.t2.c2)->Column#8 +Projection 10000.00 root eq(test.t1.c2, test.t2.c2)->Column#11 └─Apply 10000.00 root CARTESIAN left outer join ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo @@ -222,8 +222,8 @@ StreamAgg 1.00 root funcs:count(1)->Column#5 set @@session.tidb_opt_insubq_to_join_and_agg=0; explain format = 'brief' select sum(t1.c1 in (select c1 from t2)) from t1; id estRows task access object operator info -StreamAgg 1.00 root funcs:sum(Column#10)->Column#8 -└─Projection 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10 +StreamAgg 1.00 root funcs:sum(Column#13)->Column#11 +└─Projection 10000.00 root cast(Column#10, decimal(65,0) BINARY)->Column#13 └─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.c1, test.t2.c1) ├─IndexReader(Build) 10000.00 root index:IndexFullScan │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:c1(c1) keep order:false, stats:pseudo @@ -238,8 +238,8 @@ HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2 └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select sum(6 in (select c2 from t2)) from t1; id estRows task access object operator info -StreamAgg 1.00 root funcs:sum(Column#10)->Column#8 -└─Projection 10000.00 root cast(Column#7, decimal(65,0) BINARY)->Column#10 +StreamAgg 1.00 root funcs:sum(Column#13)->Column#11 +└─Projection 10000.00 root cast(Column#10, decimal(65,0) BINARY)->Column#13 └─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(6, test.t2.c2) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo @@ -248,57 +248,57 @@ StreamAgg 1.00 root funcs:sum(Column#10)->Column#8 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,11 +306,11 @@ drop table if exists t; create table t(a int primary key, b int, c int, index idx(b)); explain format = 'brief' 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 10000.00 root Column#11 -└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) +Projection 10000.00 root Column#17 +└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 └─MergeJoin 12.50 root inner join, left key:test.t.a, right key:test.t.a ├─TableReader(Build) 1.00 root data:TableRangeScan │ └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo @@ -318,11 +318,11 @@ Projection 10000.00 root Column#11 └─TableRangeScan 1.00 cop[tikv] table:s range: decided by [eq(test.t.a, test.t.a)], keep order:true, stats:pseudo explain format = 'brief' 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 10000.00 root Column#11 -└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) +Projection 10000.00 root Column#17 +└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 └─IndexJoin 12.50 root inner join, inner:TableReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) ├─IndexReader(Build) 10.00 root index:IndexRangeScan │ └─IndexRangeScan 10.00 cop[tikv] table:s, index:idx(b) range: decided by [eq(test.t.b, test.t.a)], keep order:false, stats:pseudo @@ -330,11 +330,11 @@ Projection 10000.00 root Column#11 └─TableRangeScan 1.00 cop[tikv] table:t1 range: decided by [test.t.a], keep order:false, stats:pseudo explain format = 'brief' 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 10000.00 root Column#11 -└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) +Projection 10000.00 root Column#17 +└─Apply 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 └─IndexJoin 12.49 root inner join, inner:TableReader, outer key:test.t.c, inner key:test.t.a, equal cond:eq(test.t.c, test.t.a) ├─IndexLookUp(Build) 9.99 root │ ├─IndexRangeScan(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 @@ -346,11 +346,11 @@ insert into t values(1, 1, 1), (2, 2 ,2), (3, 3, 3), (4, 3, 4),(5,3,5); analyze table t; explain format = 'brief' 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 5.00 root Column#11 -└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) +Projection 5.00 root Column#17 +└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 └─MergeJoin 2.40 root inner join, left key:test.t.a, right key:test.t.a ├─TableReader(Build) 4.00 root data:Selection │ └─Selection 4.00 cop[tikv] eq(3, test.t.a) @@ -360,11 +360,11 @@ Projection 5.00 root Column#11 └─IndexRangeScan 3.00 cop[tikv] table:s, index:idx(b) range:[3,3], keep order:true explain format = 'brief' 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 5.00 root Column#11 -└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) +Projection 5.00 root Column#17 +└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 └─MergeJoin 2.40 root left outer join, left key:test.t.a, right key:test.t.a ├─TableReader(Build) 4.00 root data:Selection │ └─Selection 4.00 cop[tikv] eq(3, test.t.a) @@ -374,11 +374,11 @@ Projection 5.00 root Column#11 └─IndexRangeScan 3.00 cop[tikv] table:s, index:idx(b) range:[3,3], keep order:true explain format = 'brief' 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 5.00 root Column#11 -└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#10) +Projection 5.00 root Column#17 +└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#16) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#10 + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16 └─MergeJoin 2.40 root right outer join, left key:test.t.a, right key:test.t.a ├─TableReader(Build) 4.00 root data:Selection │ └─Selection 4.00 cop[tikv] eq(3, test.t.a) @@ -579,15 +579,15 @@ HashJoin 2773.61 root inner join, equal:[eq(test.t.nb, test.t.nb)] └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo explain format = 'brief' 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 10000.00 root Column#14 -└─Apply 10000.00 root left outer semi join, equal:[eq(test.t.nc, Column#13)] +Projection 10000.00 root Column#22 +└─Apply 10000.00 root left outer semi join, equal:[eq(test.t.nc, Column#21)] ├─TableReader(Build) 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─HashAgg(Probe) 1.00 root funcs:count(Column#15)->Column#13 + └─HashAgg(Probe) 1.00 root funcs:count(Column#23)->Column#21 └─HashJoin 9.99 root inner join, equal:[eq(test.t.a, test.t.a)] - ├─HashAgg(Build) 7.99 root group by:test.t.a, funcs:count(Column#16)->Column#15, funcs:firstrow(test.t.a)->test.t.a + ├─HashAgg(Build) 7.99 root group by:test.t.a, funcs:count(Column#24)->Column#23, funcs:firstrow(test.t.a)->test.t.a │ └─TableReader 7.99 root data:HashAgg - │ └─HashAgg 7.99 cop[tikv] group by:test.t.a, funcs:count(1)->Column#16 + │ └─HashAgg 7.99 cop[tikv] group by:test.t.a, funcs:count(1)->Column#24 │ └─Selection 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo └─TableReader(Probe) 9.99 root data:Selection @@ -612,16 +612,16 @@ HashJoin 8002.00 root right outer join, equal:[eq(test.t.nb, test.t.nb)] └─TableFullScan 10000.00 cop[tikv] table:tb keep order:false, stats:pseudo explain format = 'brief' 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 10000.00 root Column#14 -└─Apply 10000.00 root left outer semi join, equal:[eq(Column#15, Column#13)] - ├─Projection(Build) 10000.00 root test.t.a, ifnull(test.t.a, 1)->Column#15 +Projection 10000.00 root Column#22 +└─Apply 10000.00 root left outer semi join, equal:[eq(Column#23, Column#21)] + ├─Projection(Build) 10000.00 root test.t.a, ifnull(test.t.a, 1)->Column#23 │ └─TableReader 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo - └─HashAgg(Probe) 1.00 root funcs:count(Column#17)->Column#13 + └─HashAgg(Probe) 1.00 root funcs:count(Column#25)->Column#21 └─HashJoin 9.99 root inner join, equal:[eq(test.t.a, test.t.a)] - ├─HashAgg(Build) 7.99 root group by:test.t.a, funcs:count(Column#18)->Column#17, funcs:firstrow(test.t.a)->test.t.a + ├─HashAgg(Build) 7.99 root group by:test.t.a, funcs:count(Column#26)->Column#25, funcs:firstrow(test.t.a)->test.t.a │ └─TableReader 7.99 root data:HashAgg - │ └─HashAgg 7.99 cop[tikv] group by:test.t.a, funcs:count(1)->Column#18 + │ └─HashAgg 7.99 cop[tikv] group by:test.t.a, funcs:count(1)->Column#26 │ └─Selection 9.99 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a)) │ └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo └─TableReader(Probe) 9.99 root data:Selection @@ -788,7 +788,7 @@ drop table if exists t; create table t(a int, b int); explain format = 'brief' select (select count(n.a) from t) from t n; id estRows task access object operator info -Projection 1.00 root Column#8 +Projection 1.00 root Column#11 └─Apply 1.00 root CARTESIAN left outer join ├─StreamAgg(Build) 1.00 root funcs:count(test.t.a)->Column#7 │ └─TableReader 10000.00 root data:TableFullScan diff --git a/cmd/explaintest/r/explain_easy_stats.result b/cmd/explaintest/r/explain_easy_stats.result index 92eee10bfc47c..d31bcf4f4174f 100644 --- a/cmd/explaintest/r/explain_easy_stats.result +++ b/cmd/explaintest/r/explain_easy_stats.result @@ -102,7 +102,7 @@ id estRows task access object operator info MemTableScan 10000.00 root table:COLUMNS explain format = 'brief' 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 1999.00 root eq(test.t1.c2, test.t2.c2)->Column#8 +Projection 1999.00 root eq(test.t1.c2, test.t2.c2)->Column#11 └─Apply 1999.00 root CARTESIAN left outer join ├─TableReader(Build) 1999.00 root data:TableFullScan │ └─TableFullScan 1999.00 cop[tikv] table:t1 keep order:false @@ -128,28 +128,28 @@ HashJoin 1999.00 root CARTESIAN left outer semi join, other cond:eq(1, test.t2. 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 format = 'brief' 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 902834b9c3ef3..12671fe8c08c9 100644 --- a/cmd/explaintest/r/select.result +++ b/cmd/explaintest/r/select.result @@ -374,20 +374,20 @@ drop table if exists t; create table t(a int, b int); explain format = 'brief' select a != any (select a from t t2) from t t1; id estRows task access object operator info -Projection 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 +Projection 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 10000.00 root CARTESIAN inner join - ├─StreamAgg(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 10000.00 root test.t.a, test.t.a, cast(isnull(test.t.a), decimal(22,0) BINARY)->Column#15 + ├─StreamAgg(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 10000.00 root test.t.a, test.t.a, cast(isnull(test.t.a), decimal(22,0) BINARY)->Column#18 │ └─TableReader 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo └─TableReader(Probe) 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo explain format = 'brief' select a = all (select a from t t2) from t t1; id estRows task access object operator info -Projection 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 +Projection 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 10000.00 root CARTESIAN inner join - ├─StreamAgg(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 10000.00 root test.t.a, test.t.a, cast(isnull(test.t.a), decimal(22,0) BINARY)->Column#15 + ├─StreamAgg(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 10000.00 root test.t.a, test.t.a, cast(isnull(test.t.a), decimal(22,0) BINARY)->Column#18 │ └─TableReader 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo └─TableReader(Probe) 10000.00 root data:TableFullScan @@ -398,11 +398,16 @@ drop table if exists s; create table s(a varchar(20), b varchar(20)); explain format = 'brief' select a in (select a from s where s.b = t.b) from t; id estRows task access object operator info +<<<<<<< HEAD HashJoin 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(Build) 10000.00 root test.s.a, cast(test.s.b, double BINARY)->Column#9 +======= +HashJoin 10000.00 root left outer semi join, equal:[eq(Column#11, Column#12)], other cond:eq(cast(test.t.a, double BINARY), cast(test.s.a, double BINARY)) +├─Projection(Build) 10000.00 root test.s.a, cast(test.s.b, double BINARY)->Column#12 +>>>>>>> 28c374849... planner: remove some risky cache operations in the plan builder (#23354) │ └─TableReader 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:s keep order:false, stats:pseudo -└─Projection(Probe) 10000.00 root test.t.a, cast(test.t.b, double BINARY)->Column#8 +└─Projection(Probe) 10000.00 root test.t.a, cast(test.t.b, double BINARY)->Column#11 └─TableReader 10000.00 root data:TableFullScan └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo explain format = 'brief' select a in (select a+b from t t2 where t2.b = t1.b) from t t1; diff --git a/cmd/explaintest/r/subquery.result b/cmd/explaintest/r/subquery.result index 50c83dc1800f6..0b054d45ba2a3 100644 --- a/cmd/explaintest/r/subquery.result +++ b/cmd/explaintest/r/subquery.result @@ -17,11 +17,11 @@ 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 format = 'brief' 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 5.00 root Column#14 -└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13) +Projection 5.00 root Column#22 +└─Apply 5.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#21) ├─TableReader(Build) 5.00 root data:TableFullScan │ └─TableFullScan 5.00 cop[tikv] table:t keep order:false - └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13 + └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#21 └─IndexJoin 0.50 root inner join, inner:TableReader, outer key:test.t.a, inner key:test.t.a, equal cond:eq(test.t.a, test.t.a) ├─IndexReader(Build) 1.00 root index:IndexRangeScan │ └─IndexRangeScan 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 diff --git a/cmd/explaintest/r/tpch.result b/cmd/explaintest/r/tpch.result index bb6a2e6201ee0..9985683a2d822 100644 --- a/cmd/explaintest/r/tpch.result +++ b/cmd/explaintest/r/tpch.result @@ -720,8 +720,8 @@ id estRows task access object operator info Projection 1304801.67 root tpch.partsupp.ps_partkey, Column#35 └─Sort 1304801.67 root Column#35:desc └─Selection 1304801.67 root gt(Column#35, NULL) - └─HashAgg 1631002.09 root group by:Column#44, funcs:sum(Column#42)->Column#35, funcs:firstrow(Column#43)->tpch.partsupp.ps_partkey - └─Projection 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 + └─HashAgg 1631002.09 root group by:Column#61, funcs:sum(Column#59)->Column#35, funcs:firstrow(Column#60)->tpch.partsupp.ps_partkey + └─Projection 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 1631002.09 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)] ├─HashJoin(Build) 20000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)] │ ├─TableReader(Build) 1.00 root data:Selection diff --git a/executor/executor_test.go b/executor/executor_test.go index aff376228b938..0aa43b6b7dfb5 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -6635,7 +6635,7 @@ func (s *testSuiteP2) TestApplyCache(c *C) { tk.MustExec("insert into t values (1),(1),(1),(1),(1),(1),(1),(1),(1);") tk.MustExec("analyze table t;") result := tk.MustQuery("explain analyze SELECT count(1) FROM (SELECT (SELECT min(a) FROM t as t2 WHERE t2.a > t1.a) AS a from t as t1) t;") - c.Assert(result.Rows()[1][0], Equals, "└─Apply_38") + c.Assert(result.Rows()[1][0], Equals, "└─Apply_39") var ( ind int flag bool @@ -6655,7 +6655,7 @@ func (s *testSuiteP2) TestApplyCache(c *C) { tk.MustExec("insert into t values (1),(2),(3),(4),(5),(6),(7),(8),(9);") tk.MustExec("analyze table t;") result = tk.MustQuery("explain analyze SELECT count(1) FROM (SELECT (SELECT min(a) FROM t as t2 WHERE t2.a > t1.a) AS a from t as t1) t;") - c.Assert(result.Rows()[1][0], Equals, "└─Apply_38") + c.Assert(result.Rows()[1][0], Equals, "└─Apply_39") flag = false value = (result.Rows()[1][5]).(string) for ind = 0; ind < len(value)-5; ind++ { diff --git a/executor/testdata/agg_suite_out.json b/executor/testdata/agg_suite_out.json index 325f9dd48972c..abfb0f9d102ef 100644 --- a/executor/testdata/agg_suite_out.json +++ b/executor/testdata/agg_suite_out.json @@ -49,27 +49,27 @@ "Name": "TestIssue12759HashAggCalledByApply", "Cases": [ [ - "Projection 1.00 root Column#9, Column#10, Column#11, Column#12", + "Projection 1.00 root Column#9, Column#12, Column#15, Column#18", "└─Apply 1.00 root CARTESIAN left outer join", " ├─Apply(Build) 1.00 root CARTESIAN left outer join", " │ ├─Apply(Build) 1.00 root CARTESIAN left outer join", - " │ │ ├─HashAgg(Build) 1.00 root funcs:sum(Column#22)->Column#9, funcs:firstrow(Column#23)->test.test.a", - " │ │ │ └─Projection 10000.00 root cast(test.test.a, decimal(32,0) BINARY)->Column#22, test.test.a", + " │ │ ├─HashAgg(Build) 1.00 root funcs:sum(Column#28)->Column#9, funcs:firstrow(Column#29)->test.test.a", + " │ │ │ └─Projection 10000.00 root cast(test.test.a, decimal(32,0) BINARY)->Column#28, test.test.a", " │ │ │ └─TableReader 10000.00 root data:TableFullScan", " │ │ │ └─TableFullScan 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo", - " │ │ └─Projection(Probe) 1.00 root ->Column#10", + " │ │ └─Projection(Probe) 1.00 root ->Column#12", " │ │ └─Limit 1.00 root offset:0, count:1", " │ │ └─TableReader 1.00 root data:Limit", " │ │ └─Limit 1.00 cop[tikv] offset:0, count:1", " │ │ └─Selection 1.00 cop[tikv] eq(test.test.a, test.test.a)", " │ │ └─TableFullScan 1000.00 cop[tikv] table:test keep order:false, stats:pseudo", - " │ └─Projection(Probe) 1.00 root ->Column#11", + " │ └─Projection(Probe) 1.00 root ->Column#15", " │ └─Limit 1.00 root offset:0, count:1", " │ └─TableReader 1.00 root data:Limit", " │ └─Limit 1.00 cop[tikv] offset:0, count:1", " │ └─Selection 1.00 cop[tikv] eq(test.test.a, test.test.a)", " │ └─TableFullScan 1000.00 cop[tikv] table:test keep order:false, stats:pseudo", - " └─Projection(Probe) 1.00 root ->Column#12", + " └─Projection(Probe) 1.00 root ->Column#18", " └─Limit 1.00 root offset:0, count:1", " └─TableReader 1.00 root data:Limit", " └─Limit 1.00 cop[tikv] offset:0, count:1", diff --git a/planner/cascades/testdata/integration_suite_out.json b/planner/cascades/testdata/integration_suite_out.json index 3de732f419ed1..7b6cebdd1bbf8 100644 --- a/planner/cascades/testdata/integration_suite_out.json +++ b/planner/cascades/testdata/integration_suite_out.json @@ -1026,17 +1026,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", @@ -1048,25 +1048,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_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#8)->Column#7, funcs:firstrow(Column#9)->test.t2.a, funcs:firstrow(Column#10)->test.t2.b", - " │ │ └─TableReader_40 1.00 root data:HashAgg_41", - " │ │ └─HashAgg_41 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_38 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" + "Projection_32 1.00 root Column#7, test.t1.a, test.t1.b", + "└─Apply_34 1.00 root CARTESIAN left outer join", + " ├─Apply_36(Build) 1.00 root CARTESIAN left outer join", + " │ ├─HashAgg_41(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_42 1.00 root data:HashAgg_43", + " │ │ └─HashAgg_43 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_40 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + " │ └─MaxOneRow_44(Probe) 1.00 root ", + " │ └─Limit_45 1.00 root offset:0, count:1", + " │ └─TableReader_46 1.00 root data:Limit_47", + " │ └─Limit_47 1.00 cop[tikv] offset:0, count:1", + " │ └─Selection_48 1.00 cop[tikv] eq(test.t1.a, test.t2.a)", + " │ └─TableFullScan_49 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo", + " └─MaxOneRow_50(Probe) 1.00 root ", + " └─Limit_51 1.00 root offset:0, count:1", + " └─TableReader_52 1.00 root data:Limit_53", + " └─Limit_53 1.00 cop[tikv] offset:0, count:1", + " └─Selection_54 1.00 cop[tikv] eq(test.t1.b, test.t2.b)", + " └─TableFullScan_55 1.00 cop[tikv] table:t1 keep order:false, stats:pseudo" ], "Result": [ "6 1 11" @@ -1280,7 +1280,7 @@ { "SQL": "select 1 from (select /*+ HASH_JOIN(t1) */ t1.a in (select t2.a from t2) from t1) x;", "Plan": [ - "Projection 10000.00 root 1->Column#8", + "Projection 10000.00 root 1->Column#11", "└─HashJoin 10000.00 root CARTESIAN left outer semi join, other cond:eq(test.t1.a, test.t2.a)", " ├─IndexReader(Build) 10000.00 root index:IndexFullScan", " │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:idx_a(a) keep order:false, stats:pseudo", @@ -1295,7 +1295,7 @@ { "SQL": "select 1 from (select /*+ HASH_JOIN(t1) */ t1.a not in (select t2.a from t2) from t1) x;", "Plan": [ - "Projection 10000.00 root 1->Column#8", + "Projection 10000.00 root 1->Column#11", "└─HashJoin 10000.00 root CARTESIAN anti left outer semi join, other cond:eq(test.t1.a, test.t2.a)", " ├─IndexReader(Build) 10000.00 root index:IndexFullScan", " │ └─IndexFullScan 10000.00 cop[tikv] table:t2, index:idx_a(a) keep order:false, stats:pseudo", diff --git a/planner/cascades/testdata/stringer_suite_out.json b/planner/cascades/testdata/stringer_suite_out.json index 4a3335854ac88..4890084817ea2 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", + " Sort_7 input:[Group#7], test.t.a", "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 88b3d5375665e..6ca26a1038fc0 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -2886,3 +2886,84 @@ func (s *testIntegrationSuite) TestIndexMergeTableFilter(c *C) { "10 1 1 10", )) } +<<<<<<< HEAD +======= + +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) + tk.MustExec("use test;") + tk.MustExec("drop table if exists t1_no_idx;") + tk.MustExec("create table t1_no_idx(id int, col_bit bit(16));") + tk.MustExec("insert into t1_no_idx values(1, 0x3135);") + tk.MustExec("insert into t1_no_idx values(2, 0x0f);") + + tk.MustExec("prepare stmt from 'select id from t1_no_idx where col_bit = ?';") + tk.MustExec("set @a = 0x3135;") + tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) + tk.MustExec("set @a = 0x0F;") + tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("2")) + + // same test, but use IN expr + tk.MustExec("prepare stmt from 'select id from t1_no_idx where col_bit in (?)';") + tk.MustExec("set @a = 0x3135;") + tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) + tk.MustExec("set @a = 0x0F;") + tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("2")) + + // same test, but use table with index on col_bit + tk.MustExec("drop table if exists t2_idx;") + tk.MustExec("create table t2_idx(id int, col_bit bit(16), key(col_bit));") + tk.MustExec("insert into t2_idx values(1, 0x3135);") + tk.MustExec("insert into t2_idx values(2, 0x0f);") + + tk.MustExec("prepare stmt from 'select id from t2_idx where col_bit = ?';") + tk.MustExec("set @a = 0x3135;") + tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) + tk.MustExec("set @a = 0x0F;") + tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("2")) + + // same test, but use IN expr + tk.MustExec("prepare stmt from 'select id from t2_idx where col_bit in (?)';") + tk.MustExec("set @a = 0x3135;") + tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) + tk.MustExec("set @a = 0x0F;") + tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("2")) + + // test col varchar with GetVar + tk.MustExec("drop table if exists t_varchar;") + tk.MustExec("create table t_varchar(id int, col_varchar varchar(100), key(col_varchar));") + tk.MustExec("insert into t_varchar values(1, '15');") + tk.MustExec("prepare stmt from 'select id from t_varchar where col_varchar = ?';") + tk.MustExec("set @a = 0x3135;") + tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) +} + +// test BitLiteral used with GetVar +func (s *testIntegrationSuite) TestGetVarExprWithBitLiteral(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test;") + tk.MustExec("drop table if exists t1_no_idx;") + tk.MustExec("create table t1_no_idx(id int, col_bit bit(16));") + tk.MustExec("insert into t1_no_idx values(1, 0x3135);") + tk.MustExec("insert into t1_no_idx values(2, 0x0f);") + + tk.MustExec("prepare stmt from 'select id from t1_no_idx where col_bit = ?';") + // 0b11000100110101 is 0x3135 + tk.MustExec("set @a = 0b11000100110101;") + tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) + + // same test, but use IN expr + tk.MustExec("prepare stmt from 'select id from t1_no_idx where col_bit in (?)';") + tk.MustExec("set @a = 0b11000100110101;") + tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) +} +>>>>>>> 28c374849... planner: remove some risky cache operations in the plan builder (#23354) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index aa5257b63536e..971e29d0f1a91 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -300,32 +300,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) { @@ -2261,17 +2241,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 } - // do not use cache when for update read - if isForUpdateReadSelectLock(sel.LockInfo) { - useCache = false - } // 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 } @@ -3333,7 +3309,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 0a7b73beb482e..ed1777031d43c 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -467,9 +467,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][]HandleCols // 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 @@ -579,15 +576,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][]HandleCols, 0)}, - hintProcessor: processor, - correlatedAggMapper: make(map[*ast.AggregateFuncExpr]*expression.CorrelatedColumn), - cachedResultSetNodes: make(map[*ast.Join]LogicalPlan), - cachedHandleHelperMap: make(map[*ast.Join]map[int64][]HandleCols), - isForUpdateRead: sctx.GetSessionVars().IsPessimisticReadConsistency(), + ctx: sctx, + is: is, + colMapper: make(map[*ast.ColumnNameExpr]int), + handleHelper: &handleColHelper{id2HandleMapStack: make([]map[int64][]HandleCols, 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 d902165db2dfe..7a803b145210a 100644 --- a/planner/core/testdata/analyze_suite_out.json +++ b/planner/core/testdata/analyze_suite_out.json @@ -264,11 +264,11 @@ "Name": "TestCorrelatedEstimation", "Cases": [ [ - "Projection 10.00 root Column#14", - "└─Apply 10.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#13)", + "Projection 10.00 root Column#22", + "└─Apply 10.00 root CARTESIAN left outer semi join, other cond:eq(test.t.c, Column#21)", " ├─TableReader(Build) 10.00 root data:TableFullScan", " │ └─TableFullScan 10.00 cop[tikv] table:t keep order:false", - " └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#13", + " └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#21", " └─HashJoin 1.00 root inner join, equal:[eq(test.t.a, test.t.a)]", " ├─TableReader(Build) 1.00 root data:Selection", " │ └─Selection 1.00 cop[tikv] eq(test.t.a, test.t.a), not(isnull(test.t.a))", @@ -278,12 +278,12 @@ " └─TableFullScan 10.00 cop[tikv] table:s keep order:false" ], [ - "Projection 10.00 root Column#9", + "Projection 10.00 root Column#13", "└─Apply 10.00 root CARTESIAN left outer join", " ├─TableReader(Build) 10.00 root data:TableFullScan", " │ └─TableFullScan 10.00 cop[tikv] table:t keep order:false", " └─MaxOneRow(Probe) 1.00 root ", - " └─Projection 0.10 root concat(cast(test.t.a, var_string(20)), ,, cast(test.t.b, var_string(20)))->Column#9", + " └─Projection 0.10 root concat(cast(test.t.a, var_string(20)), ,, cast(test.t.b, var_string(20)))->Column#13", " └─IndexReader 0.10 root index:Selection", " └─Selection 0.10 cop[tikv] eq(test.t.a, test.t.a)", " └─IndexRangeScan 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 eec13a9ee1dd5..dae3a5d07f1c7 100644 --- a/planner/core/testdata/integration_suite_out.json +++ b/planner/core/testdata/integration_suite_out.json @@ -338,9 +338,9 @@ "SQL": "desc format = 'brief' 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 1.00 root test.t.a", - "└─Projection 1.00 root test.t.a, test.t.b, Column#8", - " └─TopN 1.00 root Column#10, offset:0, count:1", - " └─Projection 10000.00 root test.t.a, test.t.b, Column#8, and(eq(test.t.b, 1), Column#8)->Column#10", + "└─Projection 1.00 root test.t.a, test.t.b, Column#11", + " └─TopN 1.00 root Column#13, offset:0, count:1", + " └─Projection 10000.00 root test.t.a, test.t.b, Column#11, and(eq(test.t.b, 1), Column#11)->Column#13", " └─HashJoin 10000.00 root left outer semi join, equal:[eq(test.t.b, test.t.b)]", " ├─TableReader(Build) 10000.00 root data:TableFullScan", " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", diff --git a/planner/core/testdata/plan_suite_out.json b/planner/core/testdata/plan_suite_out.json index 161ed9bb69001..dc2d3028245f0 100644 --- a/planner/core/testdata/plan_suite_out.json +++ b/planner/core/testdata/plan_suite_out.json @@ -2141,12 +2141,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 eab64f63a7ba8..1525a773b118e 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.", @@ -650,7 +650,7 @@ "1": [ "test.t.a" ], - "2": [ + "4": [ "test.t.a", "test.t.b" ] @@ -665,7 +665,7 @@ "test.t.a", "test.t.b" ], - "2": [ + "4": [ "test.t.b" ] }, @@ -673,7 +673,7 @@ "1": [ "test.t.a" ], - "2": [ + "4": [ "test.t.b" ] }, diff --git a/planner/core/testdata/stats_suite_out.json b/planner/core/testdata/stats_suite_out.json index e284758839d89..07f4c00c0a1b7 100644 --- a/planner/core/testdata/stats_suite_out.json +++ b/planner/core/testdata/stats_suite_out.json @@ -49,12 +49,12 @@ }, { "SQL": "select count(tmp.cmp) from (select t1.a as a, t1.b as b, (t1.b in (select t2.b from t2 where t2.a = t1.a limit 3)) as cmp from t1) tmp group by tmp.a, tmp.b", - "AggInput": "[{[53 54] 4}]", + "AggInput": "[{[56 57] 4}]", "JoinInput": "" }, { "SQL": "select count(tmp.cmp) from (select t1.a as a, t1.b as b, (t1.b not in (select t2.b from t2 where t2.a = t1.a limit 3)) as cmp from t1) tmp group by tmp.a, tmp.b", - "AggInput": "[{[61 62] 4}]", + "AggInput": "[{[67 68] 4}]", "JoinInput": "" }, { @@ -74,8 +74,8 @@ }, { "SQL": "select count(1) from t1 left join t2 on t1.a = t2.a group by t1.a, t1.b", - "AggInput": "[{[90 91] 4}]", - "JoinInput": "[{[90 91] 4}];[]" + "AggInput": "[{[99 100] 4}]", + "JoinInput": "[{[99 100] 4}];[]" }, { "SQL": "select count(1) from t1 left join t2 on t1.a = t2.a group by t2.a, t2.b", @@ -89,18 +89,18 @@ }, { "SQL": "select count(1) from t1 right join t2 on t1.a = t2.a group by t2.a, t2.b", - "AggInput": "[{[114 115] 9}]", - "JoinInput": "[];[{[114 115] 9}]" + "AggInput": "[{[123 124] 9}]", + "JoinInput": "[];[{[123 124] 9}]" }, { "SQL": "select count(tmp.cmp) from (select t1.a as a, t1.b as b, (t1.b in (select t2.b from t2 where t2.a > t1.a)) as cmp from t1) tmp group by tmp.a, tmp.b", - "AggInput": "[{[118 119] 4}]", - "JoinInput": "[{[118 119] 4}];[]" + "AggInput": "[{[127 128] 4}]", + "JoinInput": "[{[127 128] 4}];[]" }, { "SQL": "select count(tmp.cmp) from (select t1.a as a, t1.b as b, (t1.b not in (select t2.b from t2 where t2.a > t1.a)) as cmp from t1) tmp group by tmp.a, tmp.b", - "AggInput": "[{[126 127] 4}]", - "JoinInput": "[{[126 127] 4}];[]" + "AggInput": "[{[138 139] 4}]", + "JoinInput": "[{[138 139] 4}];[]" }, { "SQL": "select count(1) from (select t1.a as a, t1.b as b from t1 where t1.b in (select t2.b from t2 where t2.a > t1.a)) tmp group by tmp.a, tmp.b", @@ -114,8 +114,8 @@ }, { "SQL": "select * from t1 left join (select t2.a as a, t2.b as b, count(1) as cnt from t2 group by t2.a, t2.b) as tmp on t1.a = tmp.a and t1.b = tmp.b", - "AggInput": "[{[151 152] 9}]", - "JoinInput": "[{[148 149] 4}];[{[151 152] 9}]" + "AggInput": "[{[166 167] 9}]", + "JoinInput": "[{[163 164] 4}];[{[166 167] 9}]" }, { "SQL": "select count(1) from (select t1.a as a, t1.b as b from t1 limit 3) tmp group by tmp.a, tmp.b", @@ -124,7 +124,7 @@ }, { "SQL": "select count(tmp.a_sum) from (select t1.a as a, t1.b as b, sum(a) over() as a_sum from t1) tmp group by tmp.a, tmp.b", - "AggInput": "[{[159 160] 4}]", + "AggInput": "[{[174 175] 4}]", "JoinInput": "" } ] @@ -179,8 +179,13 @@ { "SQL": "select count(tmp.cmp) from (select t1.a as a, t1.b as b, (t1.b > (select t2.b from t2 where t2.a = t1.a)) as cmp from t1) tmp group by tmp.a, tmp.b", "Plan": [ +<<<<<<< HEAD "StreamAgg 4.00 root group by:test.t1.a, test.t1.b, funcs:count(Column#7)->Column#8", "└─Projection 4.00 root test.t1.a, test.t1.b, gt(test.t1.b, test.t2.b)->Column#7", +======= + "StreamAgg 4.00 root group by:Column#14, Column#15, funcs:count(Column#13)->Column#11", + "└─Projection 4.00 root gt(test.t1.b, test.t2.b)->Column#13, test.t1.a, test.t1.b", +>>>>>>> 28c374849... planner: remove some risky cache operations in the plan builder (#23354) " └─Apply 4.00 root CARTESIAN left outer join", " ├─IndexReader(Build) 4.00 root index:IndexFullScan", " │ └─IndexFullScan 4.00 cop[tikv] table:t1, index:a(a, b) keep order:true", @@ -192,7 +197,7 @@ { "SQL": "select count(tmp.cmp) from (select t1.a as a, t1.b as b, (t1.b in (select t2.b from t2 where t2.a = t1.a limit 3)) as cmp from t1) tmp group by tmp.a, tmp.b", "Plan": [ - "StreamAgg 4.00 root group by:test.t1.a, test.t1.b, funcs:count(Column#7)->Column#8", + "StreamAgg 4.00 root group by:test.t1.a, test.t1.b, funcs:count(Column#10)->Column#11", "└─Apply 4.00 root left outer semi join, equal:[eq(test.t1.b, test.t2.b)]", " ├─IndexReader(Build) 4.00 root index:IndexFullScan", " │ └─IndexFullScan 4.00 cop[tikv] table:t1, index:a(a, b) keep order:true", @@ -205,7 +210,7 @@ { "SQL": "select count(tmp.cmp) from (select t1.a as a, t1.b as b, (t1.b not in (select t2.b from t2 where t2.a = t1.a limit 3)) as cmp from t1) tmp group by tmp.a, tmp.b", "Plan": [ - "StreamAgg 4.00 root group by:test.t1.a, test.t1.b, funcs:count(Column#7)->Column#8", + "StreamAgg 4.00 root group by:test.t1.a, test.t1.b, funcs:count(Column#10)->Column#11", "└─Apply 4.00 root anti left outer semi join, equal:[eq(test.t1.b, test.t2.b)]", " ├─IndexReader(Build) 4.00 root index:IndexFullScan", " │ └─IndexFullScan 4.00 cop[tikv] table:t1, index:a(a, b) keep order:true", @@ -240,7 +245,7 @@ { "SQL": "select count(tmp.cmp) from (select t1.a as a, t1.b as b, (t1.b in (select t2.b from t2 where t2.a > t1.a)) as cmp from t1) tmp group by tmp.a, tmp.b", "Plan": [ - "HashAgg 4.00 root group by:test.t1.a, test.t1.b, funcs:count(Column#7)->Column#8", + "HashAgg 4.00 root group by:test.t1.a, test.t1.b, funcs:count(Column#10)->Column#11", "└─HashJoin 4.00 root left outer semi join, equal:[eq(test.t1.b, test.t2.b)], other cond:gt(test.t2.a, test.t1.a)", " ├─TableReader(Build) 9.00 root data:TableFullScan", " │ └─TableFullScan 9.00 cop[tikv] table:t2 keep order:false", @@ -251,7 +256,7 @@ { "SQL": "select count(tmp.cmp) from (select t1.a as a, t1.b as b, (t1.b not in (select t2.b from t2 where t2.a > t1.a)) as cmp from t1) tmp group by tmp.a, tmp.b", "Plan": [ - "HashAgg 4.00 root group by:test.t1.a, test.t1.b, funcs:count(Column#7)->Column#8", + "HashAgg 4.00 root group by:test.t1.a, test.t1.b, funcs:count(Column#10)->Column#11", "└─HashJoin 4.00 root anti left outer semi join, equal:[eq(test.t1.b, test.t2.b)], other cond:gt(test.t2.a, test.t1.a)", " ├─TableReader(Build) 9.00 root data:TableFullScan", " │ └─TableFullScan 9.00 cop[tikv] table:t2 keep order:false", diff --git a/util/ranger/testdata/ranger_suite_out.json b/util/ranger/testdata/ranger_suite_out.json index c0127b7f76e2f..16e959a9fe320 100644 --- a/util/ranger/testdata/ranger_suite_out.json +++ b/util/ranger/testdata/ranger_suite_out.json @@ -5,11 +5,11 @@ { "SQL": "explain format = 'brief' 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 2.00 root Column#17", - "└─Apply 2.00 root CARTESIAN left outer semi join, other cond:eq(test.t.e, Column#16)", + "Projection 2.00 root Column#27", + "└─Apply 2.00 root CARTESIAN left outer semi join, other cond:eq(test.t.e, Column#26)", " ├─TableReader(Build) 2.00 root data:TableFullScan", " │ └─TableFullScan 2.00 cop[tikv] table:t keep order:false", - " └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#16", + " └─StreamAgg(Probe) 1.00 root funcs:count(1)->Column#26", " └─HashJoin 2.00 root inner join, equal:[eq(test.t.a, test.t.a)]", " ├─TableReader(Build) 2.00 root data:TableFullScan", " │ └─TableFullScan 2.00 cop[tikv] table:t1 keep order:false", From b438e5e829d1edc1b9c2f65e552451ee901df994 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Thu, 25 Mar 2021 15:29:37 +0800 Subject: [PATCH 2/5] fix CI --- cmd/explaintest/r/select.result | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/cmd/explaintest/r/select.result b/cmd/explaintest/r/select.result index 12671fe8c08c9..5810a3334304f 100644 --- a/cmd/explaintest/r/select.result +++ b/cmd/explaintest/r/select.result @@ -398,13 +398,8 @@ drop table if exists s; create table s(a varchar(20), b varchar(20)); explain format = 'brief' select a in (select a from s where s.b = t.b) from t; id estRows task access object operator info -<<<<<<< HEAD -HashJoin 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(Build) 10000.00 root test.s.a, cast(test.s.b, double BINARY)->Column#9 -======= -HashJoin 10000.00 root left outer semi join, equal:[eq(Column#11, Column#12)], other cond:eq(cast(test.t.a, double BINARY), cast(test.s.a, double BINARY)) +HashJoin 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(Build) 10000.00 root test.s.a, cast(test.s.b, double BINARY)->Column#12 ->>>>>>> 28c374849... planner: remove some risky cache operations in the plan builder (#23354) │ └─TableReader 10000.00 root data:TableFullScan │ └─TableFullScan 10000.00 cop[tikv] table:s keep order:false, stats:pseudo └─Projection(Probe) 10000.00 root test.t.a, cast(test.t.b, double BINARY)->Column#11 From 8c0ab9c39a966bf9c15fdb30b905c0051b17fe98 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Thu, 25 Mar 2021 15:46:16 +0800 Subject: [PATCH 3/5] fix ci --- planner/core/integration_test.go | 81 -------------------------------- 1 file changed, 81 deletions(-) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 6ca26a1038fc0..88b3d5375665e 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -2886,84 +2886,3 @@ func (s *testIntegrationSuite) TestIndexMergeTableFilter(c *C) { "10 1 1 10", )) } -<<<<<<< HEAD -======= - -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) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t1_no_idx;") - tk.MustExec("create table t1_no_idx(id int, col_bit bit(16));") - tk.MustExec("insert into t1_no_idx values(1, 0x3135);") - tk.MustExec("insert into t1_no_idx values(2, 0x0f);") - - tk.MustExec("prepare stmt from 'select id from t1_no_idx where col_bit = ?';") - tk.MustExec("set @a = 0x3135;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) - tk.MustExec("set @a = 0x0F;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("2")) - - // same test, but use IN expr - tk.MustExec("prepare stmt from 'select id from t1_no_idx where col_bit in (?)';") - tk.MustExec("set @a = 0x3135;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) - tk.MustExec("set @a = 0x0F;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("2")) - - // same test, but use table with index on col_bit - tk.MustExec("drop table if exists t2_idx;") - tk.MustExec("create table t2_idx(id int, col_bit bit(16), key(col_bit));") - tk.MustExec("insert into t2_idx values(1, 0x3135);") - tk.MustExec("insert into t2_idx values(2, 0x0f);") - - tk.MustExec("prepare stmt from 'select id from t2_idx where col_bit = ?';") - tk.MustExec("set @a = 0x3135;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) - tk.MustExec("set @a = 0x0F;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("2")) - - // same test, but use IN expr - tk.MustExec("prepare stmt from 'select id from t2_idx where col_bit in (?)';") - tk.MustExec("set @a = 0x3135;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) - tk.MustExec("set @a = 0x0F;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("2")) - - // test col varchar with GetVar - tk.MustExec("drop table if exists t_varchar;") - tk.MustExec("create table t_varchar(id int, col_varchar varchar(100), key(col_varchar));") - tk.MustExec("insert into t_varchar values(1, '15');") - tk.MustExec("prepare stmt from 'select id from t_varchar where col_varchar = ?';") - tk.MustExec("set @a = 0x3135;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) -} - -// test BitLiteral used with GetVar -func (s *testIntegrationSuite) TestGetVarExprWithBitLiteral(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test;") - tk.MustExec("drop table if exists t1_no_idx;") - tk.MustExec("create table t1_no_idx(id int, col_bit bit(16));") - tk.MustExec("insert into t1_no_idx values(1, 0x3135);") - tk.MustExec("insert into t1_no_idx values(2, 0x0f);") - - tk.MustExec("prepare stmt from 'select id from t1_no_idx where col_bit = ?';") - // 0b11000100110101 is 0x3135 - tk.MustExec("set @a = 0b11000100110101;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) - - // same test, but use IN expr - tk.MustExec("prepare stmt from 'select id from t1_no_idx where col_bit in (?)';") - tk.MustExec("set @a = 0b11000100110101;") - tk.MustQuery("execute stmt using @a;").Check(testkit.Rows("1")) -} ->>>>>>> 28c374849... planner: remove some risky cache operations in the plan builder (#23354) From 82dd0c4ed10a8546df4c3f7300eda32a736c6bf6 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Thu, 25 Mar 2021 21:31:17 +0800 Subject: [PATCH 4/5] fixup --- planner/core/testdata/stats_suite_out.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/planner/core/testdata/stats_suite_out.json b/planner/core/testdata/stats_suite_out.json index 07f4c00c0a1b7..1d08a9a52b1ff 100644 --- a/planner/core/testdata/stats_suite_out.json +++ b/planner/core/testdata/stats_suite_out.json @@ -179,13 +179,8 @@ { "SQL": "select count(tmp.cmp) from (select t1.a as a, t1.b as b, (t1.b > (select t2.b from t2 where t2.a = t1.a)) as cmp from t1) tmp group by tmp.a, tmp.b", "Plan": [ -<<<<<<< HEAD - "StreamAgg 4.00 root group by:test.t1.a, test.t1.b, funcs:count(Column#7)->Column#8", - "└─Projection 4.00 root test.t1.a, test.t1.b, gt(test.t1.b, test.t2.b)->Column#7", -======= "StreamAgg 4.00 root group by:Column#14, Column#15, funcs:count(Column#13)->Column#11", "└─Projection 4.00 root gt(test.t1.b, test.t2.b)->Column#13, test.t1.a, test.t1.b", ->>>>>>> 28c374849... planner: remove some risky cache operations in the plan builder (#23354) " └─Apply 4.00 root CARTESIAN left outer join", " ├─IndexReader(Build) 4.00 root index:IndexFullScan", " │ └─IndexFullScan 4.00 cop[tikv] table:t1, index:a(a, b) keep order:true", From 2329c9a59116582890dced992c655f8a2af6dbdf Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Fri, 26 Mar 2021 11:40:07 +0800 Subject: [PATCH 5/5] fix ci --- planner/core/testdata/stats_suite_out.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/planner/core/testdata/stats_suite_out.json b/planner/core/testdata/stats_suite_out.json index 1d08a9a52b1ff..fdaba101a73a0 100644 --- a/planner/core/testdata/stats_suite_out.json +++ b/planner/core/testdata/stats_suite_out.json @@ -179,8 +179,8 @@ { "SQL": "select count(tmp.cmp) from (select t1.a as a, t1.b as b, (t1.b > (select t2.b from t2 where t2.a = t1.a)) as cmp from t1) tmp group by tmp.a, tmp.b", "Plan": [ - "StreamAgg 4.00 root group by:Column#14, Column#15, funcs:count(Column#13)->Column#11", - "└─Projection 4.00 root gt(test.t1.b, test.t2.b)->Column#13, test.t1.a, test.t1.b", + "StreamAgg 4.00 root group by:test.t1.a, test.t1.b, funcs:count(Column#10)->Column#11", + "└─Projection 4.00 root test.t1.a, test.t1.b, gt(test.t1.b, test.t2.b)->Column#10", " └─Apply 4.00 root CARTESIAN left outer join", " ├─IndexReader(Build) 4.00 root index:IndexFullScan", " │ └─IndexFullScan 4.00 cop[tikv] table:t1, index:a(a, b) keep order:true",