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

executor: fix setting system variables to original values failed after auto analyze #37551

Merged
merged 8 commits into from Sep 14, 2022

Conversation

xuyifangreeneyes
Copy link
Contributor

@xuyifangreeneyes xuyifangreeneyes commented Sep 1, 2022

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 and TxnIsolation 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 uses GetSessionOrGlobalSystemVar, which would not return empty values, to replace GetSystemVar.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Trigger auto analyze and see no error log like #37410.

  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Sep 1, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • qw4990
  • xiongjiwei

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 1, 2022
@@ -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)
Copy link
Member

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.

Copy link
Contributor Author

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:

  1. When GetSystemVar returns empty value, use the default value.
  2. Use GetSessionOrGlobalSystemVar(use the session system variable value if it exists, otherwise use the global system variable value).
    Which ways do you prefer?

Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

@ti-chi-bot ti-chi-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Sep 14, 2022
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 14, 2022
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 14, 2022
@qw4990
Copy link
Contributor

qw4990 commented Sep 14, 2022

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 2d36f15

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Sep 14, 2022
@hawkingrei
Copy link
Member

/run-check_dev_2

@ti-chi-bot
Copy link
Member

@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.

@ti-chi-bot ti-chi-bot merged commit 0f4c3e6 into pingcap:master Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none size/S Denotes a PR that changes 10-29 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Master: tidb hit Incorrect argument type to variable 'tidb_build_stats_concurrency' and 'tx_isolation'
8 participants