Skip to content

Commit

Permalink
ddl: check table name length when rename table (#13339) (#13347)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored and zimulala committed Nov 13, 2019
1 parent ad738bc commit 57198a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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")
}

Expand Down
3 changes: 3 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3115,6 +3115,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,
Expand Down

0 comments on commit 57198a5

Please sign in to comment.