From 11b52d1e84cdb8c093fc27cfa861158d043b8161 Mon Sep 17 00:00:00 2001 From: crazycs Date: Mon, 11 Nov 2019 13:16:12 +0800 Subject: [PATCH 1/2] ddl: check table name length when rename table --- ddl/db_test.go | 4 ++++ ddl/ddl_api.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/ddl/db_test.go b/ddl/db_test.go index a3f800163b0cc..2558802879ddc 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -2056,6 +2056,10 @@ func (s *testDBSuite) testRenameTable(c *C, sql string, isAlterTable bool) { assertErrorCode(c, s.tk, fmt.Sprintf(sql, "test1.t1", "test1.T1"), tmysql.ErrTableExists) } + // Test rename table name too long. + s.tk.MustGetErrCode("rename table test1.t1 to test1.txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", tmysql.ErrTooLongIdent) + s.tk.MustGetErrCode("alter table test1.t1 rename to test1.txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", tmysql.ErrTooLongIdent) + s.tk.MustExec("drop database test1") } diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index d2837f4b12f4a..774e132b1591a 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -3112,6 +3112,9 @@ func (d *ddl) RenameTable(ctx sessionctx.Context, oldIdent, newIdent ast.Ident, if is.TableExists(newIdent.Schema, newIdent.Name) { return infoschema.ErrTableExists.GenWithStackByArgs(newIdent) } + if err := checkTooLongTable(newIdent.Name); err != nil { + return errors.Trace(err) + } job := &model.Job{ SchemaID: newSchema.ID, From 30aa30d9d34a8431700136664baf92ab8a173520 Mon Sep 17 00:00:00 2001 From: crazycs Date: Tue, 12 Nov 2019 22:49:00 +0800 Subject: [PATCH 2/2] fix test --- ddl/db_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ddl/db_test.go b/ddl/db_test.go index 2558802879ddc..c0ab2e77fd406 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -2057,8 +2057,8 @@ func (s *testDBSuite) testRenameTable(c *C, sql string, isAlterTable bool) { } // Test rename table name too long. - s.tk.MustGetErrCode("rename table test1.t1 to test1.txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", tmysql.ErrTooLongIdent) - s.tk.MustGetErrCode("alter table test1.t1 rename to test1.txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", tmysql.ErrTooLongIdent) + assertErrorCode(c, s.tk, "rename table test1.t1 to test1.txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", tmysql.ErrTooLongIdent) + assertErrorCode(c, s.tk, "alter table test1.t1 rename to test1.txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", tmysql.ErrTooLongIdent) s.tk.MustExec("drop database test1") }