Skip to content

Commit

Permalink
Merge branch 'master' into fix-sysvar-inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
morgo authored May 31, 2021
2 parents b86105a + a80047c commit 0664c0f
Show file tree
Hide file tree
Showing 32 changed files with 899 additions and 162 deletions.
129 changes: 129 additions & 0 deletions cmd/explaintest/r/explain_cte.result
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
31 changes: 31 additions & 0 deletions cmd/explaintest/t/explain_cte.test
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);
21 changes: 0 additions & 21 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ type Config struct {
DelayCleanTableLock uint64 `toml:"delay-clean-table-lock" json:"delay-clean-table-lock"`
SplitRegionMaxNum uint64 `toml:"split-region-max-num" json:"split-region-max-num"`
StmtSummary StmtSummary `toml:"stmt-summary" json:"stmt-summary"`
TopSQL TopSQL `toml:"top-sql" json:"top-sql"`
// RepairMode indicates that the TiDB is in the repair mode for table meta.
RepairMode bool `toml:"repair-mode" json:"repair-mode"`
RepairTableList []string `toml:"repair-table-list" json:"repair-table-list"`
Expand Down Expand Up @@ -527,16 +526,6 @@ type StmtSummary struct {
HistorySize int `toml:"history-size" json:"history-size"`
}

// TopSQL is the config for top sql.
type TopSQL struct {
// Enable statement summary or not.
Enable bool `toml:"enable" json:"enable"`
// The refresh interval of statement summary.
RefreshInterval int `toml:"refresh-interval" json:"refresh-interval"`
// The maximum number of statements kept in memory.
MaxStmtCount uint `toml:"max-stmt-count" json:"max-stmt-count"`
}

// IsolationRead is the config for isolation read.
type IsolationRead struct {
// Engines filters tidb-server access paths by engine type.
Expand Down Expand Up @@ -666,11 +655,6 @@ var defaultConf = Config{
RefreshInterval: 1800,
HistorySize: 24,
},
TopSQL: TopSQL{
Enable: true,
RefreshInterval: 1,
MaxStmtCount: 5000,
},
IsolationRead: IsolationRead{
Engines: []string{"tikv", "tiflash", "tidb"},
},
Expand Down Expand Up @@ -958,11 +942,6 @@ func TableLockEnabled() bool {
return GetGlobalConfig().EnableTableLock
}

// TopSQLEnabled uses to check whether enabled the top SQL feature.
func TopSQLEnabled() bool {
return GetGlobalConfig().TopSQL.Enable
}

// TableLockDelayClean uses to get the time of delay clean table lock.
var TableLockDelayClean = func() uint64 {
return GetGlobalConfig().DelayCleanTableLock
Expand Down
7 changes: 7 additions & 0 deletions ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,13 @@ func (s *testSerialSuite) TestCreateTableWithLike(c *C) {
_, err = tk.Exec("create table temporary_table_t1 like temporary_table")
c.Assert(err.Error(), Equals, core.ErrOptOnTemporaryTable.GenWithStackByArgs("create table like").Error())
tk.MustExec("drop table if exists temporary_table;")

tk.MustExec("drop table if exists temporary_table_like;")
tk.MustExec("create table temporary_table (a int, b int,index(a))")
tk.MustExec("drop table if exists temporary_table_like_t1;")
_, err = tk.Exec("create global temporary table temporary_table_like_t1 like temporary_table on commit delete rows;")
c.Assert(err.Error(), Equals, core.ErrOptOnTemporaryTable.GenWithStackByArgs("create table like").Error())
tk.MustExec("drop table if exists temporary_table_like;")
}

// TestCancelAddIndex1 tests canceling ddl job when the add index worker is not started.
Expand Down
3 changes: 1 addition & 2 deletions distsql/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl/placement"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
Expand Down Expand Up @@ -278,7 +277,7 @@ func (builder *RequestBuilder) SetFromInfoSchema(pis interface{}) *RequestBuilde

// SetResourceGroupTag sets the request resource group tag.
func (builder *RequestBuilder) SetResourceGroupTag(sc *stmtctx.StatementContext) *RequestBuilder {
if config.TopSQLEnabled() {
if variable.TopSQLEnabled() {
builder.Request.ResourceGroupTag = sc.GetResourceGroupTag()
}
return builder
Expand Down
Loading

0 comments on commit 0664c0f

Please sign in to comment.