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: use ExtraHandleColumn as PK when generating TablePath #11959

Merged
merged 7 commits into from
Sep 2, 2019

Conversation

francis0407
Copy link
Member

@francis0407 francis0407 commented Aug 31, 2019

What problem does this PR solve?

Before this PR:

mysql> create table t(a int, b int);
Query OK, 0 rows affected (0.01 sec)

mysql> explain select * from t where a > 10 order by _tidb_rowid;
+-------------------------+----------+------+------------------------------------------------------------+
| id                      | count    | task | operator info                                              |
+-------------------------+----------+------+------------------------------------------------------------+
| Projection_6            | 3333.33  | root | test.t.a, test.t.b                                         |
| └─Sort_7                | 3333.33  | root | test.t._tidb_rowid:asc                                     |
|   └─TableReader_11      | 3333.33  | root | data:Selection_10                                          |
|     └─Selection_10      | 3333.33  | cop  | gt(test.t.a, 10)                                           |
|       └─TableScan_9     | 10000.00 | cop  | table:t, range:[-inf,+inf], keep order:false, stats:pseudo |
+-------------------------+----------+------+------------------------------------------------------------+
5 rows in set (0.00 sec)

After this PR:

mysql> explain select * from t where a > 10 order by _tidb_rowid;
+------------------------+-------+------+-----------------------------------------------------------+
| id                     | count | task | operator info                                             |
+------------------------+-------+------+-----------------------------------------------------------+
| Projection_6           | 1.33  | root | test.t.a, test.t.b                                        |
| └─TableReader_14       | 1.33  | root | data:Selection_13                                         |
|   └─Selection_13       | 1.33  | cop  | gt(test.t.a, 10)                                          |
|     └─TableScan_12     | 4.00  | cop  | table:t, range:[-inf,+inf], keep order:true, stats:pseudo |
+------------------------+-------+------+-----------------------------------------------------------+
4 rows in set (0.00 sec)

What is changed and how it works?

This PR makes getPKIsHandleCol() return ExtraHandleColumn instead of nil when the table has no PK.

Check List

Tests

  • Unit test

Release note

When the table uses _tidb_rowid as Handle, we can correctly generate a TableScan that can keep the order of _tidb_rowid. For example, select max(_tidb_rowid) from t won't require a Sort anymore.

@codecov
Copy link

codecov bot commented Aug 31, 2019

Codecov Report

Merging #11959 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #11959   +/-   ##
===========================================
  Coverage   81.2949%   81.2949%           
===========================================
  Files           444        444           
  Lines         95092      95092           
===========================================
  Hits          77305      77305           
  Misses        12305      12305           
  Partials       5482       5482

@zz-jason
Copy link
Member

zz-jason commented Sep 2, 2019

@francis0407 Please add proper labels.

Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

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

LGTM

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. labels Sep 2, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Sep 2, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Sep 2, 2019

@francis0407 merge failed.

@winoros
Copy link
Member

winoros commented Sep 2, 2019

/build

@francis0407 francis0407 merged commit 2a155f4 into pingcap:master Sep 2, 2019
@francis0407
Copy link
Member Author

/run-cherry-picker

@sre-bot
Copy link
Contributor

sre-bot commented Nov 1, 2019

cherry pick to release-2.1 failed

@sre-bot
Copy link
Contributor

sre-bot commented Nov 1, 2019

cherry pick to release-3.0 failed

@sre-bot
Copy link
Contributor

sre-bot commented Nov 1, 2019

cherry pick to release-3.1 failed

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants