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

Merged
merged 6 commits into from
Oct 31, 2018
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
13 changes: 13 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3266,3 +3266,16 @@ 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.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 @@ -14,7 +14,6 @@
package core

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

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