diff --git a/table/tables/tables.go b/table/tables/tables.go index 014a11f8fbb0e..2d702b79b5c0a 100644 --- a/table/tables/tables.go +++ b/table/tables/tables.go @@ -481,9 +481,12 @@ func (t *TableCommon) UpdateRecord(ctx context.Context, sctx sessionctx.Context, }) if t.shouldAssert(sctx) { - if err = txn.SetAssertion(key, kv.SetAssertExist); err != nil { - return err - } + err = txn.SetAssertion(key, kv.SetAssertExist) + } else { + err = txn.SetAssertion(key, kv.SetAssertUnknown) + } + if err != nil { + return err } if err = injectMutationError(t, txn, sh); err != nil { @@ -1346,9 +1349,11 @@ func (t *TableCommon) removeRowData(ctx sessionctx.Context, h kv.Handle) error { }) if t.shouldAssert(ctx) { err = txn.SetAssertion(key, kv.SetAssertExist) - if err != nil { - return err - } + } else { + err = txn.SetAssertion(key, kv.SetAssertUnknown) + } + if err != nil { + return err } return txn.Delete(key) } diff --git a/tests/realtikvtest/sessiontest/session_fail_test.go b/tests/realtikvtest/sessiontest/session_fail_test.go index a3df51be821c0..ad986c5386350 100644 --- a/tests/realtikvtest/sessiontest/session_fail_test.go +++ b/tests/realtikvtest/sessiontest/session_fail_test.go @@ -203,3 +203,24 @@ func TestKill(t *testing.T) { tk := testkit.NewTestKit(t, store) tk.MustExec("kill connection_id();") } + +func TestIssue42426(t *testing.T) { + store := realtikvtest.CreateMockStoreAndSetup(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("CREATE TABLE `sbtest1` (" + + "`id` bigint(20) NOT NULL AUTO_INCREMENT," + + "`k` int(11) NOT NULL DEFAULT '0'," + + "`c` char(120) NOT NULL DEFAULT ''," + + "`pad` char(60) NOT NULL DEFAULT ''," + + "PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */," + + "KEY `k_1` (`k`)" + + ") PARTITION BY RANGE (`id`)" + + "(PARTITION `pnew` VALUES LESS THAN (10000000)," + + "PARTITION `p5` VALUES LESS THAN (MAXVALUE));") + tk.MustExec(`INSERT INTO sbtest1 (id, k, c, pad) VALUES (502571, 499449, "init", "val");`) + tk.MustExec(`BEGIN`) + tk.MustExec(`DELETE FROM sbtest1 WHERE id=502571;`) + tk.MustExec(`INSERT INTO sbtest1 (id, k, c, pad) VALUES (502571, 499449, "abc", "def");`) + tk.MustExec(`COMMIT;`) +}