Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: add not null flag for auto_increment column #30477

Merged
merged 2 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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