From 506e1fd94da9d8ba5c2911e0d634e5a303164f00 Mon Sep 17 00:00:00 2001 From: wjhuang2016 Date: Tue, 7 Dec 2021 15:22:05 +0800 Subject: [PATCH 1/2] done Signed-off-by: wjhuang2016 --- ddl/ddl_api.go | 1 + ddl/serial_test.go | 1 + executor/show.go | 8 ++++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 7ff671fa4f6ea..30cadd4a3a2d7 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -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 { diff --git a/ddl/serial_test.go b/ddl/serial_test.go index 26ca779dc3400..51dccd346b336 100644 --- a/ddl/serial_test.go +++ b/ddl/serial_test.go @@ -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) diff --git a/executor/show.go b/executor/show.go index 7bb135d56230e..1922d3c067163 100644 --- a/executor/show.go +++ b/executor/show.go @@ -862,13 +862,13 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T buf.WriteString(" VIRTUAL") } } + if mysql.HasNotNullFlag(col.Flag) { + buf.WriteString(" NOT NULL") + } if mysql.HasAutoIncrementFlag(col.Flag) { hasAutoIncID = true - buf.WriteString(" NOT NULL AUTO_INCREMENT") + buf.WriteString(" AUTO_INCREMENT") } else { - if mysql.HasNotNullFlag(col.Flag) { - buf.WriteString(" NOT NULL") - } // default values are not shown for generated columns in MySQL if !mysql.HasNoDefaultValueFlag(col.Flag) && !col.IsGenerated() { defaultValue := col.GetDefaultValue() From a5e6798cd1726b1e1387a3f562f4f51a1426f2a8 Mon Sep 17 00:00:00 2001 From: wjhuang2016 Date: Tue, 7 Dec 2021 15:23:22 +0800 Subject: [PATCH 2/2] revert Signed-off-by: wjhuang2016 --- executor/show.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/executor/show.go b/executor/show.go index 1922d3c067163..7bb135d56230e 100644 --- a/executor/show.go +++ b/executor/show.go @@ -862,13 +862,13 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T buf.WriteString(" VIRTUAL") } } - if mysql.HasNotNullFlag(col.Flag) { - buf.WriteString(" NOT NULL") - } if mysql.HasAutoIncrementFlag(col.Flag) { hasAutoIncID = true - buf.WriteString(" AUTO_INCREMENT") + buf.WriteString(" NOT NULL AUTO_INCREMENT") } else { + if mysql.HasNotNullFlag(col.Flag) { + buf.WriteString(" NOT NULL") + } // default values are not shown for generated columns in MySQL if !mysql.HasNoDefaultValueFlag(col.Flag) && !col.IsGenerated() { defaultValue := col.GetDefaultValue()