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

support _tidb_rowid for table scan range #8047

Merged
merged 7 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
23 changes: 23 additions & 0 deletions cmd/explaintest/r/explain_easy.result
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,26 @@ Projection_3 10000.00 root plus(1, ifnull(test.t.a, 0))
└─TableScan_4 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo
drop table if exists t;
drop table if exists t;
create table t(a int);
explain select * from t where _tidb_rowid = 0;
id count task operator info
Projection_4 8000.00 root test.t.a
└─TableReader_6 10000.00 root data:TableScan_5
└─TableScan_5 10000.00 cop table:t, range:[0,0], keep order:false, stats:pseudo
explain select * from t where _tidb_rowid > 0;
id count task operator info
Projection_4 8000.00 root test.t.a
└─TableReader_6 10000.00 root data:TableScan_5
└─TableScan_5 10000.00 cop table:t, range:(0,+inf], keep order:false, stats:pseudo
explain select a, _tidb_rowid from t where a > 0;
id count task operator info
TableReader_7 3333.33 root data:Selection_6
└─Selection_6 3333.33 cop gt(test.t.a, 0)
└─TableScan_5 10000.00 cop table:t, range:[-inf,+inf], keep order:false, stats:pseudo
explain select * from t where _tidb_rowid > 0 and a > 0;
id count task operator info
Projection_4 2666.67 root test.t.a
└─TableReader_7 2666.67 root data:Selection_6
└─Selection_6 2666.67 cop gt(test.t.a, 0)
└─TableScan_5 3333.33 cop table:t, range:(0,+inf], keep order:false, stats:pseudo
drop table if exists t;
7 changes: 7 additions & 0 deletions cmd/explaintest/t/explain_easy.test
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,10 @@ explain select ifnull(nb, 0), ifnull(nb, 0) from t;
explain select 1+ifnull(nb, 0) from t;
explain select 1+ifnull(a, 0) from t;
drop table if exists t;
drop table if exists t;
create table t(a int);
explain select * from t where _tidb_rowid = 0;
explain select * from t where _tidb_rowid > 0;
explain select a, _tidb_rowid from t where a > 0;
eurekaka marked this conversation as resolved.
Show resolved Hide resolved
explain select * from t where _tidb_rowid > 0 and a > 0;
drop table if exists t;
11 changes: 10 additions & 1 deletion planner/core/logical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,16 @@ func (ds *DataSource) deriveTablePathStats(path *accessPath) (bool, error) {
}
if pkCol == nil {
path.ranges = ranger.FullIntRange(false)
return false, nil
if len(ds.Columns) > 0 {
yu34po marked this conversation as resolved.
Show resolved Hide resolved
extraHandleCol := ds.Columns[len(ds.Columns)-1]
if extraHandleCol.ID == model.ExtraHandleID {
pkCol = expression.ColInfo2Col(ds.schema.Columns, extraHandleCol)
yu34po marked this conversation as resolved.
Show resolved Hide resolved
} else {
return false, nil
}
} else {
return false, nil
}
}
path.ranges = ranger.FullIntRange(mysql.HasUnsignedFlag(pkCol.RetType.Flag))
if len(ds.pushedDownConds) == 0 {
Expand Down