Skip to content

Commit

Permalink
planner/core: fix index resolution on PhysicalIndexReader (#8118) (#8132
Browse files Browse the repository at this point in the history
)
  • Loading branch information
zz-jason authored Nov 1, 2018
1 parent dcc5fc7 commit adb5733
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 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;`)
}
9 changes: 1 addition & 8 deletions planner/core/resolve_indices.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package core

import (
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/model"
)

// ResolveIndices implements Plan interface.
Expand Down Expand Up @@ -107,13 +106,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 adb5733

Please sign in to comment.