-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: check schema stale for plan cache when forUpdateRead #22381
Conversation
Signed-off-by: you06 <[email protected]>
Signed-off-by: you06 <[email protected]>
Signed-off-by: you06 <[email protected]>
Signed-off-by: you06 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
LGTM |
Do not merge this PR now. |
Signed-off-by: you06 <[email protected]>
session/pessimistic_test.go
Outdated
c.Assert(err, IsNil) | ||
tk2.CheckExecResult(1, 0) | ||
// FIXME: should hit plan cache here | ||
tk2.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There still exist a problem, plan cache will not hit here.
Signed-off-by: you06 <[email protected]>
delete(sessVars.IsolationReadEngines, kv.TiFlash) | ||
cacheKey = NewPSTMTPlanCacheKey(sctx.GetSessionVars(), e.ExecID, prepared.SchemaVersion) | ||
sessVars.IsolationReadEngines[kv.TiFlash] = struct{}{} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When use binary protocol and the plan cache is not hit, a new cache will generate inside getPhysicalPlan
function, in which use the following codes to exclude TiFlash
engine for write statement.
Lines 85 to 88 in 2364fec
delete(sessVars.IsolationReadEngines, kv.TiFlash) | |
defer func() { | |
sessVars.IsolationReadEngines[kv.TiFlash] = struct{}{} | |
}() |
After the plan is builing complete, the
TiFlash
engine is set back and the it'll still write a plan-cache key with TiFlash
engine. As a result, we cache a write plan for TiFlash
engine, and it'll never be used correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😮 @winoros PTAL
Signed-off-by: you06 <[email protected]>
I think this bug is serious, @winoros can you help reviewing it? Thanks! |
@you06 |
Signed-off-by: you06 <[email protected]>
Signed-off-by: you06 <[email protected]>
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 5702b0e
|
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-5.0 in PR #23435 |
What problem does this PR solve?
Issue Number: #21498 will also affected plan cache.
Problem Summary:
What is changed and how it works?
What's Changed: when the plan is using forUpdateRead, we need to use the latest schema to check if plan is valid.
How it Works:
Update schema version when required.
Related changes
Check List
Tests
Release note