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: add missing update table delta for TxnCtx #20982

Merged
merged 20 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9cd935a
executor: add missing update table delta for TxnCtx
blacktear23 Nov 11, 2020
d509a28
executor: fix typo
blacktear23 Nov 11, 2020
cb2ea6a
executor: fix for test
blacktear23 Nov 11, 2020
d4a45ec
Merge branch 'master' into issue-20975
blacktear23 Nov 11, 2020
c62a393
executor: fix missing UpdateDeltaForTable for SelectLockExec
blacktear23 Nov 11, 2020
4079141
Merge branch 'issue-20975' of github.com:blacktear23/tidb into issue-…
blacktear23 Nov 11, 2020
9627f21
executor: refactor, move codes
blacktear23 Nov 11, 2020
c0f805a
Merge branch 'master' into issue-20975
AilinKid Nov 11, 2020
ec32bc4
executor: fix for point get and batch point get
blacktear23 Nov 11, 2020
fee7a5d
Merge branch 'issue-20975' of github.com:blacktear23/tidb into issue-…
blacktear23 Nov 11, 2020
a22e309
executor: refactor and add more unit test;
blacktear23 Nov 12, 2020
27b2e61
executor: Refactor, make updateDeltaForTableID call once after initia…
blacktear23 Nov 13, 2020
1e2e73a
Merge branch 'master' into issue-20975
blacktear23 Nov 13, 2020
f191c97
Merge branch 'master' into issue-20975
blacktear23 Nov 16, 2020
8c3ae1b
sessionctx: add lock for write TableDeltaMap
blacktear23 Nov 16, 2020
6124bf9
Merge branch 'issue-20975' of github.com:blacktear23/tidb into issue-…
blacktear23 Nov 16, 2020
dee9e78
Merge branch 'master' into issue-20975
blacktear23 Nov 17, 2020
7073ddd
executor: add partition table tests for issue 20975
blacktear23 Nov 18, 2020
bd78ed7
Merge branch 'master' into issue-20975
blacktear23 Nov 18, 2020
94c5206
Merge branch 'master' into issue-20975
blacktear23 Nov 18, 2020
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
10 changes: 9 additions & 1 deletion executor/batch_point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ func (e *BatchPointGetExec) Next(ctx context.Context, req *chunk.Chunk) error {
}
}

if e.lock {
blacktear23 marked this conversation as resolved.
Show resolved Hide resolved
blacktear23 marked this conversation as resolved.
Show resolved Hide resolved
e.updateDeltaForTableID(e.tblInfo.ID)
}

if e.index >= len(e.values) {
return nil
}
Expand Down Expand Up @@ -232,7 +236,11 @@ func (e *BatchPointGetExec) initialize(ctx context.Context) error {
}
e.handles = append(e.handles, handle)
if e.tblInfo.Partition != nil {
e.physIDs = append(e.physIDs, tablecodec.DecodeTableID(key))
pid := tablecodec.DecodeTableID(key)
e.physIDs = append(e.physIDs, pid)
if e.lock {
e.updateDeltaForTableID(pid)
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ func (e *baseExecutor) Next(ctx context.Context, req *chunk.Chunk) error {
return nil
}

func (e *baseExecutor) updateDeltaForTableID(id int64) {
txnCtx := e.ctx.GetSessionVars().TxnCtx
udpp := e.ctx.GetSessionVars().UseDynamicPartitionPrune()
txnCtx.UpdateDeltaForTable(id, id, 0, 0, map[int64]int64{}, udpp)
}

func newBaseExecutor(ctx sessionctx.Context, schema *expression.Schema, id int, children ...Executor) baseExecutor {
e := baseExecutor{
children: children,
Expand Down Expand Up @@ -943,6 +949,18 @@ func (e *SelectLockExec) Next(ctx context.Context, req *chunk.Chunk) error {
lockWaitTime = int64(e.Lock.WaitSec) * 1000
}

if len(e.tblID2Handle) > 0 {
for id := range e.tblID2Handle {
e.updateDeltaForTableID(id)
}
}
if len(e.partitionedTable) > 0 {
for _, p := range e.partitionedTable {
pid := p.Meta().ID
e.updateDeltaForTableID(pid)
}
}

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

Expand Down
58 changes: 58 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6815,3 +6815,61 @@ func (s *testSuite) TestIssue19667(c *C) {
tk.MustExec("INSERT INTO t VALUES('1988-04-17 01:59:59')")
tk.MustQuery(`SELECT DATE_ADD(a, INTERVAL 1 SECOND) FROM t`).Check(testkit.Rows("1988-04-17 02:00:00"))
}

blacktear23 marked this conversation as resolved.
Show resolved Hide resolved
func issue20975Prepare(c *C, store kv.Storage) (*testkit.TestKit, *testkit.TestKit) {
tk1 := testkit.NewTestKit(c, store)
tk2 := testkit.NewTestKit(c, store)
tk1.MustExec("use test")
tk1.MustExec("drop table if exists t1, t2")
tk2.MustExec("use test")
tk1.MustExec("create table t1(id int primary key, c int)")
tk1.MustExec("insert into t1 values(1, 10), (2, 20)")
return tk1, tk2
}

func (s *testSuite) TestIssue20975UpdateNoChange(c *C) {
tk1, tk2 := issue20975Prepare(c, s.store)
tk1.MustExec("begin pessimistic")
tk1.MustExec("update t1 set c=c")
tk2.MustExec("create table t2(a int)")
tk1.MustExec("commit")
}

func (s *testSuite) TestIssue20975SelectForUpdate(c *C) {
tk1, tk2 := issue20975Prepare(c, s.store)
tk1.MustExec("begin")
tk1.MustExec("select * from t1 for update")
tk2.MustExec("create table t2(a int)")
tk1.MustExec("commit")

tk1.MustExec("begin pessimistic")
tk1.MustExec("select * from t1 for update")
tk2.MustExec("drop table t2")
tk1.MustExec("commit")
}

func (s *testSuite) TestIssue20975SelectForUpdatePointGet(c *C) {
tk1, tk2 := issue20975Prepare(c, s.store)
tk1.MustExec("begin")
tk1.MustExec("select * from t1 where id=1 for update")
tk2.MustExec("create table t2(a int)")
tk1.MustExec("commit")

tk1.MustExec("begin pessimistic")
tk1.MustExec("select * from t1 where id=1 for update")
tk2.MustExec("drop table t2")
tk1.MustExec("commit")
}

func (s *testSuite) TestIssue20975SelectForUpdateBatchPointGet(c *C) {
tk1, tk2 := issue20975Prepare(c, s.store)
tk1.MustExec("begin")
tk1.MustExec("select * from t1 where id in (1, 2) for update")
tk2.MustExec("create table t2(a int)")
tk1.MustExec("commit")

tk1.MustExec("begin pessimistic")
tk1.MustExec("select * from t1 where id in (1, 2) for update")
tk2.MustExec("drop table t2")
tk1.MustExec("commit")
}
3 changes: 3 additions & 0 deletions executor/point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ func (e *PointGetExecutor) Next(ctx context.Context, req *chunk.Chunk) error {
} else {
tblID = e.tblInfo.ID
}
if e.lock {
e.updateDeltaForTableID(tblID)
}
if e.idxInfo != nil {
if isCommonHandleRead(e.tblInfo, e.idxInfo) {
handleBytes, err := EncodeUniqueIndexValuesForKey(e.ctx, e.tblInfo, e.idxInfo, e.idxVals)
Expand Down