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 column pruning bug for Apply and Join #24369

Merged
merged 10 commits into from
May 6, 2021

Conversation

guo-shaoge
Copy link
Collaborator

@guo-shaoge guo-shaoge commented Apr 29, 2021

Signed-off-by: guo-shaoge shaoge1994@163.com

What problem does this PR solve?

Issue Number: close #23887

Problem Summary:

Hash Join (eq("abc", tbl1.col1))
  |                     |
Projection     DataSource(tbl1)
  |
Index Join
  1. We prune all columns in Projection
  2. Resolve indices for col1, Its index is 0(because Projection's output columns are all pruned)
  3. Projection is eliminated, because its output columns are all pruned. But Index Join still has output columns
  4. Got panic when calc eq("abc", tbl1.col1). Because use index 0 to eval tbl1.col1

Apply also has this problem. So here I also fix this for Apply.

    Apply
     |       |
    DS   Projection
             |
            xxx

What is changed and how it works?

What's Changed: For LogicalJoin and LogicalApply, if they have Projection child, we donot prune all columns in Projection. If Projection is pruned to empty, we make it a Projection 1 (just like count(1))

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Integration test: TestIssue23887

Side effects:

  1. Some plan may changes(For situations that Apply/Join's children Projection is empty)
  2. For above situations, the performance may change, because we project 1 in runtime.

Release note

  • planner: fix column pruning bug for Apply and Join

Signed-off-by: guo-shaoge <shaoge1994@163.com>
@guo-shaoge guo-shaoge requested a review from a team as a code owner April 29, 2021 04:21
@guo-shaoge guo-shaoge requested review from winoros and removed request for a team April 29, 2021 04:21
@ti-chi-bot ti-chi-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 29, 2021
Signed-off-by: guo-shaoge <shaoge1994@163.com>
@guo-shaoge
Copy link
Collaborator Author

/run-all-tests

@ichn-hu ichn-hu mentioned this pull request Apr 29, 2021
@guo-shaoge
Copy link
Collaborator Author

This is the second try to fix #23887. Compared with last fix, the scope of influence of this fix is smaller. Only Apply and Join's behaviors are changed.

So other operators like Agg will not be affected (still can push down to TiKV, see here.

@@ -431,3 +443,24 @@ func (p *LogicalLimit) PruneColumns(parentUsedCols []*expression.Column) error {
func (*columnPruner) name() string {
return "column_prune"
}

func addConstOneForEmptyProjection(p LogicalPlan) (err error) {
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
func addConstOneForEmptyProjection(p LogicalPlan) (err error) {
func addConstOneForEmptyProjection(p LogicalPlan) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Signed-off-by: guo-shaoge <shaoge1994@163.com>
Signed-off-by: guo-shaoge <shaoge1994@163.com>
@guo-shaoge
Copy link
Collaborator Author

@eurekaka @winoros PTAL

@guo-shaoge
Copy link
Collaborator Author

/run-all-tests

@guo-shaoge guo-shaoge requested a review from lzmhhh123 May 6, 2021 09:46
@guo-shaoge
Copy link
Collaborator Author

/run-mybatis-test
/run-tics-test

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label May 6, 2021
@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • lzmhhh123
  • 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 May 6, 2021
@lzmhhh123
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: eac8a25

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label May 6, 2021
@guo-shaoge
Copy link
Collaborator Author

/run-unit-test

@sonarcloud
Copy link

sonarcloud bot commented May 6, 2021

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
12.3% 12.3% Duplication

@ti-chi-bot ti-chi-bot merged commit a6ec081 into pingcap:master May 6, 2021
@guo-shaoge
Copy link
Collaborator Author

/run-cherry-picker

@ti-srebot
Copy link
Contributor

cherry pick to release-5.0 in PR #24437

guo-shaoge added a commit to ti-srebot/tidb that referenced this pull request May 26, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
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 size/L Denotes a PR that changes 100-499 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.

executor: (*Column).GetString panic
5 participants