Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: set the correct handle in DirtyDB when executing update sta… #7219

Merged
merged 2 commits into from
Aug 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion executor/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ func updateRecord(ctx sessionctx.Context, h int64, oldData, newData []types.Datu

tid := t.Meta().ID
ctx.StmtAddDirtyTableOP(DirtyTableDeleteRow, tid, h, nil)
ctx.StmtAddDirtyTableOP(DirtyTableAddRow, tid, h, newData)
if handleChanged {
ctx.StmtAddDirtyTableOP(DirtyTableAddRow, tid, newHandle, newData)
} else {
ctx.StmtAddDirtyTableOP(DirtyTableAddRow, tid, h, newData)
}

if onDup {
sc.AddAffectedRows(2)
Expand Down
18 changes: 18 additions & 0 deletions executor/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1572,3 +1572,21 @@ func (s *testSuite) TestUpdateSelect(c *C) {
tk.MustExec("UPDATE msg SET msg.status = (SELECT detail.status FROM detail WHERE msg.id = detail.id)")
tk.MustExec("admin check table msg")
}

func (s *testSuite) TestUpdateDelete(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("CREATE TABLE ttt (id bigint(20) NOT NULL, host varchar(30) NOT NULL, PRIMARY KEY (id), UNIQUE KEY i_host (host));")
tk.MustExec("insert into ttt values (8,8),(9,9);")

tk.MustExec("begin")
tk.MustExec("update ttt set id = 0, host='9' where id = 9 limit 1;")
tk.MustExec("delete from ttt where id = 0 limit 1;")
tk.MustQuery("select * from ttt use index (i_host) order by host;").Check(testkit.Rows("8 8"))
tk.MustExec("update ttt set id = 0, host='8' where id = 8 limit 1;")
tk.MustExec("delete from ttt where id = 0 limit 1;")
tk.MustQuery("select * from ttt use index (i_host) order by host;").Check(testkit.Rows())
tk.MustExec("commit")
tk.MustExec("admin check table ttt;")
tk.MustExec("drop table ttt")
}