Skip to content

Commit

Permalink
ddl: fix a bug when we backfill index with nil (#5319) (#5323)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala authored and shenli committed Dec 6, 2017
1 parent 4ed6cfc commit a5f7fc9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ddl/ddl_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,27 @@ func (s *testDBSuite) testAlterLock(c *C) {
s.mustExec(c, "alter table t_indx_lock add index (c1, c2), lock=none")
}

func (s *testDBSuite) TestAddMultiColumnsIndex(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use " + s.schemaName)

s.tk.MustExec("drop database if exists tidb;")
s.tk.MustExec("create database tidb;")
s.tk.MustExec("use tidb;")
s.tk.MustExec("create table tidb.test (a int auto_increment primary key, b int);")
s.tk.MustExec("insert tidb.test values (1, 1);")
s.tk.MustExec("update tidb.test set b = b + 1 where a = 1;")
s.tk.MustExec("insert into tidb.test values (2, 2);")
// Test that the b value is nil.
s.tk.MustExec("insert into tidb.test (a) values (3);")
s.tk.MustExec("insert into tidb.test values (4, 4);")
// Test that the b value is nil again.
s.tk.MustExec("insert into tidb.test (a) values (5);")
s.tk.MustExec("insert tidb.test values (6, 6);")
s.tk.MustExec("alter table tidb.test add index idx1 (a, b);")
s.tk.MustExec("admin check table test")
}

func (s *testDBSuite) TestAddIndex(c *C) {
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use " + s.schemaName)
Expand Down
2 changes: 2 additions & 0 deletions ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,8 @@ func (w *worker) getIndexRecord(t table.Table, colMap map[int64]*types.FieldType
idxColumnVal := w.rowMap[col.ID]
if _, ok := w.rowMap[col.ID]; ok {
idxVal[j] = idxColumnVal
// Make sure there is no dirty data.
delete(w.rowMap, col.ID)
continue
}
idxColumnVal, err = tables.GetColDefaultValue(w.ctx, col, w.defaultVals)
Expand Down

0 comments on commit a5f7fc9

Please sign in to comment.