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 rebuild range for prepared plan #23316

Closed
wants to merge 14 commits into from

Conversation

blacktear23
Copy link
Contributor

@blacktear23 blacktear23 commented Mar 15, 2021

What problem does this PR solve?

Issue Number: close #23304 close #23290

Problem Summary:

What is changed and how it works?

What's Changed:
Rebuild ranges for the prepared plan may get the wrong result. This PR will fix the BatchPointGet plan's Handle array to fix newly variables bind and will try to convert BatchPointGet to PointGet when newly variables will only have one handle, and it also can transform PointGet convert to BatchPointGet when variables may generate more than 1 handle.

How it Works:

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test

Side effects

  • Performance regression
    • Consumes more CPU
    • Consumes more MEM

Release note

  • Fix prepared plan will get wrong result when variables changed.

@blacktear23 blacktear23 requested review from a team as code owners March 15, 2021 09:08
@blacktear23 blacktear23 requested review from qw4990 and eurekaka and removed request for a team March 15, 2021 09:08
@ti-chi-bot ti-chi-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 15, 2021
@sre-bot
Copy link
Contributor

sre-bot commented Mar 15, 2021

Please follow PR Title Format:

  • pkg [, pkg2, pkg3]: what's changed

Or if the count of mainly changed packages are more than 3, use

  • *: what's changed

@blacktear23 blacktear23 changed the title [planner] Fix rebuild range for prepared plan [planner]: Fix rebuild range for prepared plan Mar 15, 2021
@blacktear23 blacktear23 changed the title [planner]: Fix rebuild range for prepared plan planner: Fix rebuild range for prepared plan Mar 15, 2021
@ichn-hu ichn-hu mentioned this pull request Mar 15, 2021
@github-actions github-actions bot added the sig/execution SIG execution label Mar 15, 2021
@zz-jason
Copy link
Member

zz-jason commented Mar 15, 2021

we need to cherry-pick this critical bug-fix to release 3.0, 4.0, and 5.0

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • winoros

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 writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 15, 2021
@blacktear23
Copy link
Contributor Author

@zz-jason this PR will not works with master branch. But it may work in 4.0 branch. The root cause for fail at master branch still need investigating.

@blacktear23
Copy link
Contributor Author

blacktear23 commented Mar 15, 2021

If comments

case *PointGetPlan:
case and below codes. Then PointGetPlan will not cached, this PR will work correctly. And seems #23290 will also be fixed. @bb7133

@XuHuaiyu
Copy link
Contributor

If this commit can also fix #23290, we may also add this issue number in the PR description. @blacktear23

@blacktear23
Copy link
Contributor Author

blacktear23 commented Mar 16, 2021

@zz-jason After review release-4.0 branch, the code is not same as current master, I think we should create a new PR for other release branches. And I found the code for special process PointGetPlan cache maybe the base cause for those Bugs. The cached PointGetPlan cannot update AccessConditions, so it will generate wrong ranges when variables changes. So I think disable special PointGetPlan cache logic maybe the best way to fix.

And I found UseCache is always false for release-4.0 and master branch. This can disable other plan cache, but it cannot disable PointGetPlan special cache. And I found in some day before 2021-1-12 it switch to true but then some day after 2021-1-12 it turn to false again.

@eurekaka
Copy link
Contributor

eurekaka commented Mar 16, 2021

I think #23238 can fix both #23304 and #23290 as well.

@blacktear23
Copy link
Contributor Author

@eurekaka After read your PR, it will fix not cache PointGetPlan, but if enable prepared plan cache and BatchPointGet plan got cached, I think rebuildRange function also has bugs on Handles array rebuild.

@eurekaka
Copy link
Contributor

@eurekaka After read your PR, it will fix not cache PointGetPlan, but if enable prepared plan cache and BatchPointGet plan got cached, I think rebuildRange function also has bugs on Handles array rebuild.

Could you please manufacture a test case that would fail after applying #23238 ?

@blacktear23
Copy link
Contributor Author

blacktear23 commented Mar 16, 2021

@eurekaka After read your PR, it will fix not cache PointGetPlan, but if enable prepared plan cache and BatchPointGet plan got cached, I think rebuildRange function also has bugs on Handles array rebuild.

Could you please manufacture a test case that would fail after applying #23238 ?

After I do the test on your feature branch, yes bugs cannot reproduce now. But your PR just disables PreparedPlanCache for statements with variables. Is that what we expected?

@eurekaka
Copy link
Contributor

just disables PreparedPlanCache for statements with variables

How does this come? #23238 prevents plans with aggressive optimizations from being cached, because those aggressive optimizations may depend on the user variables.

@blacktear23
Copy link
Contributor Author

blacktear23 commented Mar 17, 2021

just disables PreparedPlanCache for statements with variables

How does this come? #23238 prevents plans with aggressive optimizations from being cached, because those aggressive optimizations may depend on the user variables.

In my test I see OptimDependOnMutableConst is always true, so even BatchPointGet plan still cannot be cached. Or is there has any way to let BatchPointGet can be cached?

Anyway the rebuildRanges logic is not correct I think we should fix the logic even PR #23238 can fix those issues.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 4, 2021
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 7, 2021
@eurekaka eurekaka removed their request for review June 21, 2021 08:01
@qw4990 qw4990 requested review from eurekaka and removed request for qw4990 June 24, 2021 06:16
@zz-jason
Copy link
Member

zz-jason commented Apr 6, 2022

I'm going to close this PR since it hasn't been updated for a long time. Feel free to reopen it once you wish to advance this PR in the future.

@zz-jason zz-jason closed this Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The result of executing prepare is wrong the result of prepare execute is incorrect
7 participants