From 1f810e5256a524c0e716eae840f2564b9fa23d11 Mon Sep 17 00:00:00 2001 From: fanrenhoo Date: Wed, 16 Feb 2022 10:43:39 +0800 Subject: [PATCH] ddl: make rename a not exists table report right error message (#32170) close pingcap/tidb#29893 --- ddl/db_test.go | 17 +++++++++-------- ddl/ddl_api.go | 4 ++-- ddl/error.go | 1 - executor/ddl_test.go | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ddl/db_test.go b/ddl/db_test.go index 46199d7852545..2ddcb275cd360 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -3531,6 +3531,7 @@ func (s *testDBSuite5) TestAlterTableRenameTable(c *C) { func (s *testDBSuite) testRenameTable(c *C, sql string, isAlterTable bool) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") + tk.MustGetErrCode("rename table tb1 to tb2;", errno.ErrNoSuchTable) // for different databases tk.MustExec("create table t (c1 int, c2 int)") tk.MustExec("insert t values (1, 1), (2, 2)") @@ -3570,19 +3571,19 @@ func (s *testDBSuite) testRenameTable(c *C, sql string, isAlterTable bool) { if isAlterTable { tk.MustGetErrCode(failSQL, errno.ErrNoSuchTable) } else { - tk.MustGetErrCode(failSQL, errno.ErrFileNotFound) + tk.MustGetErrCode(failSQL, errno.ErrNoSuchTable) } failSQL = fmt.Sprintf(sql, "test.test_not_exist", "test.test_not_exist") if isAlterTable { tk.MustGetErrCode(failSQL, errno.ErrNoSuchTable) } else { - tk.MustGetErrCode(failSQL, errno.ErrFileNotFound) + tk.MustGetErrCode(failSQL, errno.ErrNoSuchTable) } failSQL = fmt.Sprintf(sql, "test.t_not_exist", "test_not_exist.t") if isAlterTable { tk.MustGetErrCode(failSQL, errno.ErrNoSuchTable) } else { - tk.MustGetErrCode(failSQL, errno.ErrFileNotFound) + tk.MustGetErrCode(failSQL, errno.ErrNoSuchTable) } failSQL = fmt.Sprintf(sql, "test1.t2", "test_not_exist.t") tk.MustGetErrCode(failSQL, errno.ErrErrorOnRename) @@ -3607,7 +3608,7 @@ func (s *testDBSuite) testRenameTable(c *C, sql string, isAlterTable bool) { if isAlterTable { tk.MustGetErrCode(failSQL, errno.ErrNoSuchTable) } else { - tk.MustGetErrCode(failSQL, errno.ErrFileNotFound) + tk.MustGetErrCode(failSQL, errno.ErrNoSuchTable) } // for the same table name @@ -3726,13 +3727,13 @@ func (s *testDBSuite1) TestRenameMultiTables(c *C) { // for failure case failSQL := "rename table test_not_exist.t to test_not_exist.t, test_not_exist.t to test_not_exist.t" - tk.MustGetErrCode(failSQL, errno.ErrFileNotFound) + tk.MustGetErrCode(failSQL, errno.ErrNoSuchTable) failSQL = "rename table test.test_not_exist to test.test_not_exist, test.test_not_exist to test.test_not_exist" - tk.MustGetErrCode(failSQL, errno.ErrFileNotFound) + tk.MustGetErrCode(failSQL, errno.ErrNoSuchTable) failSQL = "rename table test.t_not_exist to test_not_exist.t, test.t_not_exist to test_not_exist.t" - tk.MustGetErrCode(failSQL, errno.ErrFileNotFound) + tk.MustGetErrCode(failSQL, errno.ErrNoSuchTable) failSQL = "rename table test1.t2 to test_not_exist.t, test1.t2 to test_not_exist.t" - tk.MustGetErrCode(failSQL, errno.ErrFileNotFound) + tk.MustGetErrCode(failSQL, errno.ErrNoSuchTable) tk.MustExec("drop database test1") tk.MustExec("drop database test") diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 8d32d226ab81d..2233a2f3b2e9a 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -5235,7 +5235,7 @@ func extractTblInfos(is infoschema.InfoSchema, oldIdent, newIdent ast.Ident, isA if tableExists(is, newIdent, tables) { return nil, 0, infoschema.ErrTableExists.GenWithStackByArgs(newIdent) } - return nil, 0, errFileNotFound.GenWithStackByArgs(oldIdent.Schema, oldIdent.Name) + return nil, 0, infoschema.ErrTableNotExists.GenWithStackByArgs(oldIdent.Schema, oldIdent.Name) } if !tableExists(is, oldIdent, tables) { if isAlterTable { @@ -5244,7 +5244,7 @@ func extractTblInfos(is infoschema.InfoSchema, oldIdent, newIdent ast.Ident, isA if tableExists(is, newIdent, tables) { return nil, 0, infoschema.ErrTableExists.GenWithStackByArgs(newIdent) } - return nil, 0, errFileNotFound.GenWithStackByArgs(oldIdent.Schema, oldIdent.Name) + return nil, 0, infoschema.ErrTableNotExists.GenWithStackByArgs(oldIdent.Schema, oldIdent.Name) } if isAlterTable && newIdent.Schema.L == oldIdent.Schema.L && newIdent.Name.L == oldIdent.Name.L { // oldIdent is equal to newIdent, do nothing diff --git a/ddl/error.go b/ddl/error.go index 6c910bf382b51..9db351199aa22 100644 --- a/ddl/error.go +++ b/ddl/error.go @@ -30,7 +30,6 @@ var ( errCantDecodeRecord = dbterror.ClassDDL.NewStd(mysql.ErrCantDecodeRecord) errInvalidDDLJob = dbterror.ClassDDL.NewStd(mysql.ErrInvalidDDLJob) errCancelledDDLJob = dbterror.ClassDDL.NewStd(mysql.ErrCancelledDDLJob) - errFileNotFound = dbterror.ClassDDL.NewStd(mysql.ErrFileNotFound) errRunMultiSchemaChanges = dbterror.ClassDDL.NewStdErr(mysql.ErrUnsupportedDDLOperation, parser_mysql.Message(fmt.Sprintf(mysql.MySQLErrName[mysql.ErrUnsupportedDDLOperation].Raw, "multi schema change"), nil)) errWaitReorgTimeout = dbterror.ClassDDL.NewStdErr(mysql.ErrLockWaitTimeout, mysql.MySQLErrName[mysql.ErrWaitReorgTimeout]) errInvalidStoreVer = dbterror.ClassDDL.NewStd(mysql.ErrInvalidStoreVersion) diff --git a/executor/ddl_test.go b/executor/ddl_test.go index d9b31af98eb59..8c5c03e0c2299 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -1593,7 +1593,7 @@ func (s *testRecoverTable) TestRenameMultiTables(c *C) { tk.MustExec("use rename3") tk.MustExec("create table rename3.t3 (a int primary key auto_increment)") tk.MustGetErrCode("rename table rename1.t1 to rename1.t2, rename1.t1 to rename3.t3", errno.ErrTableExists) - tk.MustGetErrCode("rename table rename1.t1 to rename1.t2, rename1.t1 to rename3.t4", errno.ErrFileNotFound) + tk.MustGetErrCode("rename table rename1.t1 to rename1.t2, rename1.t1 to rename3.t4", errno.ErrNoSuchTable) tk.MustExec("drop database rename1") tk.MustExec("drop database rename2") tk.MustExec("drop database rename3")