Skip to content

Commit

Permalink
ddl: make rename a not exists table report right error message (#32170)
Browse files Browse the repository at this point in the history
close #29893
  • Loading branch information
fanrenhoo authored Feb 16, 2022
1 parent 706f8a9 commit 1f810e5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
17 changes: 9 additions & 8 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion ddl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion executor/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1f810e5

Please sign in to comment.