-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CTE: support explain CTE plan (#24986)
- Loading branch information
1 parent
7af4fea
commit a80047c
Showing
9 changed files
with
292 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
use test; | ||
drop table if exists t1, t2; | ||
create table t1 (c1 int primary key, c2 int, index c2 (c2)); | ||
create table t2 (c1 int unique, c2 int); | ||
insert into t1 values(1, 0), (2, 1); | ||
insert into t2 values(1, 0), (2, 1); | ||
explain with cte(a) as (select 1) select * from cte; | ||
id estRows task access object operator info | ||
CTEFullScan_8 1.00 root CTE:cte data:CTE_0 | ||
CTE_0 1.00 root None Recursive CTE | ||
└─Projection_6(Seed Part) 1.00 root 1->Column#1 | ||
└─TableDual_7 1.00 root rows:1 | ||
explain with cte(a) as (select c1 from t1) select * from cte; | ||
id estRows task access object operator info | ||
CTEFullScan_11 1.00 root CTE:cte data:CTE_0 | ||
CTE_0 1.00 root None Recursive CTE | ||
└─TableReader_8(Seed Part) 10000.00 root data:TableFullScan_7 | ||
└─TableFullScan_7 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo | ||
explain with cte(a,b,c,d) as (select * from t1, t2) select * from cte; | ||
id estRows task access object operator info | ||
CTEFullScan_18 1.00 root CTE:cte data:CTE_0 | ||
CTE_0 1.00 root None Recursive CTE | ||
└─HashJoin_10(Seed Part) 100000000.00 root CARTESIAN inner join | ||
├─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 with recursive cte(a) as (select 1 union select a+1 from cte where a < 10) select * from cte; | ||
id estRows task access object operator info | ||
CTEFullScan_17 1.00 root CTE:cte data:CTE_0 | ||
CTE_0 1.00 root Recursive CTE | ||
├─Projection_12(Seed Part) 1.00 root 1->Column#2 | ||
│ └─TableDual_13 1.00 root rows:1 | ||
└─Projection_14(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5 | ||
└─Selection_15 0.80 root lt(Column#3, 10) | ||
└─CTETable_16 1.00 root Scan on CTE_0 | ||
explain with recursive cte(a) as (select c2 from t1 union select a+1 from cte where a < 10) select * from cte; | ||
id estRows task access object operator info | ||
CTEFullScan_20 1.00 root CTE:cte data:CTE_0 | ||
CTE_0 1.00 root Recursive CTE | ||
├─TableReader_14(Seed Part) 10000.00 root data:TableFullScan_13 | ||
│ └─TableFullScan_13 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo | ||
└─Projection_17(Recursive Part) 0.80 root cast(plus(test.t1.c2, 1), int(11))->test.t1.c2 | ||
└─Selection_18 0.80 root lt(test.t1.c2, 10) | ||
└─CTETable_19 1.00 root Scan on CTE_0 | ||
explain with cte(a) as (with recursive cte1(a) as (select 1 union select a + 1 from cte1 where a < 10) select * from cte1) select * from cte; | ||
id estRows task access object operator info | ||
CTEFullScan_21 1.00 root CTE:cte data:CTE_0 | ||
CTE_0 1.00 root None Recursive CTE | ||
└─CTEFullScan_20(Seed Part) 1.00 root CTE:cte1 data:CTE_1 | ||
CTE_1 1.00 root Recursive CTE | ||
├─Projection_15(Seed Part) 1.00 root 1->Column#2 | ||
│ └─TableDual_16 1.00 root rows:1 | ||
└─Projection_17(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5 | ||
└─Selection_18 0.80 root lt(Column#3, 10) | ||
└─CTETable_19 1.00 root Scan on CTE_1 | ||
explain with recursive cte(a) as (select 1 union select a+1 from cte where a < 10) select * from cte t1, cte t2; | ||
id estRows task access object operator info | ||
HashJoin_15 1.00 root CARTESIAN inner join | ||
├─CTEFullScan_23(Build) 1.00 root CTE:t2 data:CTE_0 | ||
└─CTEFullScan_22(Probe) 1.00 root CTE:t1 data:CTE_0 | ||
CTE_0 1.00 root Recursive CTE | ||
├─Projection_17(Seed Part) 1.00 root 1->Column#2 | ||
│ └─TableDual_18 1.00 root rows:1 | ||
└─Projection_19(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5 | ||
└─Selection_20 0.80 root lt(Column#3, 10) | ||
└─CTETable_21 1.00 root Scan on CTE_0 | ||
explain with cte(a) as (with recursive cte1(a) as (select 1 union select a + 1 from cte1 where a < 10) select * from cte1) select * from cte t1, cte t2; | ||
id estRows task access object operator info | ||
HashJoin_17 1.00 root CARTESIAN inner join | ||
├─CTEFullScan_27(Build) 1.00 root CTE:t2 data:CTE_0 | ||
└─CTEFullScan_26(Probe) 1.00 root CTE:t1 data:CTE_0 | ||
CTE_0 1.00 root None Recursive CTE | ||
└─CTEFullScan_25(Seed Part) 1.00 root CTE:cte1 data:CTE_1 | ||
CTE_1 1.00 root Recursive CTE | ||
├─Projection_20(Seed Part) 1.00 root 1->Column#2 | ||
│ └─TableDual_21 1.00 root rows:1 | ||
└─Projection_22(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5 | ||
└─Selection_23 0.80 root lt(Column#3, 10) | ||
└─CTETable_24 1.00 root Scan on CTE_1 | ||
explain with recursive cte1(a) as (select 1 union select a+1 from cte1 where a < 10), cte2(a) as (select c2 from t1 union select a+1 from cte2 where a < 10) select * from cte1, cte2; | ||
id estRows task access object operator info | ||
HashJoin_23 1.00 root CARTESIAN inner join | ||
├─CTEFullScan_39(Build) 1.00 root CTE:cte2 data:CTE_1 | ||
└─CTEFullScan_30(Probe) 1.00 root CTE:cte1 data:CTE_0 | ||
CTE_1 1.00 root Recursive CTE | ||
├─TableReader_33(Seed Part) 10000.00 root data:TableFullScan_32 | ||
│ └─TableFullScan_32 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo | ||
└─Projection_36(Recursive Part) 0.80 root cast(plus(test.t1.c2, 1), int(11))->test.t1.c2 | ||
└─Selection_37 0.80 root lt(test.t1.c2, 10) | ||
└─CTETable_38 1.00 root Scan on CTE_1 | ||
CTE_0 1.00 root Recursive CTE | ||
├─Projection_25(Seed Part) 1.00 root 1->Column#2 | ||
│ └─TableDual_26 1.00 root rows:1 | ||
└─Projection_27(Recursive Part) 0.80 root cast(plus(Column#3, 1), bigint(1) BINARY)->Column#5 | ||
└─Selection_28 0.80 root lt(Column#3, 10) | ||
└─CTETable_29 1.00 root Scan on CTE_0 | ||
explain with q(a,b) as (select * from t1) select /*+ merge(q) no_merge(q1) */ * from q, q q1 where q.a=1 and q1.a=2; | ||
id estRows task access object operator info | ||
HashJoin_12 0.64 root CARTESIAN inner join | ||
├─Selection_21(Build) 0.80 root eq(test.t1.c1, 2) | ||
│ └─CTEFullScan_22 1.00 root CTE:q1 data:CTE_0 | ||
└─Selection_14(Probe) 0.80 root eq(test.t1.c1, 1) | ||
└─CTEFullScan_20 1.00 root CTE:q data:CTE_0 | ||
CTE_0 1.00 root None Recursive CTE | ||
└─TableReader_17(Seed Part) 10000.00 root data:TableFullScan_16 | ||
└─TableFullScan_16 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo | ||
explain with recursive cte(a,b) as (select 1, concat('a', 1) union select a+1, concat(b, 1) from cte where a < 5) select * from cte; | ||
id estRows task access object operator info | ||
CTEFullScan_17 1.00 root CTE:cte data:CTE_0 | ||
CTE_0 1.00 root Recursive CTE | ||
├─Projection_12(Seed Part) 1.00 root 1->Column#3, a1->Column#4 | ||
│ └─TableDual_13 1.00 root rows:1 | ||
└─Projection_14(Recursive Part) 0.80 root cast(plus(Column#5, 1), bigint(1) BINARY)->Column#9, cast(concat(Column#6, 1), var_string(21))->Column#10 | ||
└─Selection_15 0.80 root lt(Column#5, 5) | ||
└─CTETable_16 1.00 root Scan on CTE_0 | ||
explain select * from t1 dt where exists(with recursive qn as (select c1*0+1 as b union all select b+1 from qn where b=0) select * from qn where b=1); | ||
id estRows task access object operator info | ||
Apply_19 10000.00 root CARTESIAN semi join | ||
├─TableReader_21(Build) 10000.00 root data:TableFullScan_20 | ||
│ └─TableFullScan_20 10000.00 cop[tikv] table:dt keep order:false, stats:pseudo | ||
└─Selection_24(Probe) 0.80 root eq(Column#8, 1) | ||
└─CTEFullScan_30 1.00 root CTE:qn data:CTE_0 | ||
CTE_0 1.00 root Recursive CTE | ||
├─Projection_25(Seed Part) 1.00 root plus(mul(test.t1.c1, 0), 1)->Column#4 | ||
│ └─TableDual_26 1.00 root rows:1 | ||
└─Projection_27(Recursive Part) 0.80 root plus(Column#5, 1)->Column#7 | ||
└─Selection_28 0.80 root eq(Column#5, 0) | ||
└─CTETable_29 1.00 root Scan on CTE_0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use test; | ||
drop table if exists t1, t2; | ||
create table t1 (c1 int primary key, c2 int, index c2 (c2)); | ||
create table t2 (c1 int unique, c2 int); | ||
insert into t1 values(1, 0), (2, 1); | ||
insert into t2 values(1, 0), (2, 1); | ||
|
||
# simple cte | ||
explain with cte(a) as (select 1) select * from cte; | ||
explain with cte(a) as (select c1 from t1) select * from cte; | ||
explain with cte(a,b,c,d) as (select * from t1, t2) select * from cte; | ||
|
||
# recursive cte | ||
explain with recursive cte(a) as (select 1 union select a+1 from cte where a < 10) select * from cte; | ||
explain with recursive cte(a) as (select c2 from t1 union select a+1 from cte where a < 10) select * from cte; | ||
|
||
# nested cte | ||
explain with cte(a) as (with recursive cte1(a) as (select 1 union select a + 1 from cte1 where a < 10) select * from cte1) select * from cte; | ||
|
||
# cte with join | ||
explain with recursive cte(a) as (select 1 union select a+1 from cte where a < 10) select * from cte t1, cte t2; | ||
explain with cte(a) as (with recursive cte1(a) as (select 1 union select a + 1 from cte1 where a < 10) select * from cte1) select * from cte t1, cte t2; | ||
|
||
# multiple cte | ||
explain with recursive cte1(a) as (select 1 union select a+1 from cte1 where a < 10), cte2(a) as (select c2 from t1 union select a+1 from cte2 where a < 10) select * from cte1, cte2; | ||
|
||
# other | ||
explain with q(a,b) as (select * from t1) select /*+ merge(q) no_merge(q1) */ * from q, q q1 where q.a=1 and q1.a=2; | ||
# explain with cte(a,b) as (select * from t1) select (select 1 from cte limit 1) from cte; | ||
explain with recursive cte(a,b) as (select 1, concat('a', 1) union select a+1, concat(b, 1) from cte where a < 5) select * from cte; | ||
explain select * from t1 dt where exists(with recursive qn as (select c1*0+1 as b union all select b+1 from qn where b=0) select * from qn where b=1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.