Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into rename_recreator
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelice committed Oct 15, 2021
2 parents 7b2fbcf + ac9dcbb commit e43f5c4
Show file tree
Hide file tree
Showing 25 changed files with 625 additions and 106 deletions.
11 changes: 11 additions & 0 deletions cmd/explaintest/r/new_character_set_builtin.result
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ select hex(a), hex(b), hex(c) from t;
hex(a) hex(b) hex(c)
E4B880E4BA8CE4B889 D2BBB6FEC8FD E4B880E4BA8CE4B8890000000000000000000000
set @@tidb_enable_vectorized_expression = false;
drop table if exists t;
create table t (a char(100) charset utf8mb4, b char(100) charset gbk);
insert into t values ('àáèéêìíòóùúüāēěīńňōūǎǐǒǔǖǘǚǜⅪⅫ', 'àáèéêìíòóùúüāēěīńňōūǎǐǒǔǖǘǚǜⅪⅫ');
select upper(a), upper(b) from t;
upper(a) upper(b)
ÀÁÈÉÊÌÍÒÓÙÚÜĀĒĚĪŃŇŌŪǍǏǑǓǕǗǙǛⅪⅫ àáèéêìíòóùúüāēěīńňōūǎǐǒǔǖǘǚǜⅪⅫ
set @@tidb_enable_vectorized_expression = true;
select upper(a), upper(b) from t;
upper(a) upper(b)
ÀÁÈÉÊÌÍÒÓÙÚÜĀĒĚĪŃŇŌŪǍǏǑǓǕǗǙǛⅪⅫ àáèéêìíòóùúüāēěīńňōūǎǐǒǔǖǘǚǜⅪⅫ
set @@tidb_enable_vectorized_expression = false;
10 changes: 10 additions & 0 deletions cmd/explaintest/t/new_character_set_builtin.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@ select hex(a), hex(b), hex(c) from t;
set @@tidb_enable_vectorized_expression = true;
select hex(a), hex(b), hex(c) from t;
set @@tidb_enable_vectorized_expression = false;

-- test for builtin function upper()
drop table if exists t;
create table t (a char(100) charset utf8mb4, b char(100) charset gbk);
insert into t values ('àáèéêìíòóùúüāēěīńňōūǎǐǒǔǖǘǚǜⅪⅫ', 'àáèéêìíòóùúüāēěīńňōūǎǐǒǔǖǘǚǜⅪⅫ');
select upper(a), upper(b) from t;
set @@tidb_enable_vectorized_expression = true;
select upper(a), upper(b) from t;
set @@tidb_enable_vectorized_expression = false;

15 changes: 15 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,21 @@ func checkTableInfoValidWithStmt(ctx sessionctx.Context, tbInfo *model.TableInfo
}
tbInfo.PlacementPolicyRef.ID = policy.ID
}

if tbInfo.Partition != nil {
for _, partition := range tbInfo.Partition.Definitions {
if partition.PlacementPolicyRef == nil {
continue
}

policy, ok := ctx.GetInfoSchema().(infoschema.InfoSchema).PolicyByName(partition.PlacementPolicyRef.Name)
if !ok {
return errors.Trace(infoschema.ErrPlacementPolicyNotExists.GenWithStackByArgs(partition.PlacementPolicyRef.Name))
}
partition.PlacementPolicyRef.ID = policy.ID
}
}

return nil
}

