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/core: fix index resolution on PhysicalIndexReader (#8118) #8132

Merged
merged 2 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
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