Skip to content

Commit

Permalink
ddl: add not null flag for auto_increment column (#30477)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhuang2016 committed Dec 7, 2021
1 parent 376d542 commit 4fb333c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ func columnDefToCol(ctx sessionctx.Context, offset int, colDef *ast.ColumnDef, o
hasNullFlag = true
case ast.ColumnOptionAutoIncrement:
col.Flag |= mysql.AutoIncrementFlag
col.Flag |= mysql.NotNullFlag
case ast.ColumnOptionPrimaryKey:
// Check PriKeyFlag first to avoid extra duplicate constraints.
if col.Flag&mysql.PriKeyFlag == 0 {
Expand Down
1 change: 1 addition & 0 deletions ddl/serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,7 @@ func (s *testIntegrationSuite7) TestInvisibleIndex(c *C) {
// Implicit primary key cannot be invisible index
// Create a implicit primary key
tk.MustGetErrCode("create table t2(a int not null, unique (a) invisible)", errno.ErrPKIndexCantBeInvisible)
tk.MustGetErrCode("create table t2(a int auto_increment, unique key (a) invisible);", errno.ErrPKIndexCantBeInvisible)
// Column `a` become implicit primary key after DDL statement on itself
tk.MustExec("create table t2(a int not null)")
tk.MustGetErrCode("alter table t2 add unique (a) invisible", errno.ErrPKIndexCantBeInvisible)
Expand Down

0 comments on commit 4fb333c

Please sign in to comment.