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: remove some risky cache operations in the plan builder (#23354) #23536

Merged
merged 8 commits into from
Mar 26, 2021

Conversation

ti-srebot
Copy link
Contributor

@ti-srebot ti-srebot commented Mar 25, 2021

cherry-pick #23354 to release-5.0
You can switch your code base to this Pull Request by using git-extras:

# In tidb repo:
git pr https://github.com/pingcap/tidb/pull/23536

After apply modifications, you can push your change to this PR via:

git push [email protected]:ti-srebot/tidb.git pr/23536:release-5.0-28c3748496b6

What problem does this PR solve?

Issue Number: close #22850

Problem Summary: planner: remove some risky cache operations in the plan builder

What is changed and how it works?

#21431 allows the plan builder to cache some logical plans to avoid unnecessary evaluation(in PlanBuilder.buildTableRefs), but this operation brings some risks.
Because the cached logical plans may be modified in some other places, and once they are modified, some implicit assumptions may be broken.
image

In this case(#22850):

  1. the expression rewriter has an implicit assumption that len(p.Schema().Cols) == len(p.OutputNames()) (in getExpressionRewriter).
  2. the subquery in the SQL is handled twice during processing(in buildProjection): the first happens when pre-processing user variables(preprocessUserVarTypes) and the second happens when rewriting selection fields(rewriteWithPreprocess);
  3. during the second processing, the result cached in first is returned, but the cached logical plan has been modified since its output names have been pruned, so the implicit assumption required by the rewriter is broken.

Check List

Tests

  • Unit test

Release note

  • planner: remove some risky cache operations in the plan builder

@ti-srebot ti-srebot requested review from a team as code owners March 25, 2021 07:07
@ti-srebot ti-srebot requested review from lzmhhh123 and removed request for a team March 25, 2021 07:07
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot ti-srebot added sig/execution SIG execution sig/planner SIG: Planner size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. type/5.0-cherry-pick type/bugfix This PR fixes a bug. labels Mar 25, 2021
@ti-srebot ti-srebot requested review from rebelice and winoros March 25, 2021 07:07
@ti-srebot ti-srebot added this to the v5.0.0 ga milestone Mar 25, 2021
@ti-srebot
Copy link
Contributor Author

@qw4990 you're already a collaborator in bot's repo.

@zimulala
Copy link
Contributor

/cc @winoros

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

/cc @Reminiscent @eurekaka

@zimulala
Copy link
Contributor

/cc @rebelice

Copy link
Contributor

@Reminiscent Reminiscent left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot
Copy link
Member

@Reminiscent: Please use /LGTM instead of LGTM when you want to approve the pull request by comment.
If you use the GitHub review feature, please approve the PR directly, the comment will not take effect in the GitHub review feature.
If you have any qustions please refer to lgtm command help or lgtm plugin design.

If you have approved this PR, please ignore this reply. This reply is being used as a temporary reply during the migration of the new bot and will be removed on April 1.

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
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • Reminiscent
  • 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 removed the status/LGT1 Indicates that a PR has LGTM 1. label Mar 25, 2021
@ti-chi-bot
Copy link
Member

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

Commit hash: 8c0ab9c

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 25, 2021
@qw4990
Copy link
Contributor

qw4990 commented Mar 25, 2021

/run-all-tests

@zimulala zimulala added the priority/release-blocker This issue blocks a release. Please solve it ASAP. label Mar 25, 2021
@qw4990 qw4990 force-pushed the release-5.0-28c3748496b6 branch from c0157ef to 82dd0c4 Compare March 25, 2021 13:31
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Mar 25, 2021
@qw4990
Copy link
Contributor

qw4990 commented Mar 25, 2021

/run-all-tests

@qw4990
Copy link
Contributor

qw4990 commented Mar 25, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 5c421482c417b23a009d8c9aa21c8e3e706a976c

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 25, 2021
@qw4990
Copy link
Contributor

qw4990 commented Mar 25, 2021

/merge

2 similar comments
@qw4990
Copy link
Contributor

qw4990 commented Mar 25, 2021

/merge

@zimulala
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

@zimulala: /merge is only allowed for the committers in list.

In response to this:

/merge

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.

@zimulala
Copy link
Contributor

/cc @qw4990

@ti-chi-bot ti-chi-bot requested a review from qw4990 March 26, 2021 02:45
@zimulala
Copy link
Contributor

/run-all-tests

@XuHuaiyu
Copy link
Contributor

/merge

@qw4990 qw4990 force-pushed the release-5.0-28c3748496b6 branch from a862daa to 2329c9a Compare March 26, 2021 03:40
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Mar 26, 2021
@qw4990
Copy link
Contributor

qw4990 commented Mar 26, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 64bcaeb

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 26, 2021
@ti-chi-bot
Copy link
Member

@ti-srebot: 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 7b0a996 into pingcap:release-5.0 Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/release-blocker This issue blocks a release. Please solve it ASAP. sig/execution SIG execution sig/planner SIG: Planner size/XL Denotes a PR that changes 500-999 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. type/bugfix This PR fixes a bug. type/5.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants