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

planner: fix the issue of reusing wrong point-plan for "select ... for update" #54661

Merged
merged 7 commits into from
Jul 17, 2024

Conversation

qw4990
Copy link
Contributor

@qw4990 qw4990 commented Jul 16, 2024

What problem does this PR solve?

Issue Number: close #54652

Problem Summary: planner: fix the issue of reusing wrong point-plan for "select ... for update"

What changed and how does it work?

Encode more txn state into the plan cache key, and check whether the key has changed before reusing point-get plans.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

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 ti-chi-bot bot added do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 16, 2024
Copy link

tiprow bot commented Jul 16, 2024

Hi @qw4990. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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 kubernetes-sigs/prow repository.

Copy link
Contributor

@cfzjywxk cfzjywxk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, some refactor and improvements mentioned by @MyonKeminta could be done in later PRs.

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 16, 2024
Copy link

codecov bot commented Jul 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.0969%. Comparing base (ac92026) to head (4a9e070).
Report is 665 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54661         +/-   ##
=================================================
- Coverage   72.8656%   56.0969%   -16.7687%     
=================================================
  Files          1551       1672        +121     
  Lines        436701     611860     +175159     
=================================================
+ Hits         318205     343235      +25030     
- Misses        98995     245315     +146320     
- Partials      19501      23310       +3809     
Flag Coverage Δ
integration 37.2284% <100.0000%> (?)
unit 71.8417% <100.0000%> (-0.0520%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9656% <ø> (ø)
parser ∅ <ø> (∅)
br 52.5910% <ø> (+6.7270%) ⬆️

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 16, 2024
Copy link

ti-chi-bot bot commented Jul 16, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-16 08:50:40.972857862 +0000 UTC m=+343862.963799332: ☑️ agreed by cfzjywxk.
  • 2024-07-16 09:07:52.816627233 +0000 UTC m=+344894.807568703: ☑️ agreed by AilinKid.

Copy link

tiprow bot commented Jul 16, 2024

@qw4990: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow 4484661 link true /test fast_test_tiprow

Full PR test history. Your PR dashboard.

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 kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link
Contributor

@MyonKeminta MyonKeminta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

@@ -935,7 +935,7 @@ func TestMDLPreparePlanCacheExecute(t *testing.T) {
tk.MustQuery("select * from t2")
tk.MustExec(`set @a = 2, @b=4;`)
tk.MustExec(`execute stmt_test_1 using @a, @b;`)
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1"))
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also have a separated test case for the case about preparing select ... for update statement outside transaction? This test targets on testing MDL, and I'm afraid that this test might being modified / removed without being known by us and making the case lose coverage...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I enhancemented this test, PTAL

@qw4990
Copy link
Contributor Author

qw4990 commented Jul 17, 2024

/retest

Copy link

tiprow bot commented Jul 17, 2024

@qw4990: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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 kubernetes-sigs/prow repository.

tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
tk.MustExec(`execute stmt_test_1 using @a, @b;`) // can't reuse the prior plan since this table becomes dirty.
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
tk.MustExec(`execute stmt_test_1 using @a, @b;`) // can't reuse the prior plan now.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tk.MustExec(`execute stmt_test_1 using @a, @b;`) // can't reuse the prior plan now.
tk.MustExec(`execute stmt_test_1 using @a, @b;`) // can reuse the prior plan now.

Did you mean this?

Copy link

ti-chi-bot bot commented Jul 17, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, cfzjywxk, MyonKeminta, wjhuang2016

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Jul 17, 2024
@ti-chi-bot ti-chi-bot bot merged commit e1626a9 into pingcap:master Jul 17, 2024
21 checks passed
@ti-chi-bot ti-chi-bot added the needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. label Jul 17, 2024
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jul 17, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #54680.

ti-chi-bot bot pushed a commit that referenced this pull request Jul 18, 2024
@ti-chi-bot ti-chi-bot added needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. labels Jul 25, 2024
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jul 25, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #54891.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jul 25, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #54892.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #54938.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jul 26, 2024
ti-chi-bot bot pushed a commit that referenced this pull request Aug 1, 2024
ti-chi-bot bot pushed a commit that referenced this pull request Sep 5, 2024
@qw4990 qw4990 added the type/bugfix This PR fixes a bug. label Oct 9, 2024
ti-chi-bot bot pushed a commit that referenced this pull request Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

planner, txn: select ... for update using Plan Cache can not lock data correctly in some cases
6 participants