Expand Down
47 changes: 45 additions & 2 deletions ddl/placement_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (s *testDBSuite6) TestAlterPlacementPolicy(c *C) {
func (s *testDBSuite6) TestCreateTableWithPlacementPolicy(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("drop table if exists t,t2")

// Direct placement option: special constraints may be incompatible with common constraint.
_, err := tk.Exec("create table t(a int) " +
Expand Down Expand Up @@ -301,17 +301,59 @@ func (s *testDBSuite6) TestCreateTableWithPlacementPolicy(c *C) {
tk.MustExec("create placement policy x " +
"FOLLOWERS=2 " +
"CONSTRAINTS=\"[+disk=ssd]\" ")
tk.MustExec("create placement policy y " +
"FOLLOWERS=3 " +
"CONSTRAINTS=\"[+region=bj]\" ")
tk.MustExec("create table t(a int)" +
"PLACEMENT POLICY=\"x\"")
tk.MustExec("create table t2(id int) placement policy x partition by range(id) (" +
"PARTITION p0 VALUES LESS THAN (100)," +
"PARTITION p1 VALUES LESS THAN (1000) placement policy y," +
"PARTITION p2 VALUES LESS THAN (10000) PRIMARY_REGION=\"cn-east-1\" REGIONS=\"cn-east-1, cn-east-2\" FOLLOWERS=2 )",
)

policyX := testGetPolicyByName(c, tk.Se, "x", true)
c.Assert(policyX.Name.L, Equals, "x")
c.Assert(policyX.ID != 0, Equals, true)

policyY := testGetPolicyByName(c, tk.Se, "y", true)
c.Assert(policyY.Name.L, Equals, "y")
c.Assert(policyY.ID != 0, Equals, true)

tbl = testGetTableByName(c, tk.Se, "test", "t")
c.Assert(tbl, NotNil)
c.Assert(tbl.Meta().PlacementPolicyRef, NotNil)
c.Assert(tbl.Meta().PlacementPolicyRef.Name.L, Equals, "x")
c.Assert(tbl.Meta().PlacementPolicyRef.ID != 0, Equals, true)
c.Assert(tbl.Meta().PlacementPolicyRef.ID, Equals, policyX.ID)
tk.MustQuery("SELECT * FROM information_schema.placement_rules WHERE TABLE_NAME = 't'").Check(testkit.Rows())
tk.MustExec("drop table if exists t")

tbl = testGetTableByName(c, tk.Se, "test", "t2")
c.Assert(tbl, NotNil)
c.Assert(tbl.Meta().PlacementPolicyRef, NotNil)
c.Assert(tbl.Meta().PlacementPolicyRef.Name.L, Equals, "x")
c.Assert(tbl.Meta().PlacementPolicyRef.ID, Equals, policyX.ID)
c.Assert(tbl.Meta().DirectPlacementOpts, IsNil)

c.Assert(tbl.Meta().Partition, NotNil)
c.Assert(len(tbl.Meta().Partition.Definitions), Equals, 3)

p0 := tbl.Meta().Partition.Definitions[0]
c.Assert(p0.PlacementPolicyRef, IsNil)
c.Assert(p0.DirectPlacementOpts, IsNil)

p1 := tbl.Meta().Partition.Definitions[1]
c.Assert(p1.PlacementPolicyRef, NotNil)
c.Assert(p1.PlacementPolicyRef.Name.L, Equals, "y")
c.Assert(p1.PlacementPolicyRef.ID, Equals, policyY.ID)
c.Assert(p1.DirectPlacementOpts, IsNil)

p2 := tbl.Meta().Partition.Definitions[2]
c.Assert(p0.PlacementPolicyRef, IsNil)
checkFunc(p2.DirectPlacementOpts)

tk.MustExec("drop table if exists t2")

tk.MustExec("create table t(a int)" +
"FOLLOWERS=2 " +
"CONSTRAINTS=\"[+disk=ssd]\" ")
Expand All @@ -336,6 +378,7 @@ func (s *testDBSuite6) TestCreateTableWithPlacementPolicy(c *C) {
tk.MustQuery("SELECT * FROM information_schema.placement_rules WHERE TABLE_NAME = 't'").Check(testkit.Rows("<nil> def <nil> test t <nil> [+disk=ssd] 2 0"))
tk.MustExec("drop table if exists t")
tk.MustExec("drop placement policy if exists x")
tk.MustExec("drop placement policy if exists y")
}

func (s *testDBSuite6) TestDropPlacementPolicyInUse(c *C) {
Expand Down
1 change: 1 addition & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ func (b *executorBuilder) buildShow(v *plannercore.PhysicalShow) Executor {
Tp: v.Tp,
DBName: model.NewCIStr(v.DBName),
Table: v.Table,
Partition: v.Partition,
Column: v.Column,
IndexName: v.IndexName,
Flag: v.Flag,
Expand Down
68 changes: 68 additions & 0 deletions executor/explainfor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,3 +816,71 @@ func (s *testPrepareSerialSuite) TestIssue28696(c *C) {
c.Assert(res.Rows()[3][0], Matches, ".*Selection.*")
c.Assert(res.Rows()[4][0], Matches, ".*TableRowIDScan.*")
}

func (s *testPrepareSerialSuite) TestIssue28710(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)

orgEnable := core.PreparedPlanCacheEnabled()
defer func() {
core.SetPreparedPlanCache(orgEnable)
}()
core.SetPreparedPlanCache(true)

var err error
tk.Se, err = session.CreateSession4TestWithOpt(s.store, &session.Opt{
PreparedPlanCache: kvcache.NewSimpleLRUCache(100, 0.1, math.MaxUint64),
})
c.Assert(err, IsNil)

tk.MustExec("use test")
tk.MustExec("set @@tidb_enable_collect_execution_info=0;")
tk.MustExec("drop table if exists IDT_MULTI15858STROBJSTROBJ;")
tk.MustExec("CREATE TABLE `IDT_MULTI15858STROBJSTROBJ` (" +
"`COL1` enum('aa','bb','cc','dd','ee','ff','gg','hh','ii','mm') DEFAULT NULL," +
"`COL2` int(41) DEFAULT NULL," +
"`COL3` datetime DEFAULT NULL," +
"KEY `U_M_COL4` (`COL1`,`COL2`)," +
"KEY `U_M_COL5` (`COL3`,`COL2`)" +
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;")
tk.MustExec("insert into IDT_MULTI15858STROBJSTROBJ values('aa', 1333053589,'1037-12-26 01:38:52');")

tk.MustExec("set tidb_enable_index_merge=on;")
tk.MustExec("prepare stmt from 'select * from IDT_MULTI15858STROBJSTROBJ where col2 <> ? and col1 not in (?, ?, ?) or col3 = ? order by 2;';")
tk.MustExec("set @a=2134549621, @b='aa', @c='aa', @d='aa', @e='9941-07-07 01:08:48';")
tk.MustQuery("execute stmt using @a,@b,@c,@d,@e;").Check(testkit.Rows())

tk.MustExec("set @a=-2144294194, @b='mm', @c='mm', @d='mm', @e='0198-09-29 20:19:49';")
tk.MustQuery("execute stmt using @a,@b,@c,@d,@e;").Check(testkit.Rows("aa 1333053589 1037-12-26 01:38:52"))
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1"))
tk.MustQuery("execute stmt using @a,@b,@c,@d,@e;").Check(testkit.Rows("aa 1333053589 1037-12-26 01:38:52"))

tkProcess := tk.Se.ShowProcess()
ps := []*util.ProcessInfo{tkProcess}
tk.Se.SetSessionManager(&mockSessionManager1{PS: ps})
res := tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
c.Assert(len(res.Rows()), Equals, 6)
c.Assert(res.Rows()[1][0], Matches, ".*IndexMerge.*")
c.Assert(res.Rows()[3][0], Matches, ".*IndexRangeScan.*")
c.Assert(res.Rows()[3][4], Equals, "range:(NULL,\"mm\"), (\"mm\",+inf], keep order:false, stats:pseudo")
c.Assert(res.Rows()[4][0], Matches, ".*IndexRangeScan.*")
c.Assert(res.Rows()[4][4], Equals, "range:[0198-09-29 20:19:49,0198-09-29 20:19:49], keep order:false, stats:pseudo")

// test for cluster index in indexMerge
tk.MustExec("drop table if exists t;")
tk.MustExec("set @@tidb_enable_clustered_index = 1;")
tk.MustExec("create table t(a int, b int, c int, primary key(a), index idx_b(b));")
tk.MustExec("prepare stmt from 'select * from t where ((a > ? and a < ?) or b > 1) and c > 1;';")
tk.MustExec("set @a = 0, @b = 3;")
tk.MustQuery("execute stmt using @a, @b;").Check(testkit.Rows())

tkProcess = tk.Se.ShowProcess()
ps = []*util.ProcessInfo{tkProcess}
tk.Se.SetSessionManager(&mockSessionManager1{PS: ps})
res = tk.MustQuery("explain for connection " + strconv.FormatUint(tkProcess.ID, 10))
c.Assert(len(res.Rows()), Equals, 5)
c.Assert(res.Rows()[0][0], Matches, ".*IndexMerge.*")
c.Assert(res.Rows()[1][0], Matches, ".*TableRangeScan.*")
c.Assert(res.Rows()[1][4], Equals, "range:(0,3), keep order:false, stats:pseudo")
c.Assert(res.Rows()[2][0], Matches, ".*IndexRangeScan.*")
c.Assert(res.Rows()[2][4], Equals, "range:(1,+inf], keep order:false, stats:pseudo")
}
5 changes: 1 addition & 4 deletions executor/memtable_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,8 @@ func fetchClusterConfig(sctx sessionctx.Context, nodeTypes, nodeAddrs set.String
switch typ {
case "pd":
url = fmt.Sprintf("%s://%s%s", util.InternalHTTPSchema(), statusAddr, pdapi.Config)
case "tikv", "tidb":
case "tikv", "tidb", "tiflash":
url = fmt.Sprintf("%s://%s/config", util.InternalHTTPSchema(), statusAddr)
case "tiflash":
// TODO: support show tiflash config once tiflash supports it
return
default:
ch <- result{err: errors.Errorf("currently we do not support get config from node type: %s(%s)", typ, address)}
return
Expand Down
24 changes: 19 additions & 5 deletions executor/memtable_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ func (s *testMemTableReaderSuite) TestTiDBClusterConfig(c *C) {
"tikv key1 value1",
"tikv key2.nest1 n-value1",
"tikv key2.nest2 n-value2",
"tiflash key1 value1",
"tiflash key2.nest1 n-value1",
"tiflash key2.nest2 n-value2",
"tiflash key1 value1",
"tiflash key2.nest1 n-value1",
"tiflash key2.nest2 n-value2",
"tiflash key1 value1",
"tiflash key2.nest1 n-value1",
"tiflash key2.nest2 n-value2",
"pd key1 value1",
"pd key2.nest1 n-value1",
"pd key2.nest2 n-value2",
Expand All @@ -213,7 +222,7 @@ func (s *testMemTableReaderSuite) TestTiDBClusterConfig(c *C) {
))
warnings := tk.Se.GetSessionVars().StmtCtx.GetWarnings()
c.Assert(len(warnings), Equals, 0, Commentf("unexpected warnigns: %+v", warnings))
c.Assert(requestCounter, Equals, int32(9))
c.Assert(requestCounter, Equals, int32(12))

// TODO: we need remove it when index usage is GA.
rs := tk.MustQuery("show config").Rows()
Expand All @@ -226,7 +235,7 @@ func (s *testMemTableReaderSuite) TestTiDBClusterConfig(c *C) {

// type => server index => row
rows := map[string][][]string{}
for _, typ := range []string{"tidb", "tikv", "pd"} {
for _, typ := range []string{"tidb", "tikv", "tiflash", "pd"} {
for _, server := range testServers {
rows[typ] = append(rows[typ], []string{
fmt.Sprintf("%s %s key1 value1", typ, server.address),
Expand All @@ -249,14 +258,17 @@ func (s *testMemTableReaderSuite) TestTiDBClusterConfig(c *C) {
}{
{
sql: "select * from information_schema.cluster_config",
reqCount: 9,
reqCount: 12,
rows: flatten(
rows["tidb"][0],
rows["tidb"][1],
rows["tidb"][2],
rows["tikv"][0],
rows["tikv"][1],
rows["tikv"][2],
rows["tiflash"][0],
rows["tiflash"][1],
rows["tiflash"][2],
rows["pd"][0],
rows["pd"][1],
rows["pd"][2],
Expand All @@ -276,10 +288,11 @@ func (s *testMemTableReaderSuite) TestTiDBClusterConfig(c *C) {
},
{
sql: "select * from information_schema.cluster_config where type='pd' or instance='" + testServers[0].address + "'",
reqCount: 9,
reqCount: 12,
rows: flatten(
rows["tidb"][0],
rows["tikv"][0],
rows["tiflash"][0],
rows["pd"][0],
rows["pd"][1],
rows["pd"][2],
Expand Down Expand Up @@ -355,10 +368,11 @@ func (s *testMemTableReaderSuite) TestTiDBClusterConfig(c *C) {
{
sql: fmt.Sprintf(`select * from information_schema.cluster_config where instance='%s'`,
testServers[0].address),
reqCount: 3,
reqCount: 4,
rows: flatten(
rows["tidb"][0],
rows["tikv"][0],
rows["tiflash"][0],
rows["pd"][0],
),
},
Expand Down
2 changes: 1 addition & 1 deletion executor/plan_replayer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 PingCAP, Inc.
// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
3 changes: 3 additions & 0 deletions executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type ShowExec struct {
Tp ast.ShowStmtType // Databases/Tables/Columns/....
DBName model.CIStr
Table *ast.TableName // Used for showing columns.
Partition model.CIStr // Used for showing partition
Column *ast.ColumnName // Used for `desc table column`.
IndexName model.CIStr // Used for show table regions.
Flag int // Some flag parsed from sql, such as FULL.
Expand Down Expand Up @@ -224,6 +225,8 @@ func (e *ShowExec) fetchAll(ctx context.Context) error {
return e.fetchShowPlacementForDB(ctx)
case ast.ShowPlacementForTable:
return e.fetchShowPlacementForTable(ctx)
case ast.ShowPlacementForPartition:
return e.fetchShowPlacementForPartition(ctx)
}
return nil
}
Expand Down
Loading

0 comments on commit e43f5c4

Please sign in to comment.