-
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 a sporadic panic due to the PR #7684 when using the prepared plan cache #7956
planner: fix a sporadic panic due to the PR #7684 when using the prepared plan cache #7956
Conversation
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
PTAL @jackysp |
/run-all-tests |
planner/core/optimizer.go
Outdated
@@ -66,6 +66,7 @@ type logicalOptRule interface { | |||
func BuildLogicalPlan(ctx sessionctx.Context, node ast.Node, is infoschema.InfoSchema) (Plan, error) { | |||
ctx.GetSessionVars().PlanID = 0 | |||
ctx.GetSessionVars().PlanColumnID = 0 | |||
ctx.GetSessionVars().StmtCtx.UseCache = false |
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.
StmtCtx.UseCache
is set in: https://github.com/pingcap/tidb/blob/master/executor/prepared.go#L155
Then the function BuildLogicalPlan()
is called. Maybe it's better to set StmtCtx.UseCache
to false before the function BuildLogicalPlan()
call: https://github.com/pingcap/tidb/blob/master/executor/prepared.go#L162
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.
If we can ensure calling BuildLogicalPlan()
at prepared.go#L162
only, setting the variable at the location as you said is good. Otherwise, setting the variable in BuildLogicalPlan()
might be a good choice in order to prevent from a potential risk because StmtCtx.UseCache
should be false in the call paths of BuildLogicalPlan()
.
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 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.
You can get the similar result by:
find . -name "*.go" | xargs grep --color -n "\<BuildLogicalPlan\>"
@zz-jason Thank you for the comment. I've updated the PR. |
/run-all-tests |
/run-all-tests |
@dbjoa I will add a integeration test in internal test repo to cover this question. |
/run-all-tests tidb-test=pr/637 |
It's a simple test case: public void testPrepareCacheIssue8065() throws Exception {
createTable("test_prepare1", "(a int)");
createTable("test_prepare2", "(a int, b int)");
try {
try (PreparedStatement pStmt = this.conn.prepareStatement("select * from test_prepare1 where a = ?")) {
pStmt.setInt(1, 1);
this.rs = pStmt.executeQuery();
while(this.rs.next()) {}
}
try (PreparedStatement pStmt = this.conn.prepareStatement("select * from test_prepare2 where a = ? and b = ?")) {
pStmt.setInt(1, 1);
pStmt.setInt(2, 2);
this.rs = pStmt.executeQuery();
while(this.rs.next()) {}
}
} finally {
if (this.rs != null) {
this.rs.close();
}
this.rs = null;
}
} and 9643cde make plan-cache enable in CI env |
…pared plan cache main: default enable prepare plan cache in test env
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
PTAL @lysu |
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
/run-all-tests |
…he prepared plan cache (pingcap#7956)
What problem does this PR solve?
fixes #8065
Fix the panics are occurred sporadically after merging the PR #7684 when using the prepared plan cache.
What is changed and how it works?
Initialize UseCache of the statement context in BuildLogicalPlan
Check List
Tests
Code changes
Side effects
Related changes