diff --git a/util/ranger/points.go b/util/ranger/points.go index 46a4283dd3222..3931a2c42b9fe 100644 --- a/util/ranger/points.go +++ b/util/ranger/points.go @@ -460,7 +460,7 @@ func handleEnumFromBinOp(sc *stmtctx.StatementContext, ft *types.FieldType, val for i := range ft.Elems { tmpEnum.Name = ft.Elems[i] tmpEnum.Value = uint64(i) + 1 - d := types.NewMysqlEnumDatum(tmpEnum) + d := types.NewCollateMysqlEnumDatum(tmpEnum, ft.Collate) if v, err := d.CompareDatum(sc, &val); err == nil { switch op { case ast.LT: diff --git a/util/ranger/ranger_test.go b/util/ranger/ranger_test.go index ed4722566033a..b0b66e8a469c1 100644 --- a/util/ranger/ranger_test.go +++ b/util/ranger/ranger_test.go @@ -347,12 +347,14 @@ create table t( d varchar(10), e binary(10), f varchar(10) collate utf8mb4_general_ci, + g enum('A','B','C') collate utf8mb4_general_ci, index idx_ab(a(50), b), index idx_cb(c, a), index idx_d(d(2)), index idx_e(e(2)), index idx_f(f), - index idx_de(d(2), e) + index idx_de(d(2), e), + index idx_g(g) )`) tests := []struct { @@ -628,6 +630,13 @@ create table t( filterConds: "[in(test.t.d, aab, aac)]", resultStr: "[[\"aa\" 0x61,\"aa\" 0x61]]", }, + { + indexPos: 6, + exprStr: "g = 'a'", + accessConds: "[eq(test.t.g, a)]", + filterConds: "[]", + resultStr: "[[\"A\",\"A\"]]", + }, } collate.SetNewCollationEnabledForTest(true)