From a04b928958e3045941a8eefd6bf0106b1ec017e3 Mon Sep 17 00:00:00 2001 From: lihaowei Date: Sat, 8 May 2021 21:05:04 +0800 Subject: [PATCH 01/11] admin check table Signed-off-by: lihaowei --- executor/admin_test.go | 9 +++++++++ executor/executor.go | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/executor/admin_test.go b/executor/admin_test.go index c9cda897a4745..4ed4c0056e619 100644 --- a/executor/admin_test.go +++ b/executor/admin_test.go @@ -76,6 +76,15 @@ func (s *testSuite5) TestAdminCheckIndex(c *C) { check() } +func (s *testSuite5) TestAdminCheckIndexInTemporaryMode(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists admin_test;") + tk.MustExec("create global temporary table admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2)) ON COMMIT DELETE ROWS;") + tk.MustExec("insert admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);") + tk.MustGetErrCode("admin check table admin_test;", mysql.ErrAdminCheckTable) +} + func (s *testSuite5) TestAdminRecoverIndex(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") diff --git a/executor/executor.go b/executor/executor.go index e5d5d44efefe3..bf76b3e76fd9a 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -735,6 +735,10 @@ func (e *CheckTableExec) handlePanic(r interface{}) { // Next implements the Executor Next interface. func (e *CheckTableExec) Next(ctx context.Context, req *chunk.Chunk) error { + tempTableType := e.table.Meta().TempTableType + if tempTableType == model.TempTableGlobal || tempTableType == model.TempTableLocal { + return errors.Trace(ErrAdminCheckTable) + } if e.done || len(e.srcs) == 0 { return nil } From 41fdfc8ba7ab9143b63a0f096781914b531b5e5b Mon Sep 17 00:00:00 2001 From: lihaowei Date: Sun, 9 May 2021 09:52:21 +0800 Subject: [PATCH 02/11] drop table --- executor/admin_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/executor/admin_test.go b/executor/admin_test.go index 4ed4c0056e619..565512836ba7c 100644 --- a/executor/admin_test.go +++ b/executor/admin_test.go @@ -82,6 +82,7 @@ func (s *testSuite5) TestAdminCheckIndexInTemporaryMode(c *C) { tk.MustExec("drop table if exists admin_test;") tk.MustExec("create global temporary table admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2)) ON COMMIT DELETE ROWS;") tk.MustExec("insert admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);") + tk.MustExec("drop table if exists admin_test;") tk.MustGetErrCode("admin check table admin_test;", mysql.ErrAdminCheckTable) } From 8688e852ab9730b42a2bddefe47e1d42a9cc7710 Mon Sep 17 00:00:00 2001 From: lihaowei Date: Sun, 9 May 2021 10:07:08 +0800 Subject: [PATCH 03/11] change pos --- executor/admin_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor/admin_test.go b/executor/admin_test.go index 565512836ba7c..13ad22e60b5f6 100644 --- a/executor/admin_test.go +++ b/executor/admin_test.go @@ -82,8 +82,8 @@ func (s *testSuite5) TestAdminCheckIndexInTemporaryMode(c *C) { tk.MustExec("drop table if exists admin_test;") tk.MustExec("create global temporary table admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2)) ON COMMIT DELETE ROWS;") tk.MustExec("insert admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);") - tk.MustExec("drop table if exists admin_test;") tk.MustGetErrCode("admin check table admin_test;", mysql.ErrAdminCheckTable) + tk.MustExec("drop table if exists admin_test;") } func (s *testSuite5) TestAdminRecoverIndex(c *C) { From 74676c57146c45cbafe6c9f50e52803e0d7c77a5 Mon Sep 17 00:00:00 2001 From: lihaowei Date: Sun, 9 May 2021 10:21:42 +0800 Subject: [PATCH 04/11] change table name --- executor/admin_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/executor/admin_test.go b/executor/admin_test.go index 13ad22e60b5f6..a281c16c387f0 100644 --- a/executor/admin_test.go +++ b/executor/admin_test.go @@ -79,11 +79,11 @@ func (s *testSuite5) TestAdminCheckIndex(c *C) { func (s *testSuite5) TestAdminCheckIndexInTemporaryMode(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") - tk.MustExec("drop table if exists admin_test;") - tk.MustExec("create global temporary table admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2)) ON COMMIT DELETE ROWS;") - tk.MustExec("insert admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);") - tk.MustGetErrCode("admin check table admin_test;", mysql.ErrAdminCheckTable) - tk.MustExec("drop table if exists admin_test;") + tk.MustExec("drop table if exists temporary_admin_test;") + tk.MustExec("create global temporary table temporary_admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2)) ON COMMIT DELETE ROWS;") + tk.MustExec("insert temporary_admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);") + tk.MustGetErrCode("admin check table temporary_admin_test;", mysql.ErrAdminCheckTable) + tk.MustExec("drop table if exists temporary_admin_test;") } func (s *testSuite5) TestAdminRecoverIndex(c *C) { From 89fd2bd28f2ec305eb8de137e97b7c871217c2fc Mon Sep 17 00:00:00 2001 From: lihaowei Date: Sun, 9 May 2021 22:15:29 +0800 Subject: [PATCH 05/11] fix test Signed-off-by: lihaowei --- executor/admin_test.go | 3 +-- executor/ddl.go | 8 ++++++++ executor/executor_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/executor/admin_test.go b/executor/admin_test.go index a281c16c387f0..dd386e173eb90 100644 --- a/executor/admin_test.go +++ b/executor/admin_test.go @@ -76,14 +76,13 @@ func (s *testSuite5) TestAdminCheckIndex(c *C) { check() } -func (s *testSuite5) TestAdminCheckIndexInTemporaryMode(c *C) { +func (s *testSuite13) TestAdminCheckIndexInTemporaryMode(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("drop table if exists temporary_admin_test;") tk.MustExec("create global temporary table temporary_admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2)) ON COMMIT DELETE ROWS;") tk.MustExec("insert temporary_admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);") tk.MustGetErrCode("admin check table temporary_admin_test;", mysql.ErrAdminCheckTable) - tk.MustExec("drop table if exists temporary_admin_test;") } func (s *testSuite5) TestAdminRecoverIndex(c *C) { diff --git a/executor/ddl.go b/executor/ddl.go index 64a597e2eb024..0532c6bfe7fc6 100644 --- a/executor/ddl.go +++ b/executor/ddl.go @@ -314,6 +314,14 @@ func (e *DDLExec) dropTableObject(objects []*ast.TableName, obt objectType, ifEx } if obt == tableObject && config.CheckTableBeforeDrop { + tableInfo, err := e.is.TableByName(tn.Schema, tn.Name) + if err != nil { + return err + } + tempTableType := tableInfo.Meta().TempTableType + if tempTableType == model.TempTableGlobal || tempTableType == model.TempTableLocal { + return ErrAdminCheckTable + } logutil.BgLogger().Warn("admin check table before drop", zap.String("database", fullti.Schema.O), zap.String("table", fullti.Name.O), diff --git a/executor/executor_test.go b/executor/executor_test.go index 80056439ec7c6..9ea40ef4c399e 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -116,6 +116,7 @@ var _ = Suite(&testSuite2{&baseTestSuite{}}) var _ = Suite(&testSuite3{&baseTestSuite{}}) var _ = Suite(&testSuite4{&baseTestSuite{}}) var _ = Suite(&testSuite5{&baseTestSuite{}}) +var _ = Suite(&testSuite13{&baseTestSuite{}}) var _ = Suite(&testSuiteJoin1{&baseTestSuite{}}) var _ = Suite(&testSuiteJoin2{&baseTestSuite{}}) var _ = Suite(&testSuiteJoin3{&baseTestSuite{}}) @@ -4872,6 +4873,30 @@ func (s *testSuite8) TearDownTest(c *C) { } } +type testSuite13 struct { + *baseTestSuite +} + +func (s *testSuite13) TearDownTest(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + r := tk.MustQuery("show full tables") + for _, tb := range r.Rows() { + tableName := tb[0] + if tb[1] == "VIEW" { + tk.MustExec(fmt.Sprintf("drop view %v", tableName)) + } else if tb[1] == "SEQUENCE" { + tk.MustExec(fmt.Sprintf("drop sequence %v", tableName)) + } else { + if !config.CheckTableBeforeDrop { + tk.MustExec(fmt.Sprintf("drop table %v", tableName)) + } else { + tk.MustGetErrCode(fmt.Sprintf("drop table %v", tableName), errno.ErrAdminCheckTable) + } + } + } +} + type testSerialSuite1 struct { *baseTestSuite } From b0883b325df5a87f851dbb490b5b71f235895cde Mon Sep 17 00:00:00 2001 From: lihaowei Date: Mon, 10 May 2021 09:37:15 +0800 Subject: [PATCH 06/11] fix test --- session/session_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/session/session_test.go b/session/session_test.go index 84442a8a16956..7510ece44860e 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -36,6 +36,7 @@ import ( "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl/placement" "github.com/pingcap/tidb/domain" + "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/executor" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta/autoid" @@ -234,7 +235,11 @@ func (s *testSessionSuiteBase) TearDownTest(c *C) { case "VIEW": tk.MustExec(fmt.Sprintf("drop view %v", tableName)) case "BASE TABLE": - tk.MustExec(fmt.Sprintf("drop table %v", tableName)) + if !config.CheckTableBeforeDrop { + tk.MustExec(fmt.Sprintf("drop table %v", tableName)) + } else { + tk.MustGetErrCode(fmt.Sprintf("drop table %v", tableName), errno.ErrAdminCheckTable) + } default: panic(fmt.Sprintf("Unexpected table '%s' with type '%s'.", tableName, tableType)) } From fdef1d46658583bf26e6cd136d14f441d2379fc7 Mon Sep 17 00:00:00 2001 From: lihaowei Date: Mon, 10 May 2021 12:10:03 +0800 Subject: [PATCH 07/11] change tests Signed-off-by: lihaowei --- executor/admin_test.go | 2 +- executor/ddl.go | 16 ++++++---------- executor/executor.go | 4 ---- executor/executor_test.go | 25 ------------------------- infoschema/error.go | 2 ++ planner/core/planbuilder.go | 3 +++ session/session_test.go | 7 +------ 7 files changed, 13 insertions(+), 46 deletions(-) diff --git a/executor/admin_test.go b/executor/admin_test.go index dd386e173eb90..a566a17f129de 100644 --- a/executor/admin_test.go +++ b/executor/admin_test.go @@ -76,7 +76,7 @@ func (s *testSuite5) TestAdminCheckIndex(c *C) { check() } -func (s *testSuite13) TestAdminCheckIndexInTemporaryMode(c *C) { +func (s *testSuite5) TestAdminCheckIndexInTemporaryMode(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("drop table if exists temporary_admin_test;") diff --git a/executor/ddl.go b/executor/ddl.go index 0532c6bfe7fc6..b5ea143192f7f 100644 --- a/executor/ddl.go +++ b/executor/ddl.go @@ -312,16 +312,12 @@ func (e *DDLExec) dropTableObject(objects []*ast.TableName, obt objectType, ifEx if isSystemTable(tn.Schema.L, tn.Name.L) { return errors.Errorf("Drop tidb system table '%s.%s' is forbidden", tn.Schema.L, tn.Name.L) } - - if obt == tableObject && config.CheckTableBeforeDrop { - tableInfo, err := e.is.TableByName(tn.Schema, tn.Name) - if err != nil { - return err - } - tempTableType := tableInfo.Meta().TempTableType - if tempTableType == model.TempTableGlobal || tempTableType == model.TempTableLocal { - return ErrAdminCheckTable - } + tableInfo, err := e.is.TableByName(tn.Schema, tn.Name) + if err != nil { + return err + } + tempTableType := tableInfo.Meta().TempTableType + if obt == tableObject && config.CheckTableBeforeDrop && tempTableType != model.TempTableGlobal && tempTableType != model.TempTableLocal { logutil.BgLogger().Warn("admin check table before drop", zap.String("database", fullti.Schema.O), zap.String("table", fullti.Name.O), diff --git a/executor/executor.go b/executor/executor.go index bf76b3e76fd9a..e5d5d44efefe3 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -735,10 +735,6 @@ func (e *CheckTableExec) handlePanic(r interface{}) { // Next implements the Executor Next interface. func (e *CheckTableExec) Next(ctx context.Context, req *chunk.Chunk) error { - tempTableType := e.table.Meta().TempTableType - if tempTableType == model.TempTableGlobal || tempTableType == model.TempTableLocal { - return errors.Trace(ErrAdminCheckTable) - } if e.done || len(e.srcs) == 0 { return nil } diff --git a/executor/executor_test.go b/executor/executor_test.go index 9ea40ef4c399e..80056439ec7c6 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -116,7 +116,6 @@ var _ = Suite(&testSuite2{&baseTestSuite{}}) var _ = Suite(&testSuite3{&baseTestSuite{}}) var _ = Suite(&testSuite4{&baseTestSuite{}}) var _ = Suite(&testSuite5{&baseTestSuite{}}) -var _ = Suite(&testSuite13{&baseTestSuite{}}) var _ = Suite(&testSuiteJoin1{&baseTestSuite{}}) var _ = Suite(&testSuiteJoin2{&baseTestSuite{}}) var _ = Suite(&testSuiteJoin3{&baseTestSuite{}}) @@ -4873,30 +4872,6 @@ func (s *testSuite8) TearDownTest(c *C) { } } -type testSuite13 struct { - *baseTestSuite -} - -func (s *testSuite13) TearDownTest(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - r := tk.MustQuery("show full tables") - for _, tb := range r.Rows() { - tableName := tb[0] - if tb[1] == "VIEW" { - tk.MustExec(fmt.Sprintf("drop view %v", tableName)) - } else if tb[1] == "SEQUENCE" { - tk.MustExec(fmt.Sprintf("drop sequence %v", tableName)) - } else { - if !config.CheckTableBeforeDrop { - tk.MustExec(fmt.Sprintf("drop table %v", tableName)) - } else { - tk.MustGetErrCode(fmt.Sprintf("drop table %v", tableName), errno.ErrAdminCheckTable) - } - } - } -} - type testSerialSuite1 struct { *baseTestSuite } diff --git a/infoschema/error.go b/infoschema/error.go index a0ef7ab9c8760..ed4a244f4c218 100644 --- a/infoschema/error.go +++ b/infoschema/error.go @@ -69,4 +69,6 @@ var ( ErrTableLocked = dbterror.ClassSchema.NewStd(mysql.ErrTableLocked) // ErrWrongObject returns when the table/view/sequence is not the expected object. ErrWrongObject = dbterror.ClassSchema.NewStd(mysql.ErrWrongObject) + // ErrAdminCheckTable returns when the check table in temporary mode + ErrAdminCheckTable = dbterror.ClassSchema.NewStd(mysql.ErrAdminCheckTable) ) diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 6fc98bc522508..45aa14697a7bd 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -1463,6 +1463,9 @@ func (b *PlanBuilder) buildAdminCheckTable(ctx context.Context, as *ast.AdminStm if !ok { return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(tblName.DBInfo.Name.O, tableInfo.Name.O) } + if tableInfo.TempTableType == model.TempTableGlobal || tableInfo.TempTableType == model.TempTableLocal { + return nil, infoschema.ErrAdminCheckTable + } p := &CheckTable{ DBName: tblName.Schema.O, Table: tbl, diff --git a/session/session_test.go b/session/session_test.go index 7510ece44860e..84442a8a16956 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -36,7 +36,6 @@ import ( "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl/placement" "github.com/pingcap/tidb/domain" - "github.com/pingcap/tidb/errno" "github.com/pingcap/tidb/executor" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/meta/autoid" @@ -235,11 +234,7 @@ func (s *testSessionSuiteBase) TearDownTest(c *C) { case "VIEW": tk.MustExec(fmt.Sprintf("drop view %v", tableName)) case "BASE TABLE": - if !config.CheckTableBeforeDrop { - tk.MustExec(fmt.Sprintf("drop table %v", tableName)) - } else { - tk.MustGetErrCode(fmt.Sprintf("drop table %v", tableName), errno.ErrAdminCheckTable) - } + tk.MustExec(fmt.Sprintf("drop table %v", tableName)) default: panic(fmt.Sprintf("Unexpected table '%s' with type '%s'.", tableName, tableType)) } From f36dd726fb3cc1f17acf526803f441762815b699 Mon Sep 17 00:00:00 2001 From: lihaowei Date: Mon, 10 May 2021 12:48:49 +0800 Subject: [PATCH 08/11] add err toml Signed-off-by: lihaowei --- errors.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/errors.toml b/errors.toml index 458af951629d8..192012c298775 100644 --- a/errors.toml +++ b/errors.toml @@ -1281,6 +1281,11 @@ error = ''' Unknown SEQUENCE: '%-.300s' ''' +["schema:8003"] +error = ''' +TiDB admin check table failed. +''' + ["schema:8020"] error = ''' Table '%s' was locked in %s by %v From 226ed64d64e332f984bde4ba4e322d799d80b43f Mon Sep 17 00:00:00 2001 From: lihaowei Date: Tue, 11 May 2021 14:16:30 +0800 Subject: [PATCH 09/11] add check Signed-off-by: lihaowei --- executor/admin_test.go | 7 +++++++ infoschema/error.go | 2 +- planner/core/planbuilder.go | 3 --- planner/core/preprocess.go | 24 ++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/executor/admin_test.go b/executor/admin_test.go index a566a17f129de..20095eb59a0ba 100644 --- a/executor/admin_test.go +++ b/executor/admin_test.go @@ -83,6 +83,13 @@ func (s *testSuite5) TestAdminCheckIndexInTemporaryMode(c *C) { tk.MustExec("create global temporary table temporary_admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2)) ON COMMIT DELETE ROWS;") tk.MustExec("insert temporary_admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);") tk.MustGetErrCode("admin check table temporary_admin_test;", mysql.ErrAdminCheckTable) + tk.MustExec("drop table if exists temporary_admin_test;") + + tk.MustExec("drop table if exists non_temporary_admin_test;") + tk.MustExec("create table non_temporary_admin_test (c1 int, c2 int, c3 int default 1, primary key (c1), index (c1), unique key(c2));") + tk.MustExec("insert non_temporary_admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);") + tk.MustExec("admin check table non_temporary_admin_test;") + tk.MustExec("drop table if exists non_temporary_admin_test;") } func (s *testSuite5) TestAdminRecoverIndex(c *C) { diff --git a/infoschema/error.go b/infoschema/error.go index ed4a244f4c218..cb49e48419dec 100644 --- a/infoschema/error.go +++ b/infoschema/error.go @@ -69,6 +69,6 @@ var ( ErrTableLocked = dbterror.ClassSchema.NewStd(mysql.ErrTableLocked) // ErrWrongObject returns when the table/view/sequence is not the expected object. ErrWrongObject = dbterror.ClassSchema.NewStd(mysql.ErrWrongObject) - // ErrAdminCheckTable returns when the check table in temporary mode + // ErrAdminCheckTable returns when the check table in temporary mode. ErrAdminCheckTable = dbterror.ClassSchema.NewStd(mysql.ErrAdminCheckTable) ) diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 45aa14697a7bd..6fc98bc522508 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -1463,9 +1463,6 @@ func (b *PlanBuilder) buildAdminCheckTable(ctx context.Context, as *ast.AdminStm if !ok { return nil, infoschema.ErrTableNotExists.GenWithStackByArgs(tblName.DBInfo.Name.O, tableInfo.Name.O) } - if tableInfo.TempTableType == model.TempTableGlobal || tableInfo.TempTableType == model.TempTableLocal { - return nil, infoschema.ErrAdminCheckTable - } p := &CheckTable{ DBName: tblName.Schema.O, Table: tbl, diff --git a/planner/core/preprocess.go b/planner/core/preprocess.go index a3719fe4c4b0b..f9e792831bfba 100644 --- a/planner/core/preprocess.go +++ b/planner/core/preprocess.go @@ -125,6 +125,8 @@ type preprocessor struct { func (p *preprocessor) Enter(in ast.Node) (out ast.Node, skipChildren bool) { switch node := in.(type) { + case *ast.AdminStmt: + p.checkAdminCheckTableGrammar(node) case *ast.DeleteStmt: p.stmtTp = TypeDelete case *ast.SelectStmt: @@ -557,6 +559,28 @@ func (p *preprocessor) checkDropDatabaseGrammar(stmt *ast.DropDatabaseStmt) { } } +func (p *preprocessor) checkAdminCheckTableGrammar(stmt *ast.AdminStmt) { + for _, table := range stmt.Tables { + currentDB := p.ctx.GetSessionVars().CurrentDB + if currentDB == "" { + p.err = errors.Trace(ErrNoDB) + return + } + sName := model.NewCIStr(currentDB) + tName := table.Name + tableInfo, err := p.is.TableByName(sName, tName) + if err != nil { + p.err = err + return + } + tempTableType := tableInfo.Meta().TempTableType + if stmt.Tp == ast.AdminCheckTable && (tempTableType == model.TempTableGlobal || tempTableType == model.TempTableLocal) { + p.err = infoschema.ErrAdminCheckTable + return + } + } +} + func (p *preprocessor) checkCreateTableGrammar(stmt *ast.CreateTableStmt) { tName := stmt.Table.Name.String() if isIncorrectName(tName) { From 3f0efea8d1db276ec1e783a961ff3e9e21749b16 Mon Sep 17 00:00:00 2001 From: lihaowei Date: Tue, 11 May 2021 21:01:39 +0800 Subject: [PATCH 10/11] tests Signed-off-by: lihaowei --- executor/ddl.go | 2 +- expression/integration_test.go | 2 ++ planner/core/preprocess.go | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/executor/ddl.go b/executor/ddl.go index 00135ddc69fa0..2f10555d21e1e 100644 --- a/executor/ddl.go +++ b/executor/ddl.go @@ -316,7 +316,7 @@ func (e *DDLExec) dropTableObject(objects []*ast.TableName, obt objectType, ifEx return err } tempTableType := tableInfo.Meta().TempTableType - if obt == tableObject && config.CheckTableBeforeDrop && tempTableType != model.TempTableGlobal && tempTableType != model.TempTableLocal { + if obt == tableObject && config.CheckTableBeforeDrop && tempTableType == model.TempTableNone { logutil.BgLogger().Warn("admin check table before drop", zap.String("database", fullti.Schema.O), zap.String("table", fullti.Name.O), diff --git a/expression/integration_test.go b/expression/integration_test.go index f15dc5822be15..a3d983069cce9 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -9161,8 +9161,10 @@ func (s *testIntegrationSuite) TestIssue24429(c *C) { tk.MustExec("set @@sql_mode = ANSI_QUOTES;") tk.MustExec("use test") + tk.MustExec("drop table if exists t;") tk.MustExec("create table t (a int);") tk.MustQuery(`select t."a"=10 from t;`).Check(testkit.Rows()) + tk.MustExec("drop table if exists t;") } func (s *testIntegrationSuite) TestVitessHash(c *C) { diff --git a/planner/core/preprocess.go b/planner/core/preprocess.go index f9e792831bfba..9683e6d65fbb8 100644 --- a/planner/core/preprocess.go +++ b/planner/core/preprocess.go @@ -574,7 +574,7 @@ func (p *preprocessor) checkAdminCheckTableGrammar(stmt *ast.AdminStmt) { return } tempTableType := tableInfo.Meta().TempTableType - if stmt.Tp == ast.AdminCheckTable && (tempTableType == model.TempTableGlobal || tempTableType == model.TempTableLocal) { + if stmt.Tp == ast.AdminCheckTable && tempTableType != model.TempTableNone { p.err = infoschema.ErrAdminCheckTable return } From 65dd15833ec57dbb2c49ff19ced7b365d0e67203 Mon Sep 17 00:00:00 2001 From: lihaowei Date: Tue, 11 May 2021 23:29:36 +0800 Subject: [PATCH 11/11] fix test Signed-off-by: lihaowei --- planner/core/preprocess.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/planner/core/preprocess.go b/planner/core/preprocess.go index 9683e6d65fbb8..b5caf55e8de03 100644 --- a/planner/core/preprocess.go +++ b/planner/core/preprocess.go @@ -562,6 +562,9 @@ func (p *preprocessor) checkDropDatabaseGrammar(stmt *ast.DropDatabaseStmt) { func (p *preprocessor) checkAdminCheckTableGrammar(stmt *ast.AdminStmt) { for _, table := range stmt.Tables { currentDB := p.ctx.GetSessionVars().CurrentDB + if table.Schema.String() != "" { + currentDB = table.Schema.L + } if currentDB == "" { p.err = errors.Trace(ErrNoDB) return