From 88eead53117507d3105c020466000c06e2bd661d Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Thu, 17 Jan 2019 19:48:52 +0800 Subject: [PATCH 1/3] admin: fix admin check table err when add column not null, then add index on the column --- executor/admin_test.go | 8 ++++++++ util/admin/admin.go | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/executor/admin_test.go b/executor/admin_test.go index 195eb0697feb0..302f767334e84 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..af86bde4113b6 100644 --- a/util/admin/admin.go +++ b/util/admin/admin.go @@ -440,7 +440,7 @@ 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) { + if mysql.HasNotNullFlag(col.Flag) && col.ToInfo().OriginDefaultValue == nil { return false, errors.New("Miss") } // NULL value is regarded as its default value. @@ -647,7 +647,7 @@ func rowWithCols(sessCtx sessionctx.Context, txn kv.Retriever, t table.Table, h } ri, ok := rowMap[col.ID] if !ok { - if mysql.HasNotNullFlag(col.Flag) { + if mysql.HasNotNullFlag(col.Flag) && col.ToInfo().OriginDefaultValue == nil { return nil, errors.New("Miss") } // NULL value is regarded as its default value. From 1cbae40be8737052ef1857c8f10bb08d4a7e7852 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Thu, 17 Jan 2019 19:54:26 +0800 Subject: [PATCH 2/3] refine test --- executor/admin_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/executor/admin_test.go b/executor/admin_test.go index 302f767334e84..eb56c62684904 100644 --- a/executor/admin_test.go +++ b/executor/admin_test.go @@ -509,11 +509,11 @@ func (s *testSuite1) TestAdminCheckTable(c *C) { // 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;") + 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) { From fa2a67db607f7a50295f45b7d5ec8e6cca7e97a2 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Sun, 20 Jan 2019 15:18:56 +0800 Subject: [PATCH 3/3] refine err msg --- util/admin/admin.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/admin/admin.go b/util/admin/admin.go index af86bde4113b6..d15d7edc7eb9f 100644 --- a/util/admin/admin.go +++ b/util/admin/admin.go @@ -441,7 +441,7 @@ func CheckRecordAndIndex(sessCtx sessionctx.Context, txn kv.Transaction, t table col := cols[i] if val.IsNull() { if mysql.HasNotNullFlag(col.Flag) && col.ToInfo().OriginDefaultValue == nil { - return false, errors.New("Miss") + 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()) @@ -648,7 +648,7 @@ func rowWithCols(sessCtx sessionctx.Context, txn kv.Retriever, t table.Table, h ri, ok := rowMap[col.ID] if !ok { if mysql.HasNotNullFlag(col.Flag) && col.ToInfo().OriginDefaultValue == nil { - return nil, errors.New("Miss") + 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())