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

Merged
merged 2 commits into from
Aug 17, 2021

Conversation

wshwsh12
Copy link
Contributor

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

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Aug 16, 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-chi-bot ti-chi-bot added 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. labels Aug 16, 2021
@wshwsh12
Copy link
Contributor Author

wshwsh12 commented Aug 16, 2021

In release 4.0, the distinct count missing both distinct flag and a column, and the result is correct by mistake..
(Missing distinct flag is fixed in #26959)

[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                     | 6400.00      | root      |                                     | test.pk_s_multi_31.col2                                                                                                                                                     |
| └─Selection_11                    | 6400.00      | root      |                                     | gt(Column#7, 2)                                                                                                                                                             |
|   └─HashAgg_12                    | 8000.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(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                                                                                                                                              |
+-----------------------------------+--------------+-----------+-------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
8 rows in set (0.001 sec)

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 Aug 17, 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 Aug 17, 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: 8cc6252

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

cherry pick to release-4.0 in PR #27282

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

cherry pick to release-5.0 in PR #27283

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

cherry pick to release-5.1 in PR #27284

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

cherry pick to release-5.2 in PR #27285

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

Successfully merging this pull request may close these issues.

wrong results in associated subquery statement
5 participants