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

*: add the tid to the schema-change related tables only when keys need to be locked (#15698) #15708

Merged
merged 1 commit into from
Mar 26, 2020
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
14 changes: 8 additions & 6 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,12 +776,6 @@ func (e *SelectLockExec) Open(ctx context.Context) error {
return err
}

txnCtx := e.ctx.GetSessionVars().TxnCtx
for id := range e.Schema().TblID2Handle {
// This operation is only for schema validator check.
txnCtx.UpdateDeltaForTable(id, 0, 0, map[int64]int64{})
}

if len(e.Schema().TblID2Handle) > 0 && len(e.partitionedTable) > 0 {
e.tblID2Table = make(map[int64]table.PartitionedTable, len(e.partitionedTable))
for id := range e.Schema().TblID2Handle {
Expand Down Expand Up @@ -835,6 +829,14 @@ func (e *SelectLockExec) Next(ctx context.Context, req *chunk.Chunk) error {
return nil
}
lockWaitTime := e.ctx.GetSessionVars().LockWaitTimeout

if len(e.keys) > 0 {
// This operation is only for schema validator check.
for id := range e.Schema().TblID2Handle {
e.ctx.GetSessionVars().TxnCtx.UpdateDeltaForTable(id, 0, 0, map[int64]int64{})
}
}

return doLockKeys(ctx, e.ctx, newLockCtx(e.ctx.GetSessionVars(), lockWaitTime), e.keys...)
}

Expand Down
22 changes: 22 additions & 0 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,28 @@ func (s *testSchemaSuite) TestCommitWhenSchemaChanged(c *C) {
c.Assert(terror.ErrorEqual(err, plannercore.ErrWrongValueCountOnRow), IsTrue, Commentf("err %v", err))
}

func (s *testSchemaSuite) TestRetrySchemaChangeForEmptyChange(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk1 := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("create table t (i int)")
tk.MustExec("create table t1 (i int)")
tk.MustExec("begin")
tk1.MustExec("alter table t add j int")
tk.MustExec("select * from t for update")
tk.MustExec("update t set i = -i")
tk.MustExec("delete from t")
tk.MustExec("insert into t1 values (1)")
tk.MustExec("commit")

tk.MustExec("begin pessimistic")
tk1.MustExec("alter table t add k int")
tk.MustExec("select * from t for update")
tk.MustExec("update t set i = -i")
tk.MustExec("delete from t")
tk.MustExec("insert into t1 values (1)")
tk.MustExec("commit")
}

func (s *testSchemaSuite) TestRetrySchemaChange(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk1 := testkit.NewTestKitWithInit(c, s.store)
Expand Down