diff --git a/plan/preprocess.go b/plan/preprocess.go index 2c28591444..25b6d9121c 100644 --- a/plan/preprocess.go +++ b/plan/preprocess.go @@ -57,6 +57,7 @@ func (p *preprocessor) Enter(in ast.Node) (out ast.Node, skipChildren bool) { p.checkDropTableGrammar(node) case *ast.RenameTableStmt: p.inCreateOrDropTable = true + p.checkRenameTableGrammar(node) case *ast.CreateIndexStmt: p.checkCreateIndexGrammar(node) case *ast.AlterTableStmt: @@ -300,6 +301,21 @@ func (p *preprocessor) checkCreateIndexGrammar(stmt *ast.CreateIndexStmt) { p.err = checkIndexInfo(stmt.IndexName, stmt.IndexColNames) } +func (p *preprocessor) checkRenameTableGrammar(stmt *ast.RenameTableStmt) { + oldTable := stmt.OldTable.Name.String() + newTable := stmt.NewTable.Name.String() + + if isIncorrectName(oldTable) { + p.err = ddl.ErrWrongTableName.GenByArgs(oldTable) + return + } + + if isIncorrectName(newTable) { + p.err = ddl.ErrWrongTableName.GenByArgs(newTable) + return + } +} + func (p *preprocessor) checkAlterTableGrammar(stmt *ast.AlterTableStmt) { tName := stmt.Table.Name.String() if isIncorrectName(tName) { diff --git a/plan/preprocess_test.go b/plan/preprocess_test.go index 062fb71320..b8df1c7bca 100644 --- a/plan/preprocess_test.go +++ b/plan/preprocess_test.go @@ -134,6 +134,8 @@ func (s *testValidatorSuite) TestValidator(c *C) { {"alter table t change column a `a ` int", true, errors.New("[ddl:1166]Incorrect column name 'a '")}, {"create index idx on `t ` (a)", true, errors.New("[ddl:1103]Incorrect table name 't '")}, {"create index idx on `` (a)", true, errors.New("[ddl:1103]Incorrect table name ''")}, + {"rename table t to ``", false, errors.New("[ddl:1103]Incorrect table name ''")}, + {"rename table `` to t", false, errors.New("[ddl:1103]Incorrect table name ''")}, // issue 3844 {`create table t (a set("a, b", "c, d"))`, true, errors.New("[types:1367]Illegal set 'a, b' value found during parsing")},