From 95f6da134a4ca5856fb23329d46671076afce913 Mon Sep 17 00:00:00 2001 From: tangenta Date: Fri, 13 May 2022 14:58:23 +0800 Subject: [PATCH] table: calculate the default value even if the column is non-public (#96) --- ddl/multi_schema_change_test.go | 12 ++++++++++++ table/tables/tables.go | 3 --- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ddl/multi_schema_change_test.go b/ddl/multi_schema_change_test.go index 31ce963d66eb5..4b5794637e696 100644 --- a/ddl/multi_schema_change_test.go +++ b/ddl/multi_schema_change_test.go @@ -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, diff --git a/table/tables/tables.go b/table/tables/tables.go index fe8c4f4a513ad..b0250e8026e8a 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -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 {