-
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: fix wrong prepare plan after isolation read changed #16293
planner: fix wrong prepare plan after isolation read changed #16293
Conversation
planner/core/common_plans.go
Outdated
@@ -229,20 +230,24 @@ func (e *Execute) OptimizePreparedPlan(ctx context.Context, sctx sessionctx.Cont | |||
} | |||
} | |||
|
|||
if prepared.SchemaVersion != is.SchemaMetaVersion() { | |||
if prepared.SchemaVersion != is.SchemaMetaVersion() || !reflect.DeepEqual(preparedObj.IsolationEngines, e.ctx.GetSessionVars().IsolationReadEngines) { |
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.
How about not use reflect.DeepEqual
?
func prepare() (map[string]struct{}, map[string]struct{}) {
m1 := make(map[string]struct{}, 3)
m1["tikv"] = struct{}{}
m1["tidb"] = struct{}{}
m1["tiflash"] = struct{}{}
m2 := make(map[string]struct{}, 3)
m2["tikv"] = struct{}{}
m2["tidb"] = struct{}{}
m2["tiflash"] = struct{}{}
return m1, m2
}
func Benchmark_cmp1(b *testing.B) {
m1, m2 := prepare()
for i := 0; i < b.N; i++ {
reflect.DeepEqual(m1, m2)
}
}
func Benchmark_cmp2(b *testing.B) {
m1, m2 := prepare()
for i := 0; i < b.N; i++ {
checkEqualMap(m1, m2)
}
}
func checkEqualMap(m1, m2 map[string]struct{}) bool {
if len(m1) != len(m2) {
return false
}
for k := range m1 {
if _, ok := m2[k]; !ok {
return false
}
}
return true
}
▶ go test -run '^$' -bench .
goos: darwin
goarch: amd64
pkg: github.com/crazycs520/test
Benchmark_cmp1-12 2272569 521 ns/op
Benchmark_cmp2-12 21689436 54.1 ns/op
PASS
ok github.com/crazycs520/test 2.955s
Codecov Report
@@ Coverage Diff @@
## master #16293 +/- ##
===========================================
Coverage 79.8503% 79.8503%
===========================================
Files 520 520
Lines 139888 139888
===========================================
Hits 111701 111701
Misses 19231 19231
Partials 8956 8956 |
LGTM |
/run-all-tests |
I prefer to add isolation read engines to the key of the prepared plan cache. It's different from schema change. schema version change is unpreventable, but isolation read engine change is. Once the user changed back to the original value of the isolation read engine, the cache can be used again at that time. @eurekaka What's your opinion? |
+1 |
OK, I'll change it to that way. |
21a206b
to
bf54be0
Compare
/rebuild |
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
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
Your auto merge job has been accepted, waiting for:
|
/run-all-tests |
@lzmhhh123 merge failed. |
/merge |
2 similar comments
/merge |
/merge |
/run-all-tests |
@lzmhhh123 merge failed. |
/run-all-tests |
@lzmhhh123 merge failed. |
/run-all-tests |
@lzmhhh123 merge failed. |
/run-cherry-pick |
/run-cherry-picker |
Signed-off-by: sre-bot <sre-bot@pingcap.com>
cherry pick to release-4.0 in PR #17570 |
What problem does this PR solve?
Issue Number: close #16256
Problem Summary: After isolation read changed, the prepared statement should be re-prepared.
What is changed and how it works?
What's Changed: clear prepared plan when isolation read changes.
Related changes
Check List
Tests
Side effects
Release note