Repository: pingcap/tidb (Go)

Issue:
unsupported modify column %!s(ast.ColumnOptionType=12)
## Bug Report

Please answer these questions before submitting your issue. Thanks!

1. What did you do?
If possible, provide a recipe for reproducing the error.
`CREATE TABLE `t1` (
  b char(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ;

ALTER TABLE t1  MODIFY COLUMN b char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ;`

2. What did you expect to see?



3. What did you see instead?

unsupported modify column %!s(ast.ColumnOptionType=12)

4. What version of TiDB are you using (`tidb-server -V` or run `select tidb_version();` on TiDB)?

Release Version: v3.0.0-rc.2
Git Commit Hash: 06f3f63d5a87e7f0436c0618cf524fea7172eb93
Git Branch: HEAD
UTC Build Time: 2019-05-28 12:48:52
GoVersion: go version go1.12 linux/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false

I would got the error when I used COLLATE.

Cannot change column collation from `utf8mb4_general_ci` to `utf8mb4_general_ci`
## Bug Report

Please answer these questions before submitting your issue. Thanks!

1. What did you do?
If possible, provide a recipe for reproducing the error.
```sql
create table t (b char(1) collate utf8mb4_general_ci);
alter table t modify b char(1) character set utf8mb4 collate utf8mb4_general_ci;
```
2. What did you expect to see?
In MySQL 5.7:
```sql
Query OK (0.059 sec)
```

3. What did you see instead?
In TiDB:
```sql
Error 1105: unsupported modify collate from utf8mb4_general_ci to utf8mb4_bin
```

4. What version of TiDB are you using (`tidb-server -V` or run `select tidb_version();` on TiDB)?
```sql
+--------------------------------------------------------------------------+
| tidb_version()                                                           |
+--------------------------------------------------------------------------+
| Release Version: v3.0.0-rc.1-271-gf56ef0064                              |
| Git Commit Hash: f56ef00649ec388b1ac3989f8009442f3be4e299                |
| Git Branch: master                                                       |
| UTC Build Time: 2019-07-03 08:47:32                                      |
| GoVersion: go version go1.12.5 linux/amd64                               |
| Race Enabled: false                                                      |
| TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e |
| Check Table Before Drop: false                                           |
+--------------------------------------------------------------------------+
```



Discussion:
Thanks for your feedback! PTAL @crazycs520 





Patch:
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)
 	}
 


Test patch:
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)