Skip to content

Commit

Permalink
fix primary key's type (pingcap#2222)
Browse files Browse the repository at this point in the history
* executor: fix primay key type error

When we do single read index scan, primay key's type should be determined
by it's flag.

* executor: add test

* executor: format code:

* executor: address comment
  • Loading branch information
alivxxx authored Dec 12, 2016
1 parent 654f4f4 commit dd4dcfe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions executor/executor_distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,12 @@ func (e *XSelectIndexExec) nextForSingleRead() (*Row, error) {
func (e *XSelectIndexExec) indexRowToTableRow(handle int64, indexRow []types.Datum) []types.Datum {
tableRow := make([]types.Datum, len(e.indexPlan.Columns))
for i, tblCol := range e.indexPlan.Columns {
if mysql.HasPriKeyFlag(tblCol.Flag) && e.indexPlan.Table.PKIsHandle {
tableRow[i] = types.NewIntDatum(handle)
if table.ToColumn(tblCol).IsPKHandleColumn(e.indexPlan.Table) {
if mysql.HasUnsignedFlag(tblCol.FieldType.Flag) {
tableRow[i] = types.NewUintDatum(uint64(handle))
} else {
tableRow[i] = types.NewIntDatum(handle)
}
continue
}
for j, idxCol := range e.indexPlan.Index.Columns {
Expand Down
8 changes: 8 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,14 @@ func (s *testSuite) TestUnion(c *C) {
r.Check(testkit.Rows("1"))
r = tk.MustQuery("select (select * from t1 where a != t.a union all (select * from t2 where a != t.a) order by a limit 1) from t1 t")
r.Check(testkit.Rows("1", "2"))

tk.MustExec("drop table if exists t")
tk.MustExec("create table t (id int unsigned primary key auto_increment, c1 int, c2 int, index c1_c2 (c1, c2))")
tk.MustExec("insert into t (c1, c2) values (1, 1)")
tk.MustExec("insert into t (c1, c2) values (1, 2)")
tk.MustExec("insert into t (c1, c2) values (2, 3)")
r = tk.MustQuery("select * from t where t.c1 = 1 union select * from t where t.id = 1")
r.Check(testkit.Rows("1 1 1", "2 1 2"))
}

func (s *testSuite) TestIn(c *C) {
Expand Down

0 comments on commit dd4dcfe

Please sign in to comment.