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

planner: push down Lock to PointGet and BatchPointGet #15257

Merged
merged 5 commits into from
Mar 11, 2020

Conversation

coocood
Copy link
Member

@coocood coocood commented Mar 10, 2020

What problem does this PR solve?

  • Lock non-exist keys if DataSource is PointGet or BatchPointGet.
  • Make BatchPointGet supports Update and Delete.

What is changed and how it works?

PointGet and BatchPointGet supports lock by itself, so we can push down
the lock operation down to PointGet and BatchPointGet to lock non-exist keys.

They also read data from MemBuffer, so UnionScan can be eliminated.

By add a function in postOptimize, we can eliminate UnionScan and push down lock to PointGet and BatchPointGet.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Related changes

  • Need to update the documentation

Release note

  • Lock non-exist keys if DataSource is PointGet or BatchPointGet.

PointGet and BatchPointGet supports lock by itself, so we can push down
the lock operation down to PointGet and BatchPointGet to lock non-exist keys.

They also read data from MemBuffer, so UnionScan can be eliminated.
@coocood coocood requested review from a team as code owners March 10, 2020 07:17
@ghost ghost requested review from francis0407, lzmhhh123, qw4990 and XuHuaiyu and removed request for a team March 10, 2020 07:17
@coocood
Copy link
Member Author

coocood commented Mar 10, 2020

@lzmhhh123 @cfzjywxk @tiancaiamao PTAL

@github-actions github-actions bot added sig/execution SIG execution sig/planner SIG: Planner labels Mar 10, 2020
@qw4990 qw4990 removed their request for review March 10, 2020 07:47
Comment on lines +197 to +212
iteratePhysicalPlan(p, func(p PhysicalPlan) bool {
if len(p.Children()) > 1 {
return false
}
switch x := p.(type) {
case *PointGetPlan:
pointGet = x
case *BatchPointGetPlan:
batchPointGet = x
case *PhysicalLock:
physLock = x
case *PhysicalUnionScan:
unionScan = x
}
return true
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about doing transformPhysicalPlan here to reduce plan tree iteration?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transform is post-order, iterate is pre-order.
Use pre-order to iterate so we can stop early, and we can not do transform in pre-order.

return p
}
if physLock == nil {
return p
Copy link
Contributor

@lysu lysu Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we eliminate unionScan even if it's a select without for update?

begin pessimistic;
insert t values (8, 8)
explain select c + 1 from t where k = 2 and c = 2; // no need unionScan too?

// verify that select with project and filter on a non exists key still locks the key.
tk.MustExec("begin pessimistic")
tk.MustExec("insert t values (8, 8)") // Make the transaction dirty.
tk.MustQuery("select c + 1 from t where k = 2 and c = 2 for update").Check(testkit.Rows())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we change this sql to

select c + 1 from t where k = (2, 3) and c = 2 for update

(3, 3) also be locked after this pr, but mysql seems do the same things - -

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is expected, we lock it even if it doesn't pass the filter.

@codecov
Copy link

codecov bot commented Mar 11, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@ac2fa18). Click here to learn what that means.
The diff coverage is 100%.

@@             Coverage Diff             @@
##             master     #15257   +/-   ##
===========================================
  Coverage          ?   80.3457%           
===========================================
  Files             ?        503           
  Lines             ?     132989           
  Branches          ?          0           
===========================================
  Hits              ?     106851           
  Misses            ?      17731           
  Partials          ?       8407

Copy link
Contributor

@lzmhhh123 lzmhhh123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lzmhhh123 lzmhhh123 added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 11, 2020
lysu
lysu previously approved these changes Mar 11, 2020
Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lysu lysu added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 11, 2020
@coocood
Copy link
Member Author

coocood commented Mar 11, 2020

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 11, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Mar 11, 2020

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Mar 11, 2020

@coocood merge failed.

@lzmhhh123
Copy link
Contributor

/merge

@sre-bot
Copy link
Contributor

sre-bot commented Mar 11, 2020

Your auto merge job has been accepted, waiting for 15238

@sre-bot
Copy link
Contributor

sre-bot commented Mar 11, 2020

/run-all-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution sig/planner SIG: Planner status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants