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: donot prune all columns for Projection #24024

Merged
merged 8 commits into from
Apr 16, 2021

Conversation

guo-shaoge
Copy link
Collaborator

@guo-shaoge guo-shaoge commented Apr 14, 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

What is changed and how it works?

What's Changed:

  1. We donot prune all columns in Projection. If Projection is pruned to empty, we make it a Projection 1 (just like count(1))
  2. Delete some code in rule_eliminate_projection.go, because Projection cannot be empty. Check here

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Integration test

Side effects: no

Release note

  • donot prune all columns for Projection

@guo-shaoge guo-shaoge requested a review from a team as a code owner April 14, 2021 10:04
@guo-shaoge guo-shaoge requested review from lzmhhh123 and removed request for a team April 14, 2021 10:04
@ti-chi-bot ti-chi-bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 14, 2021
@ichn-hu ichn-hu mentioned this pull request Apr 14, 2021
@ti-chi-bot ti-chi-bot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 14, 2021
@guo-shaoge
Copy link
Collaborator Author

/run-all-tests

@ti-chi-bot ti-chi-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 15, 2021
@guo-shaoge guo-shaoge changed the title planner: do physical projection eliminatoin before resolve column indices planner: donot prune all columns for Projection Apr 15, 2021
@guo-shaoge
Copy link
Collaborator Author

@winoros @lzmhhh123 PTAL

@guo-shaoge
Copy link
Collaborator Author

guo-shaoge commented Apr 15, 2021

As @lzmhhh123 suggested, I'm trying to make it Projection(1), just like Count(1) does. Good for performance.

@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 15, 2021
@guo-shaoge
Copy link
Collaborator Author

/run-all-tests

Copy link
Contributor

@lzmhhh123 lzmhhh123 left a comment

Choose a reason for hiding this comment

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

How about adding some tests? BTW, can we avoid pruning projection in tryEliminateProjection?

@lzmhhh123
Copy link
Contributor

@winoros PTAL the PR. Do you have any better way to solve the issue?

@guo-shaoge
Copy link
Collaborator Author

tryEliminateProjection

You mean we do not eliminate Projection whose output column is empty?

Maybe we can not do that because this PR

Copy link
Contributor

@lzmhhh123 lzmhhh123 left a comment

Choose a reason for hiding this comment

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

tryEliminateProjection

You mean we do not eliminate Projection whose output column is empty?

Maybe we can not do that because this PR

No, we can check whether a join above it.

@guo-shaoge
Copy link
Collaborator Author

guo-shaoge commented Apr 16, 2021

tryEliminateProjection

You mean we do not eliminate Projection whose output column is empty?
Maybe we can not do that because this PR

No, we can check whether a join above it.

I think this bug is not only for Join, for example, Apply may also got same error.

Apply
 |       |
DS   Projection
         |
        xxx

You can repeat this bug use following SQL(I will add it to testcase):

drop table if exists t, s;
create table t(a int, b int);
insert into t values(1, 2), (3, 4);
select (2) in (select b from t) from (select t.a < (select t.a from t t1 limit 1) from t) t;

planner/core/rule_column_pruning.go Outdated Show resolved Hide resolved
planner/core/rule_column_pruning.go Show resolved Hide resolved
@ti-chi-bot ti-chi-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Apr 16, 2021
@guo-shaoge
Copy link
Collaborator Author

/run-cla

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

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 037b140

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

/run-unit-test

@guo-shaoge
Copy link
Collaborator Author

/run-all-tests

@guo-shaoge
Copy link
Collaborator Author

/run-mybatis-test

@ti-chi-bot ti-chi-bot merged commit 4cd7fb0 into pingcap:master Apr 16, 2021
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Apr 16, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #24092

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

cherry pick to release-5.0 in PR #24093

@XuHuaiyu XuHuaiyu added the sig/planner SIG: Planner label Apr 22, 2021
guo-shaoge added a commit to guo-shaoge/tidb that referenced this pull request Apr 22, 2021
… (pingcap#24093)"

This reverts commit f5cac30.

Signed-off-by: guo-shaoge <shaoge1994@163.com>
guo-shaoge added a commit to guo-shaoge/tidb that referenced this pull request Apr 23, 2021
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/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.

executor: (*Column).GetString panic
6 participants