diff --git a/executor/admin_test.go b/executor/admin_test.go index 195eb0697feb0..eb56c62684904 100644 --- a/executor/admin_test.go +++ b/executor/admin_test.go @@ -506,6 +506,14 @@ func (s *testSuite1) TestAdminCheckTable(c *C) { tk.MustExec(`ALTER TABLE td1 ADD COLUMN c4 DECIMAL(12,8) NULL DEFAULT '213.41598062';`) tk.MustExec(`ALTER TABLE td1 ADD INDEX id2 (c4) ;`) tk.MustExec(`ADMIN CHECK TABLE td1;`) + + // Test add not null column, then add index. + tk.MustExec(`drop table if exists t1`) + tk.MustExec(`create table t1 (a int);`) + tk.MustExec(`insert into t1 set a=2;`) + tk.MustExec(`alter table t1 add column b timestamp not null;`) + tk.MustExec(`alter table t1 add index(b);`) + tk.MustExec(`admin check table t1;`) } func (s *testSuite1) TestAdminCheckPrimaryIndex(c *C) { diff --git a/util/admin/admin.go b/util/admin/admin.go index 3e9446bd0182a..d15d7edc7eb9f 100644 --- a/util/admin/admin.go +++ b/util/admin/admin.go @@ -440,8 +440,8 @@ func CheckRecordAndIndex(sessCtx sessionctx.Context, txn kv.Transaction, t table for i, val := range vals1 { col := cols[i] if val.IsNull() { - if mysql.HasNotNullFlag(col.Flag) { - return false, errors.New("Miss") + if mysql.HasNotNullFlag(col.Flag) && col.ToInfo().OriginDefaultValue == nil { + return false, errors.Errorf("Column %v define as not null, but can't find the value where handle is %v", col.Name, h1) } // NULL value is regarded as its default value. colDefVal, err := table.GetColOriginDefaultValue(sessCtx, col.ToInfo()) @@ -647,8 +647,8 @@ func rowWithCols(sessCtx sessionctx.Context, txn kv.Retriever, t table.Table, h } ri, ok := rowMap[col.ID] if !ok { - if mysql.HasNotNullFlag(col.Flag) { - return nil, errors.New("Miss") + if mysql.HasNotNullFlag(col.Flag) && col.ToInfo().OriginDefaultValue == nil { + return nil, errors.Errorf("Column %v define as not null, but can't find the value where handle is %v", col.Name, h) } // NULL value is regarded as its default value. colDefVal, err := table.GetColOriginDefaultValue(sessCtx, col.ToInfo())