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

Merged
merged 10 commits into from
Mar 18, 2021

Conversation

qw4990
Copy link
Contributor

@qw4990 qw4990 commented Mar 16, 2021

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

@qw4990 qw4990 added type/bugfix This PR fixes a bug. sig/planner SIG: Planner labels Mar 16, 2021
@qw4990 qw4990 requested review from winoros and rebelice March 16, 2021 09:15
@qw4990 qw4990 requested a review from a team as a code owner March 16, 2021 09:15
@ti-chi-bot ti-chi-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 16, 2021
@qw4990 qw4990 requested a review from a team as a code owner March 16, 2021 10:07
@qw4990 qw4990 requested review from lzmhhh123 and removed request for a team and lzmhhh123 March 16, 2021 10:07
@ichn-hu ichn-hu mentioned this pull request Mar 16, 2021
@github-actions github-actions bot added the sig/execution SIG execution label Mar 16, 2021
@ti-chi-bot ti-chi-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 17, 2021
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 17, 2021
Copy link
Member

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

@winoros: 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:

  • rebelice
  • 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 status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 17, 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 Mar 18, 2021
@qw4990
Copy link
Contributor Author

qw4990 commented Mar 18, 2021

/run-all-tests

@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 18, 2021
@qw4990
Copy link
Contributor Author

qw4990 commented Mar 18, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: af066a5

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 18, 2021
@qw4990 qw4990 merged commit 28c3748 into pingcap:master Mar 18, 2021
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 25, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.0 in PR #23536

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 25, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #23537

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.0 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

runtime error: index out of range [2] with length 1
6 participants