From 0db1a50d1d9db615d4caf599077879cd1db4f938 Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 1 Aug 2018 11:36:22 +0800 Subject: [PATCH 1/2] executor: set the correct handle in DirtyDB when executing update statements (#7209) --- executor/write.go | 6 +++++- executor/write_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/executor/write.go b/executor/write.go index c0d8dbd7cdbb2..cfec063c83d76 100644 --- a/executor/write.go +++ b/executor/write.go @@ -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) diff --git a/executor/write_test.go b/executor/write_test.go index a385de7906432..3325f9aef38a4 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -1572,3 +1572,38 @@ 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") +} + +func (s *testSuite) TestUpdateAffectRowCnt(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("create table a(id int auto_increment, a int default null, primary key(id))") + tk.MustExec("insert into a values (1, 1001), (2, 1001), (10001, 1), (3, 1)") + tk.MustExec("update a set id = id*10 where a = 1001") + ctx := tk.Se.(sessionctx.Context) + c.Assert(ctx.GetSessionVars().StmtCtx.AffectedRows(), Equals, uint64(2)) + + tk.MustExec("drop table a") + tk.MustExec("create table a ( a bigint, b bigint)") + tk.MustExec("insert into a values (1, 1001), (2, 1001), (10001, 1), (3, 1)") + tk.MustExec("update a set a = a*10 where b = 1001") + ctx = tk.Se.(sessionctx.Context) + c.Assert(ctx.GetSessionVars().StmtCtx.AffectedRows(), Equals, uint64(2)) +} From 60d2d053d94e658c7e1ae5ef5dbe8f34be47145d Mon Sep 17 00:00:00 2001 From: Yu Shuaipeng Date: Wed, 1 Aug 2018 14:22:02 +0800 Subject: [PATCH 2/2] remove no cherry-pick test --- executor/write_test.go | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/executor/write_test.go b/executor/write_test.go index 3325f9aef38a4..a8f878a641b6c 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -1590,20 +1590,3 @@ func (s *testSuite) TestUpdateDelete(c *C) { tk.MustExec("admin check table ttt;") tk.MustExec("drop table ttt") } - -func (s *testSuite) TestUpdateAffectRowCnt(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("create table a(id int auto_increment, a int default null, primary key(id))") - tk.MustExec("insert into a values (1, 1001), (2, 1001), (10001, 1), (3, 1)") - tk.MustExec("update a set id = id*10 where a = 1001") - ctx := tk.Se.(sessionctx.Context) - c.Assert(ctx.GetSessionVars().StmtCtx.AffectedRows(), Equals, uint64(2)) - - tk.MustExec("drop table a") - tk.MustExec("create table a ( a bigint, b bigint)") - tk.MustExec("insert into a values (1, 1001), (2, 1001), (10001, 1), (3, 1)") - tk.MustExec("update a set a = a*10 where b = 1001") - ctx = tk.Se.(sessionctx.Context) - c.Assert(ctx.GetSessionVars().StmtCtx.AffectedRows(), Equals, uint64(2)) -}