From bcad4640099960fd725a742524f941c1fc937720 Mon Sep 17 00:00:00 2001 From: crazycs Date: Mon, 11 Nov 2019 14:25:49 +0800 Subject: [PATCH] ddl: check table name length when rename table (#13339) --- 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 0265c06e626fd..1e8e09001a41a 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -2191,6 +2191,10 @@ func (s *testDBSuite) testRenameTable(c *C, sql string, isAlterTable bool) { s.tk.MustGetErrCode(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 cec7e61e600e2..2bae87ce66f31 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -3298,6 +3298,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,