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
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 19 additions & 0 deletions executor/rowid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,22 @@ func (s *testSuite1) TestNotAllowWriteRowID(c *C) {
// tk.MustExec("insert into tt (id, c, _tidb_rowid) values(30000,10,1);")
// tk.MustExec("admin check table tt;")
}

func (s *testSuite1) TestRowIDOrder(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("create table t(a int, b int);")
tk.MustQuery("explain select * from t where a > 10 order by _tidb_rowid").Check(testkit.Rows(
"Projection_6 3333.33 root test.t.a, test.t.b",
"└─TableReader_14 3333.33 root data:Selection_13",
" └─Selection_13 3333.33 cop gt(test.t.a, 10)",
" └─TableScan_12 10000.00 cop table:t, range:[-inf,+inf], keep order:true, stats:pseudo",
))
tk.MustQuery("explain select max(_tidb_rowid) from t").Check(testkit.Rows(
"StreamAgg_13 1.00 root funcs:max(test.t._tidb_rowid)",
"└─Limit_17 1.00 root offset:0, count:1",
" └─TableReader_27 1.00 root data:Limit_26",
" └─Limit_26 1.00 cop offset:0, count:1",
" └─TableScan_25 1.25 cop table:t, range:[-inf,+inf], keep order:true, desc, stats:pseudo",
))
}
6 changes: 6 additions & 0 deletions planner/core/logical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,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