Skip to content

Commit

Permalink
planner/core: fix index resolution on PhysicalIndexReader (pingcap#8118)
Browse files Browse the repository at this point in the history
  • Loading branch information
zz-jason committed Nov 1, 2018
1 parent dcc5fc7 commit c6b076a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
17 changes: 17 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3229,3 +3229,20 @@ func (s *testSuite) TestCurrentTimestampValueSelection(c *C) {
c.Assert(strings.Split(b, ".")[1], Equals, "00")
c.Assert(len(strings.Split(d, ".")[1]), Equals, 3)
}

func (s *testSuite) TestRowID(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec(`use test`)
tk.MustExec(`drop table if exists t`)
tk.MustExec(`create table t(a varchar(10), b varchar(10), c varchar(1), index idx(a, b, c));`)
tk.MustExec(`insert into t values('a', 'b', 'c');`)
tk.MustExec(`insert into t values('a', 'b', 'c');`)
tk.MustQuery(`select b, _tidb_rowid from t use index(idx) where a = 'a';`).Check(testkit.Rows(
`b 1`,
`b 2`,
))
tk.MustExec(`begin;`)
tk.MustExec(`select * from t for update`)
tk.MustQuery(`select distinct b from t use index(idx) where a = 'a';`).Check(testkit.Rows(`b`))
tk.MustExec(`commit;`)
}
8 changes: 1 addition & 7 deletions planner/core/resolve_indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,7 @@ func (p *PhysicalIndexReader) ResolveIndices() {
p.physicalSchemaProducer.ResolveIndices()
p.indexPlan.ResolveIndices()
for i, col := range p.OutputColumns {
if col.ID != model.ExtraHandleID {
p.OutputColumns[i] = col.ResolveIndices(p.indexPlan.Schema()).(*expression.Column)
} else {
p.OutputColumns[i] = col.Clone().(*expression.Column)
// If this is extra handle, then it must be the tail.
p.OutputColumns[i].Index = len(p.OutputColumns) - 1
}
p.OutputColumns[i] = col.ResolveIndices(p.indexPlan.Schema()).(*expression.Column)
}
}

Expand Down

0 comments on commit c6b076a

Please sign in to comment.