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) (#13095) #13291

Merged
merged 2 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cmd/explaintest/r/access_path_selection.result
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,15 @@ IndexLookUp_11 0.00 root
├─IndexScan_8 1.00 cop table:outdated_statistics, index:a, b, range:[1 1,1 1], keep order:false
└─Selection_10 0.00 cop eq(test.outdated_statistics.c, 1)
└─TableScan_9 1.00 cop table:outdated_statistics, keep order:false
explain select a, b from access_path_selection order by _tidb_rowid;
id count task operator info
Projection_5 10000.00 root test.access_path_selection.a, test.access_path_selection.b
└─TableReader_11 10000.00 root data:TableScan_10
└─TableScan_10 10000.00 cop table:access_path_selection, range:[-inf,+inf], keep order:true, stats:pseudo
explain select max(_tidb_rowid) from access_path_selection;
id count task operator info
StreamAgg_13 1.00 root funcs:max(test.access_path_selection._tidb_rowid)
└─Limit_17 1.00 root offset:0, count:1
└─TableReader_42 1.00 root data:Limit_41
└─Limit_41 1.00 cop offset:0, count:1
└─TableScan_40 1.25 cop table:access_path_selection, range:[-inf,+inf], keep order:true, desc, stats:pseudo
3 changes: 3 additions & 0 deletions cmd/explaintest/t/access_path_selection.test
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ insert into outdated_statistics values (1, 3, 3);
# result after Skyline Pruning is introduced.
analyze table outdated_statistics index idx_ab;
explain select * from outdated_statistics where a=1 and b=1 and c=1;
# _tidb_rowid should also be considered as PK.
explain select a, b from access_path_selection order by _tidb_rowid;
explain select max(_tidb_rowid) from access_path_selection;
6 changes: 6 additions & 0 deletions planner/core/logical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,12 @@ func isColEqCorColOrConstant(filter expression.Expression, col *expression.Colum

func (ds *DataSource) getPKIsHandleCol() *expression.Column {
if !ds.tableInfo.PKIsHandle {
// If the PKIsHandle is false, return the ExtraHandleColumn.
for i, col := range ds.Columns {
if col.ID == model.ExtraHandleID {
return ds.schema.Columns[i]
}
}
return nil
}
for i, col := range ds.Columns {
Expand Down