Skip to content

Commit

Permalink
table: calculate the default value even if the column is non-public (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta authored May 13, 2022
1 parent 405d2c0 commit 95f6da1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 12 additions & 0 deletions ddl/multi_schema_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,18 @@ func TestMultiSchemaChangeTableOption(t *testing.T) {
Check(testkit.Rows("SHARD_BITS=3 abc utf8mb4_bin"))
}

func TestMultiSchemaChangeNonPublicDefaultValue(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("set @@global.tidb_enable_change_multi_schema = 1;")
tk.MustExec("create table t (a tinyint);")
tk.MustExec("insert into t set a = 10;")
tk.MustExec("alter table t add column b int not null, change column a c char(5) first;")
tk.MustQuery("select * from t;").Check(testkit.Rows("10 0"))
}

func composeHooks(dom *domain.Domain, cbs ...ddl.Callback) ddl.Callback {
return &ddl.TestDDLCallback{
Do: dom,
Expand Down
3 changes: 0 additions & 3 deletions table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1446,9 +1446,6 @@ func GetColDefaultValue(ctx sessionctx.Context, col *table.Column, defaultVals [
if col.GetOriginDefaultValue() == nil && mysql.HasNotNullFlag(col.GetFlag()) {
return colVal, errors.New("Miss column")
}
if col.State != model.StatePublic {
return colVal, nil
}
if defaultVals[col.Offset].IsNull() {
colVal, err = table.GetColOriginDefaultValue(ctx, col.ToInfo())
if err != nil {
Expand Down

0 comments on commit 95f6da1

Please sign in to comment.