Skip to content

Commit

Permalink
admin: fix admin check table err when add column not null, then add i…
Browse files Browse the repository at this point in the history
…ndex on the column (#9108) (#9470)
  • Loading branch information
crazycs520 authored and zimulala committed Feb 26, 2019
1 parent c71588e commit 604b68e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,14 @@ func (s *testSuite) TestAdminCheckTable(c *C) {
tk.MustExec(`ALTER TABLE t1 ADD INDEX idx5 (c5)`)
tk.MustExec(`ALTER TABLE t1 ADD INDEX idx6 (c6)`)
tk.MustExec(`admin check table t1`)

// 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 *testSuite) TestAdminShowNextID(c *C) {
Expand Down
8 changes: 4 additions & 4 deletions util/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,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())
Expand Down Expand Up @@ -538,8 +538,8 @@ func rowWithCols(sessCtx sessionctx.Context, txn kv.Retriever, t table.Table, h
}
ri, ok := row[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())
Expand Down

0 comments on commit 604b68e

Please sign in to comment.