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: add missing column for Apply convert to Join (#27246) #27283

Merged
merged 7 commits into from
Sep 3, 2021

Conversation

ti-srebot
Copy link
Contributor

@ti-srebot ti-srebot commented Aug 17, 2021

cherry-pick #27246 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/27283

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

git push git@github.com:ti-srebot/tidb.git pr/27283:release-5.0-1c6c5483341c

What problem does this PR solve?

Issue Number: close #27233

Problem Summary:
In master 5ae87ca, the aggregate function missing a column.
In this case, count distinct function should have 2 args col1 and col2.

[tidb]> desc SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 ;
+-----------------------------------+--------------+-----------+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id                                | estRows      | task      | access object                       | operator info                                                                                                                                                                        |
+-----------------------------------+--------------+-----------+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Projection_10                     | 0.80         | root      |                                     | test.pk_s_multi_31.col2                                                                                                                                                              |
| └─Selection_11                    | 0.80         | root      |                                     | gt(Column#7, 2)                                                                                                                                                                      |
|   └─HashAgg_12                    | 1.00         | root      |                                     | group by:test.pk_s_multi_31.col1, test.pk_s_multi_31.col2, funcs:firstrow(test.pk_s_multi_31.col2)->test.pk_s_multi_31.col2, funcs:count(distinct test.pk_s_multi_31.col1)->Column#7 |
|     └─HashJoin_14                 | 100000000.00 | root      |                                     | CARTESIAN left outer join, other cond:gt(test.pk_s_multi_31.col1, test.pk_s_multi_31.col1)                                                                                           |
|       ├─TableReader_21(Build)     | 10000.00     | root      |                                     | data:TableFullScan_20                                                                                                                                                                |
|       │ └─TableFullScan_20        | 10000.00     | cop[tikv] | table:T2                            | keep order:false, stats:pseudo                                                                                                                                                       |
|       └─IndexReader_19(Probe)     | 10000.00     | root      |                                     | index:IndexFullScan_18                                                                                                                                                               |
|         └─IndexFullScan_18        | 10000.00     | cop[tikv] | table:T1, index:PRIMARY(COL1, COL2) | keep order:false, stats:pseudo                                                                                                                                                       |
+-----------------------------------+--------------+-----------+-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

What is changed and how it works?

Proposal: xxx

What's Changed:
Aggregate maybe have many args, so we should also consider when converting Apply to Join.

In this pr, the distinct count will have two args.

[tidb]> desc SELECT col2 FROM PK_S_MULTI_31 AS T1 WHERE (SELECT count(DISTINCT COL1, COL2) FROM PK_S_MULTI_31 AS T2 WHERE T2.COL1>T1.COL1)>2 ;
+-----------------------------------+----------+-----------+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id                                | estRows  | task      | access object                       | operator info                                                                                                                                                                                                 |
+-----------------------------------+----------+-----------+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Projection_10                     | 0.80     | root      |                                     | test.pk_s_multi_31.col2                                                                                                                                                                                       |
| └─Selection_11                    | 0.80     | root      |                                     | gt(Column#7, 2)                                                                                                                                                                                               |
|   └─HashAgg_12                    | 1.00     | root      |                                     | group by:test.pk_s_multi_31.col1, test.pk_s_multi_31.col2, funcs:firstrow(test.pk_s_multi_31.col2)->test.pk_s_multi_31.col2, funcs:count(distinct test.pk_s_multi_31.col1, test.pk_s_multi_31.col2)->Column#7 |
|     └─HashJoin_14                 | 10404.00 | root      |                                     | CARTESIAN left outer join, other cond:gt(test.pk_s_multi_31.col1, test.pk_s_multi_31.col1)                                                                                                                    |
|       ├─IndexReader_23(Build)     | 102.00   | root      |                                     | index:IndexFullScan_22                                                                                                                                                                                        |
|       │ └─IndexFullScan_22        | 102.00   | cop[tikv] | table:T2, index:PRIMARY(COL1, COL2) | keep order:false, stats:pseudo                                                                                                                                                                                |
|       └─IndexReader_19(Probe)     | 102.00   | root      |                                     | index:IndexFullScan_18                                                                                                                                                                                        |
|         └─IndexFullScan_18        | 102.00   | cop[tikv] | table:T1, index:PRIMARY(COL1, COL2) | keep order:false, stats:pseudo                                                                                                                                                                                |
+-----------------------------------+----------+-----------+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
8 rows in set, 1 warning (0.001 sec)

How it Works:

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

planner: add missing column for Apply convert to Join

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Aug 17, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • XuHuaiyu
  • lzmhhh123

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 submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-srebot ti-srebot requested review from a team as code owners August 17, 2021 03:51
@ti-srebot ti-srebot requested review from XuHuaiyu and removed request for a team August 17, 2021 03:51
@ti-chi-bot ti-chi-bot added do-not-merge/cherry-pick-not-approved do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Aug 17, 2021
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-chi-bot ti-chi-bot removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Aug 17, 2021
@ti-srebot ti-srebot added component/expression size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/5.0-cherry-pick labels Aug 17, 2021
@ti-srebot ti-srebot added this to the v5.0.3 milestone Aug 17, 2021
@ti-srebot
Copy link
Contributor Author

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

@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 Aug 17, 2021
@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 30, 2021
@zhouqiang-cl zhouqiang-cl added the cherry-pick-approved Cherry pick PR approved by release team. label Sep 3, 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 Sep 3, 2021
@wshwsh12
Copy link
Contributor

wshwsh12 commented Sep 3, 2021

Also included #26968

Copy link
Contributor

@XuHuaiyu XuHuaiyu 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 ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 3, 2021
@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 Sep 3, 2021
@wshwsh12
Copy link
Contributor

wshwsh12 commented Sep 3, 2021

/merge

@ti-chi-bot
Copy link
Member

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

Commit hash: 10a2bdf

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Sep 3, 2021
@zhouqiang-cl
Copy link
Contributor

/merge

@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 7c5988c into pingcap:release-5.0 Sep 3, 2021
@zhouqiang-cl zhouqiang-cl modified the milestones: v5.0.3, v5.0.4 Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Cherry pick PR approved by release team. component/expression release-note Denotes a PR that will be considered when it comes time to generate release notes. 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/5.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants