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 choosing the partition wrongly when the where stmt is only one eq condition. (#16975) #17054

Merged
merged 5 commits into from
May 11, 2020

Conversation

sre-bot
Copy link
Contributor

@sre-bot sre-bot commented May 9, 2020

cherry-pick #16975 to release-4.0


What problem does this PR solve?

Issue Number: close #16842

Problem Summary: Got wrong result because of choosing wrong partition

select /*+ HASH_JOIN(t1, t2) */ * from t1 partition (p0) left join t2 partition (p1) on t1.a = t2.a where t1.a = 6 order by t1.a, t1.b, t2.a, t2.b;
+--------------------------------+---------+---------+-----------+------------------------+----------------------------------------------------------------------------+------------------------------------------------------------+--------------+---------+
| id                             | estRows | actRows | task      | access object          | execution info                                                             | operator info                                              | memory       | disk    |
+--------------------------------+---------+---------+-----------+------------------------+----------------------------------------------------------------------------+------------------------------------------------------------+--------------+---------+
| Sort_9                         | 0.01    | 1       | root      |                        | time:417.345µs, loops:2                                                    | test.t1.a:asc, test.t1.b:asc, test.t2.a:asc, test.t2.b:asc | 1.4609375 KB | 0 Bytes |
| └─HashJoin_12                  | 0.01    | 1       | root      |                        | time:403.351µs, loops:2, Concurrency:5, probe collision:0, build:3.341µs   | CARTESIAN left outer join                                  | 16.46875 KB  | 0 Bytes |
|   ├─TableReader_19(Build)      | 0.00    | 1       | root      |                        | time:246.412µs, loops:2, rpc num: 1, rpc time:263.064µs, proc keys:0       | data:Selection_18                                          | 185 Bytes    | N/A     |
|   │ └─Selection_18             | 0.00    | 1       | cop[tikv] |                        | time:68.752µs, loops:2                                                     | eq(6, test.t2.a)                                           | N/A          | N/A     |
|   │   └─TableFullScan_17       | 2.00    | 2       | cop[tikv] | table:t2, partition:p6 | time:62.883µs, loops:3                                                     | keep order:false, stats:pseudo                             | N/A          | N/A     |
|   └─TableReader_16(Probe)      | 0.01    | 1       | root      |                        | time:337.02µs, loops:2, rpc num: 1, rpc time:360.723µs, proc keys:0        | data:Selection_15                                          | 185 Bytes    | N/A     |
|     └─Selection_15             | 0.01    | 1       | cop[tikv] |                        | time:177.32µs, loops:2                                                     | eq(test.t1.a, 6)                                           | N/A          | N/A     |
|       └─TableFullScan_14       | 9.00    | 9       | cop[tikv] | table:t1, partition:p0 | time:161.26µs, loops:10                                                    | keep order:false, stats:pseudo                             | N/A          | N/A     |
+--------------------------------+---------+---------+-----------+------------------------+----------------------------------------------------------------------------+------------------------------------------------------------+--------------+---------+
8 rows in set (0.00 sec)

The partition should be p1 instead of p6 for t2. (Of course, table dual is also ok.)

What is changed and how it works?

What's Changed: Check the datasource's partitions includes the partition build from condition.

How it Works:

+-------------------------------+---------+---------+-----------+------------------------+------------------------------------------------------------------------+------------------------------------------------------------+--------------+---------+
| id                            | estRows | actRows | task      | access object          | execution info                                                         | operator info                                              | memory       | disk    |
+-------------------------------+---------+---------+-----------+------------------------+------------------------------------------------------------------------+------------------------------------------------------------+--------------+---------+
| Sort_9                        | 0.01    | 1       | root      |                        | time:1.717822ms, loops:2                                               | test.t1.a:asc, test.t1.b:asc, test.t2.a:asc, test.t2.b:asc | 1.4609375 KB | 0 Bytes |
| └─HashJoin_12                 | 0.01    | 1       | root      |                        | time:1.686675ms, loops:2, Concurrency:5, probe collision:0, build:0s   | CARTESIAN left outer join                                  | 0 Bytes      | 0 Bytes |
|   ├─TableDual_17(Build)       | 0.00    | 0       | root      |                        | time:335.178µs, loops:1                                                | rows:0                                                     | N/A          | N/A     |
|   └─TableReader_16(Probe)     | 0.01    | 1       | root      |                        | time:1.574268ms, loops:2, rpc num: 1, rpc time:1.160928ms, proc keys:0 | data:Selection_15                                          | 185 Bytes    | N/A     |
|     └─Selection_15            | 0.01    | 1       | cop[tikv] |                        | time:316.313µs, loops:2                                                | eq(test.t1.a, 6)                                           | N/A          | N/A     |
|       └─TableFullScan_14      | 9.00    | 9       | cop[tikv] | table:t1, partition:p0 | time:286.938µs, loops:10                                               | keep order:false, stats:pseudo                             | N/A          | N/A     |
+-------------------------------+---------+---------+-----------+------------------------+------------------------------------------------------------------------+------------------------------------------------------------+--------------+---------+
6 rows in set (0.01 sec)

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test

Side effects

Release note

  • Bug-fix: Fix choosing the partition wrongly when there is only one eq condition.

Signed-off-by: sre-bot <sre-bot@pingcap.com>
@sre-bot sre-bot requested a review from a team as a code owner May 9, 2020 06:16
@sre-bot
Copy link
Contributor Author

sre-bot commented May 9, 2020

/run-all-tests

Copy link

@imtbkcat imtbkcat left a comment

Choose a reason for hiding this comment

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

LGTM

@imtbkcat imtbkcat added the status/LGT1 Indicates that a PR has LGTM 1. label May 11, 2020
@wshwsh12
Copy link
Contributor

/run-all-tests

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels May 11, 2020
@sre-bot
Copy link
Contributor Author

sre-bot commented May 11, 2020

/run-all-tests

@sre-bot sre-bot merged commit 5cc5d0e into pingcap:release-4.0 May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner 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. type/4.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants