From 9b0de062f156251a70b620f7ffcf86de61486302 Mon Sep 17 00:00:00 2001 From: Lynn Date: Thu, 5 Sep 2019 20:21:55 +0800 Subject: [PATCH 1/2] cherry pick #12008 to release-2.1 Signed-off-by: sre-bot --- ddl/ddl_api.go | 15 +++++++++++++++ executor/ddl_test.go | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 9c4e17d88ed67..201ee02267ca2 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -579,6 +579,7 @@ func columnDefToCol(ctx sessionctx.Context, offset int, colDef *ast.ColumnDef, o col.Flag &= ^mysql.BinaryFlag col.Flag |= mysql.ZerofillFlag } + // If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column. // See https://dev.mysql.com/doc/refman/5.7/en/numeric-type-overview.html for more details. // But some types like bit and year, won't show its unsigned flag in `show create table`. @@ -1983,11 +1984,21 @@ func setColumnComment(ctx sessionctx.Context, col *table.Column, option *ast.Col return errors.Trace(err) } +<<<<<<< HEAD // setDefaultAndComment is only used in getModifiableColumnJob. func setDefaultAndComment(ctx sessionctx.Context, col *table.Column, options []*ast.ColumnOption) error { if len(options) == 0 { return nil } +======= +// processColumnOptions is only used in getModifiableColumnJob. +func processColumnOptions(ctx sessionctx.Context, col *table.Column, options []*ast.ColumnOption) error { + var sb strings.Builder + restoreFlags := format.RestoreStringSingleQuotes | format.RestoreKeyWordLowercase | format.RestoreNameBackQuotes | + format.RestoreSpacesAroundBinaryOperation + restoreCtx := format.NewRestoreCtx(restoreFlags, &sb) + +>>>>>>> 2ef6f46... ddl: fix modify bit column (#12008) var hasDefaultValue, setOnUpdateNow bool var err error for _, opt := range options { @@ -2047,6 +2058,10 @@ func setDefaultAndComment(ctx sessionctx.Context, col *table.Column, options []* // it is `not null` and not an `AUTO_INCREMENT` field or `TIMESTAMP` field. setNoDefaultValueFlag(col, hasDefaultValue) + if col.Tp == mysql.TypeBit { + col.Flag |= mysql.UnsignedFlag + } + if hasDefaultValue { return errors.Trace(checkDefaultValue(ctx, col, true)) } diff --git a/executor/ddl_test.go b/executor/ddl_test.go index 07622f8cc1604..1deb1a18fddaf 100644 --- a/executor/ddl_test.go +++ b/executor/ddl_test.go @@ -253,7 +253,7 @@ func (s *testSuite6) TestAlterTableModifyColumn(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("drop table if exists mc") - tk.MustExec("create table mc(c1 int, c2 varchar(10))") + tk.MustExec("create table mc(c1 int, c2 varchar(10), c3 bit)") _, err := tk.Exec("alter table mc modify column c1 short") c.Assert(err, NotNil) tk.MustExec("alter table mc modify column c1 bigint") @@ -266,9 +266,10 @@ func (s *testSuite6) TestAlterTableModifyColumn(c *C) { tk.MustExec("alter table mc modify column c2 varchar(11)") tk.MustExec("alter table mc modify column c2 text(13)") tk.MustExec("alter table mc modify column c2 text") + tk.MustExec("alter table mc modify column c3 bit") result := tk.MustQuery("show create table mc") createSQL := result.Rows()[0][1] - expected := "CREATE TABLE `mc` (\n `c1` bigint(20) DEFAULT NULL,\n `c2` text DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" + expected := "CREATE TABLE `mc` (\n `c1` bigint(20) DEFAULT NULL,\n `c2` text DEFAULT NULL,\n `c3` bit(1) DEFAULT NULL\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" c.Assert(createSQL, Equals, expected) // test multiple collate modification in column. From ebe1f80199924d644174f643af6c5b8e512b817e Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 13 Apr 2020 11:27:35 +0800 Subject: [PATCH 2/2] ddl: fix conflicts --- ddl/ddl_api.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 201ee02267ca2..375756690a8bf 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -1984,21 +1984,8 @@ func setColumnComment(ctx sessionctx.Context, col *table.Column, option *ast.Col return errors.Trace(err) } -<<<<<<< HEAD // setDefaultAndComment is only used in getModifiableColumnJob. func setDefaultAndComment(ctx sessionctx.Context, col *table.Column, options []*ast.ColumnOption) error { - if len(options) == 0 { - return nil - } -======= -// processColumnOptions is only used in getModifiableColumnJob. -func processColumnOptions(ctx sessionctx.Context, col *table.Column, options []*ast.ColumnOption) error { - var sb strings.Builder - restoreFlags := format.RestoreStringSingleQuotes | format.RestoreKeyWordLowercase | format.RestoreNameBackQuotes | - format.RestoreSpacesAroundBinaryOperation - restoreCtx := format.NewRestoreCtx(restoreFlags, &sb) - ->>>>>>> 2ef6f46... ddl: fix modify bit column (#12008) var hasDefaultValue, setOnUpdateNow bool var err error for _, opt := range options {