Skip to content

Commit

Permalink
plan/validator: return an error when alter auto_incerment (pingcap#3041
Browse files Browse the repository at this point in the history
  • Loading branch information
bobotu authored and hanfei1991 committed Apr 19, 2017
1 parent 12f07da commit 7b381c0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plan/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ var (
ErrUnknownColumn = terror.ClassOptimizerPlan.New(CodeUnknownColumn, "Unknown column '%s' in '%s'")
ErrWrongArguments = terror.ClassOptimizerPlan.New(CodeWrongArguments, "Incorrect arguments to EXECUTE")
ErrAmbiguous = terror.ClassOptimizerPlan.New(CodeAmbiguous, "Column '%s' in field list is ambiguous")
ErrAlterAutoID = terror.ClassAutoid.New(CodeAlterAutoID, "No support for setting auto_increment using alter_table")
)

// Error codes.
const (
CodeUnsupportedType terror.ErrCode = 1
SystemInternalError terror.ErrCode = 2
CodeAlterAutoID terror.ErrCode = 3
CodeAmbiguous terror.ErrCode = 1052
CodeUnknownColumn terror.ErrCode = 1054
CodeWrongArguments terror.ErrCode = 1210
Expand Down
7 changes: 7 additions & 0 deletions plan/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ func (v *validator) checkAlterTableGrammar(stmt *ast.AlterTableStmt) {
default:
// Nothing to do now.
}
case ast.AlterTableOption:
for _, opt := range spec.Options {
if opt.Tp == ast.TableOptionAutoIncrement {
v.err = ErrAlterAutoID
return
}
}
default:
// Nothing to do now.
}
Expand Down
4 changes: 4 additions & 0 deletions plan/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ func (s *testValidatorSuite) TestValidator(c *C) {
errors.New("[schema:1068]Multiple primary key defined")},
{"create table t(c1 int not null, c2 int not null, primary key(c1), primary key(c2))", true,
errors.New("[schema:1068]Multiple primary key defined")},
{"alter table t auto_increment=1", true, errors.New("[autoid:3]No support for setting auto_increment using alter_table")},
{"alter table t add column c int auto_increment key, auto_increment=10", true,
errors.New("[autoid:3]No support for setting auto_increment using alter_table")},
{"alter table t add column c int auto_increment key", true, nil},
}

store, err := tidb.NewStore(tidb.EngineGoLevelDBMemory)
Expand Down

0 comments on commit 7b381c0

Please sign in to comment.