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: Select-For-Update should skip the FastPlan #54773

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion pkg/planner/core/casetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ go_test(
],
data = glob(["testdata/**"]),
flaky = True,
shard_count = 26,
shard_count = 27,
deps = [
"//pkg/domain",
"//pkg/errno",
Expand Down
10 changes: 10 additions & 0 deletions pkg/planner/core/casetest/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,13 @@ WHERE res.state != 2
ORDER BY res.branch_id;
`, errno.ErrNotSupportedYet)
}

func TestSelectLockForPointGet(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t(a int key);")
tk.MustQuery("explain select * from t where a = 1 for update;").Check(testkit.Rows(
"SelectLock_6 1.00 root for update 0",
"└─Point_Get_7 1.00 root table:t handle:1"))
}
2 changes: 1 addition & 1 deletion pkg/planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ func TryFastPlan(ctx base.PlanContext, node ast.Node) (p base.Plan) {
ctx.GetSessionVars().PlanColumnID.Store(0)
switch x := node.(type) {
case *ast.SelectStmt:
if x.SelectIntoOpt != nil {
if x.SelectIntoOpt != nil || x.LockInfo != nil {
Copy link
Contributor

@cfzjywxk cfzjywxk Jul 19, 2024

Choose a reason for hiding this comment

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

The lock operations of point get and batch point get are push down. The original design of selectLockExec was only for cop reads that cannot be pushed down.

TryFastPlan is designed be used to generate point/batch point get plans with for update.

The issue is not a high priority one by now, better to resolve the plan display issue after some proper executor builder and transaction state refactor.

Copy link
Contributor

@AilinKid AilinKid Jul 24, 2024

Choose a reason for hiding this comment

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

so it's barely a explained issue, not the correctness one, right? 😂

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes the correctness one is #54652.
The severity of #54705 is moderate, there is also related behaviour fix checking lock is needed or not in https://github.com/pingcap/tidb/pull/54738/files#diff-359d434f5527f2d2157554bb9081bdc497f25e0a76253907fb5c9d1bdfb9b233L770.

return nil
}
defer func() {
Expand Down