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: make queries with the extra column _tidb_rowid can use PointGet #31552

Merged
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
4 changes: 4 additions & 0 deletions planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,10 @@ func (ds *DataSource) getPruningInfo(candidates []*candidatePath, prop *property

func (ds *DataSource) isPointGetConvertableSchema() bool {
for _, col := range ds.Columns {
if col.Name.L == model.ExtraHandleName.L {
continue
}

// Only handle tables that all columns are public.
if col.State != model.StatePublic {
return false
Expand Down
5 changes: 5 additions & 0 deletions planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,11 @@ func buildPointDeletePlan(ctx sessionctx.Context, pointPlan PhysicalPlan, dbName

func findCol(tbl *model.TableInfo, colName *ast.ColumnName) *model.ColumnInfo {
for _, col := range tbl.Columns {
if colName.Name.L == model.ExtraHandleName.L && !tbl.PKIsHandle {
colInfo := model.NewExtraHandleColInfo()
colInfo.Offset = len(tbl.Columns) - 1
return colInfo
}
tiancaiamao marked this conversation as resolved.
Show resolved Hide resolved
if col.Name.L == colName.Name.L {
return col
}
Expand Down
28 changes: 28 additions & 0 deletions planner/core/point_get_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,34 @@ func (s *testPointGetSuite) TestPointGetForUpdate(c *C) {
tk.MustExec("rollback")
}

func (s *testPointGetSuite) TestGetExtraColumn(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec(`CREATE TABLE t (
a int(11) DEFAULT NULL,
b int(11) DEFAULT NULL,
UNIQUE KEY idx (a))`)
tk.MustQuery(`explain format='brief' select t.*, _tidb_rowid from t where a = 1`).Check(testkit.Rows("Point_Get 1.00 root table:t, index:idx(a) "))
tk.MustQuery(`explain format='brief' select t.*, _tidb_rowid, date_format(a, "") from t where a = 1`).Check(testkit.Rows(
`Projection 1.00 root test.t.a, test.t.b, test.t._tidb_rowid, date_format(cast(test.t.a, datetime BINARY), )->Column#4`,
`└─Point_Get 1.00 root table:t, index:idx(a) `))
tk.MustExec(`begin`) // in transaction
tk.MustExec(`insert into t values (1, 1)`)
tk.MustQuery(`explain format='brief' select t.*, _tidb_rowid from t where a = 1`).Check(testkit.Rows(`Point_Get 1.00 root table:t, index:idx(a) `))
tk.MustExec(`commit`)
tk.MustQuery(`explain format='brief' select count(_tidb_rowid) from t where a=1`).Check(testkit.Rows(
`StreamAgg 1.00 root funcs:count(test.t._tidb_rowid)->Column#4`,
`└─Point_Get 1.00 root table:t, index:idx(a) `))
tk.MustQuery(`explain format='brief' select *, date_format(b, "") from t where a =1 for update`).Check(testkit.Rows(
`Projection 1.00 root test.t.a, test.t.b, date_format(cast(test.t.b, datetime BINARY), )->Column#4`,
`└─SelectLock 1.00 root for update 0`,
` └─Point_Get 1.00 root table:t, index:idx(a) `))

// if the PK is handled
tk.MustExec(`create table t1 (pk int, a int, b int, primary key(pk), unique key(a))`)
c.Check(tk.ExecToErr(`explain format='brief' select t1.*, _tidb_rowid from t1 where a = 1`), ErrorMatches, ".*Unknown column \\'_tidb_rowid\\'.*")
}

func (s *testPointGetSuite) TestPointGetForUpdateWithSubquery(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down