diff --git a/ddl/db_integration_test.go b/ddl/db_integration_test.go index 4943c00432b6e..367549acc13cb 100644 --- a/ddl/db_integration_test.go +++ b/ddl/db_integration_test.go @@ -770,6 +770,33 @@ func (s *testIntegrationSuite4) TestChangingTableCharset(c *C) { } +func (s *testIntegrationSuite5) TestModifyingColumnOption(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("create database if not exists test") + tk.MustExec("use test") + + errMsg := "[ddl:203]" // unsupported modify column with references + assertErrCode := func(sql string, errCodeStr string) { + _, err := tk.Exec(sql) + c.Assert(err, NotNil) + c.Assert(err.Error()[:len(errCodeStr)], Equals, errCodeStr) + } + + tk.MustExec("drop table if exists t1") + tk.MustExec("create table t1 (b char(1) default null) engine=InnoDB default charset=utf8mb4 collate=utf8mb4_general_ci") + tk.MustExec("alter table t1 modify column b char(1) character set utf8mb4 collate utf8mb4_general_ci") + + tk.MustExec("drop table t1") + tk.MustExec("create table t1 (b char(1) collate utf8mb4_general_ci)") + tk.MustExec("alter table t1 modify b char(1) character set utf8mb4 collate utf8mb4_general_ci") + + tk.MustExec("drop table t1") + tk.MustExec("drop table if exists t2") + tk.MustExec("create table t1 (a int)") + tk.MustExec("create table t2 (b int, c int)") + assertErrCode("alter table t2 modify column c int references t1(a)", errMsg) +} + func (s *testIntegrationSuite2) TestCaseInsensitiveCharsetAndCollate(c *C) { tk := testkit.NewTestKit(c, s.store) diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index a279c501dd0ca..5a930f6aafcf6 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -2520,9 +2520,14 @@ func processColumnOptions(ctx sessionctx.Context, col *table.Column, options []* for _, colName := range findColumnNamesInExpr(opt.Expr) { col.Dependences[colName.Name.L] = struct{}{} } + case ast.ColumnOptionCollate: + col.Collate = opt.StrValue + case ast.ColumnOptionReference: + return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs("with references")) + case ast.ColumnOptionFulltext: + return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs("with full text")) default: - // TODO: Support other types. - return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs(opt.Tp)) + return errors.Trace(errUnsupportedModifyColumn.GenWithStackByArgs(fmt.Sprintf("unknown column option type: %d", opt.Tp))) } } @@ -2604,11 +2609,12 @@ func (d *ddl) getModifiableColumnJob(ctx sessionctx.Context, ident ast.Ident, or if err != nil { return nil, errors.Trace(err) } - err = modifiable(&col.FieldType, &newCol.FieldType) - if err != nil { + + if err = processColumnOptions(ctx, newCol, specNewColumn.Options); err != nil { return nil, errors.Trace(err) } - if err = processColumnOptions(ctx, newCol, specNewColumn.Options); err != nil { + + if err = modifiable(&col.FieldType, &newCol.FieldType); err != nil { return nil, errors.Trace(err) }