diff --git a/executor/executor_test.go b/executor/executor_test.go index a0f1375277584..c6f5f9b688e32 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -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;`) +} diff --git a/planner/core/resolve_indices.go b/planner/core/resolve_indices.go index d11f3c49d453e..97ca5c1619500 100644 --- a/planner/core/resolve_indices.go +++ b/planner/core/resolve_indices.go @@ -15,7 +15,6 @@ package core import ( "github.com/pingcap/tidb/expression" - "github.com/pingcap/tidb/model" ) // ResolveIndices implements Plan interface. @@ -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) } }