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
executor: fix setting system variables to original values failed after auto analyze #37551
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
executor/adapter.go
Outdated
@@ -437,10 +437,12 @@ func (a *ExecStmt) Exec(ctx context.Context) (_ sqlexec.RecordSet, err error) { | |||
sctx := a.Ctx | |||
ctx = util.SetSessionID(ctx, sctx.GetSessionVars().ConnectionID) | |||
if _, ok := a.Plan.(*plannercore.Analyze); ok && sctx.GetSessionVars().InRestrictedSQL { | |||
oriStats, _ := sctx.GetSessionVars().GetSystemVar(variable.TiDBBuildStatsConcurrency) | |||
oriStats, err := sctx.GetSessionVars().GetSessionOrGlobalSystemVar(variable.TiDBBuildStatsConcurrency) | |||
terror.Log(err) |
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.
GetSystemVar returns empty values for both system variables in an internal session
I think we should try to avoid it, if it is not trivial to do so, we could use the default value as 'oriStats' here.
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.
It seems not trivial to use the global system variable value to initialize the session system variable for internal sessions because we need the first internal session to read the global system variable value from disk. The two quick-fix ways are:
- When
GetSystemVar
returns empty value, use the default value. - Use
GetSessionOrGlobalSystemVar
(use the session system variable value if it exists, otherwise use the global system variable value).
Which ways do you prefer?
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.
I think to be default value is fine
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.
defaults are safer for internal sessions. Probably outside of the scope here, but we should even consider making internal sessions only use defaults unless a variable has a special flag saying it should apply to internal sessions.
Consider the case that the user changes the Txn Isolation, Optimistic/Pessimistic locking, change in lock wait timeout etc. These could affect how statements execute quite a lot, resulting in bugs.
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.
Changed to use default value. PTAL @xiongjiwei @morgo @bb7133
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 2d36f15
|
/run-check_dev_2 |
@xuyifangreeneyes: Your PR was out of date, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
What problem does this PR solve?
Issue Number: close #37410
Problem Summary:
What is changed and how it works?
When saving original values of
TiDBBuildStatsConcurrency
andTxnIsolation
before auto analyze,GetSystemVar
returns empty values for both system variables in an internal session, which causes restoring original values after auto analyze failed. The pr usesGetSessionOrGlobalSystemVar
, which would not return empty values, to replaceGetSystemVar
.Check List
Tests
Trigger auto analyze and see no error log like #37410.
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.