Skip to content

Commit

Permalink
executor: fix deadloop when exec replace with generated column
Browse files Browse the repository at this point in the history
  • Loading branch information
amyangfei committed May 6, 2019
1 parent 62d37a8 commit 97c4e9a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions executor/replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ func (e *ReplaceExec) removeIndexRow(r toBeCheckedRow) (bool, bool, error) {
if err != nil {
return false, found, err
}
if !rowUnchanged {
delete(e.dupKVs, string(uk.newKV.key))
}
return rowUnchanged, found, nil
}
}
Expand Down
14 changes: 14 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,20 @@ func (s *testSuite2) TestReplace(c *C) {
tk.MustExec(`replace into t1 select * from (select 1, 2) as tmp;`)
c.Assert(int64(tk.Se.AffectedRows()), Equals, int64(2))
tk.CheckLastMessage("Records: 1 Duplicates: 1 Warnings: 0")

// Test Replace with generated column
tk.MustExec(`drop table if exists t1;`)
tk.MustExec("create table t1(id int, id_gen int as(`id` + 42), b int, unique key id_gen(`id_gen`));")
tk.MustExec(`insert into t1 (id, b) values(1,1),(2,2),(3,3),(4,4),(5,5);`)
tk.MustExec(`replace into t1 (id, b) values(1,1);`)
r.Check(testkit.Rows("ERROR 1062 Duplicate entry '43' for key 'id_gen'"))
tk.CheckLastMessage("")
tk.MustExec(`replace into t1 (id, b) values(1,1),(2,2);`)
r.Check(testkit.Rows("ERROR 1062 Duplicate entry '43' for key 'id_gen'"))
tk.CheckLastMessage("")
tk.MustExec(`replace into t1 (id, b) values(6,16),(7,17),(8,18);`)
c.Assert(int64(tk.Se.AffectedRows()), Equals, int64(3))
tk.CheckLastMessage("Records: 3 Duplicates: 0 Warnings: 0")
}

func (s *testSuite2) TestPartitionedTableReplace(c *C) {
Expand Down

0 comments on commit 97c4e9a

Please sign in to comment.