Skip to content

Commit

Permalink
planner: remove some risky cache operations in the plan builder (#23354)
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 authored Mar 18, 2021
1 parent 411dba2 commit 28c3748
Show file tree
Hide file tree
Showing 18 changed files with 196 additions and 217 deletions.
122 changes: 61 additions & 61 deletions cmd/explaintest/r/explain_easy.result

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions cmd/explaintest/r/explain_easy_stats.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions cmd/explaintest/r/select.result
Original file line number Diff line number Diff line change
Expand Up @@ -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), <nil>, 0)), and(ne(Column#10, 0), if(isnull(test.t.a), <nil>, 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), <nil>, 0)), and(ne(Column#13, 0), if(isnull(test.t.a), <nil>, 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), <nil>, 1)), or(eq(Column#10, 0), if(isnull(test.t.a), <nil>, 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), <nil>, 1)), or(eq(Column#13, 0), if(isnull(test.t.a), <nil>, 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
Expand All @@ -398,11 +398,11 @@ 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
HashJoin 10000.00 root left outer semi join, equal:[eq(Column#8, Column#9)], 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#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
│ └─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;
Expand Down
6 changes: 3 additions & 3 deletions cmd/explaintest/r/subquery.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/explaintest/r/tpch.result
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,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
Expand Down
4 changes: 2 additions & 2 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6643,7 +6643,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
Expand All @@ -6663,7 +6663,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++ {
Expand Down
12 changes: 6 additions & 6 deletions executor/testdata/agg_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nil>->Column#10",
" │ │ └─Projection(Probe) 1.00 root <nil>->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 <nil>->Column#11",
" │ └─Projection(Probe) 1.00 root <nil>->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 <nil>->Column#12",
" └─Projection(Probe) 1.00 root <nil>->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",
Expand Down
64 changes: 32 additions & 32 deletions planner/cascades/testdata/integration_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
24 changes: 12 additions & 12 deletions planner/cascades/testdata/stringer_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
Expand Down
Loading

0 comments on commit 28c3748

Please sign in to comment.