Skip to content

Commit

Permalink
executor: fix wrong enum key in point get (#24618) (#24772)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Aug 12, 2021
1 parent 210764b commit 4154778
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions executor/batch_point_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ func (s *testBatchPointGetSuite) TestIssue18843(c *C) {
tk.MustQuery("select * from t18843 where f is null").Check(testkit.Rows("2 <nil>"))
}

func (s *testBatchPointGetSuite) TestIssue24562(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists ttt")
tk.MustExec("create table ttt(a enum(\"a\",\"b\",\"c\",\"d\"), primary key(a));")
tk.MustExec("insert into ttt values(1)")
tk.MustQuery("select * from ttt where ttt.a in (\"1\",\"b\")").Check(testkit.Rows())
tk.MustQuery("select * from ttt where ttt.a in (1,\"b\")").Check(testkit.Rows("a"))
}

func (s *testBatchPointGetSuite) TestBatchPointGetUnsignedHandleWithSort(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
12 changes: 12 additions & 0 deletions executor/point_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,18 @@ func EncodeUniqueIndexValuesForKey(ctx sessionctx.Context, tblInfo *model.TableI
var str string
str, err = idxVals[i].ToString()
idxVals[i].SetString(str, colInfo.FieldType.Collate)
} else if colInfo.Tp == mysql.TypeEnum && (idxVals[i].Kind() == types.KindString || idxVals[i].Kind() == types.KindBytes || idxVals[i].Kind() == types.KindBinaryLiteral) {
var str string
var e types.Enum
str, err = idxVals[i].ToString()
if err != nil {
return nil, kv.ErrNotExist
}
e, err = types.ParseEnumName(colInfo.FieldType.Elems, str, colInfo.FieldType.Collate)
if err != nil {
return nil, kv.ErrNotExist
}
idxVals[i].SetMysqlEnum(e, colInfo.FieldType.Collate)
} else {
// If a truncated error or an overflow error is thrown when converting the type of `idxVal[i]` to
// the type of `colInfo`, the `idxVal` does not exist in the `idxInfo` for sure.
Expand Down

0 comments on commit 4154778

Please sign in to comment.