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

expression: support enum pushdown #22686

Merged
merged 39 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bbfe974
support enum pushdown
dyzsr Jan 29, 2021
ffb83b2
modify test case
dyzsr Feb 3, 2021
3b05a97
modify unistore
dyzsr Feb 4, 2021
272fb86
merge from 22691
dyzsr Feb 4, 2021
50823b5
updates
dyzsr Feb 4, 2021
3cfeb2e
update decode encode
dyzsr Feb 4, 2021
3bc80be
fix CI
dyzsr Feb 4, 2021
a824e93
fix CI
dyzsr Feb 4, 2021
789d0c3
updates
dyzsr Feb 4, 2021
5ab07e6
clone column when wrapping cast as int
dyzsr Feb 18, 2021
7e1722f
Merge branch 'master' into pushdown-enum-expr
dyzsr Feb 18, 2021
4216776
Merge branch 'master' into pushdown-enum-expr
dyzsr Mar 4, 2021
1993f14
Merge branch 'master' into pushdown-enum-expr
dyzsr Mar 11, 2021
3863129
add test cases
dyzsr Mar 18, 2021
96c3967
Merge branch 'master' into pushdown-enum-expr
dyzsr Mar 18, 2021
9f12567
Merge branch 'master' into pushdown-enum-expr
dyzsr Mar 18, 2021
6ef9b72
Merge branch 'master' into pushdown-enum-expr
dyzsr Mar 24, 2021
2505e07
Merge branch 'master' into pushdown-enum-expr
dyzsr Mar 31, 2021
df8d290
fix hash join
dyzsr Mar 31, 2021
d52bb7f
updates
dyzsr Mar 31, 2021
860c1ad
updates
dyzsr Mar 31, 2021
9273da7
Merge branch 'master' into pushdown-enum-expr
dyzsr Apr 1, 2021
c655797
bug fixes
dyzsr Apr 1, 2021
0baf362
update
dyzsr Apr 1, 2021
baf882a
Merge branch 'master' into pushdown-enum-expr
dyzsr Apr 14, 2021
fa002ad
add simple test
dyzsr Apr 14, 2021
96e3859
add simple test
dyzsr Apr 14, 2021
d83fed3
update parser
wshwsh12 Apr 21, 2021
55aafe3
avoid push down to tiflash
wshwsh12 Apr 21, 2021
d810d7e
avoid enum index range scan
wshwsh12 Apr 21, 2021
e556387
Merge remote-tracking branch 'upstream/master' into pushdown-enum-expr
wshwsh12 Apr 21, 2021
b6d7bbc
fix test
wshwsh12 Apr 21, 2021
55fda14
update parser
wshwsh12 Apr 22, 2021
38da991
Merge remote-tracking branch 'upstream/master' into pushdown-enum-expr
wshwsh12 Apr 22, 2021
ab9094d
Merge branch 'master' into pushdown-enum-expr
wshwsh12 Apr 22, 2021
95affa1
add test for correlated query
dyzsr Apr 22, 2021
f5c4a16
Merge remote-tracking branch 'upstream/master' into pushdown-enum-expr
wshwsh12 Apr 25, 2021
f9a8273
Merge branch 'master' into pushdown-enum-expr
wshwsh12 Apr 26, 2021
d06b8ce
Merge branch 'master' into pushdown-enum-expr
ti-chi-bot Apr 26, 2021
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
6 changes: 6 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,12 @@ func (b *executorBuilder) buildHashJoin(v *plannercore.PhysicalHashJoin) Executo
} else {
e.buildTypes, e.probeTypes = rightTypes, leftTypes
}
for _, key := range e.buildKeys {
e.buildTypes[key.Index].Flag = key.RetType.Flag
}
for _, key := range e.probeKeys {
e.probeTypes[key.Index].Flag = key.RetType.Flag
}
return e
}

Expand Down
8 changes: 8 additions & 0 deletions expression/builtin_cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,14 @@ func BuildCastFunction(ctx sessionctx.Context, expr Expression, tp *types.FieldT
// WrapWithCastAsInt wraps `expr` with `cast` if the return type of expr is not
// type int, otherwise, returns `expr` directly.
func WrapWithCastAsInt(ctx sessionctx.Context, expr Expression) Expression {
if expr.GetType().Tp == mysql.TypeEnum {
if col, ok := expr.(*Column); ok {
col = col.Clone().(*Column)
lzmhhh123 marked this conversation as resolved.
Show resolved Hide resolved
col.RetType = col.RetType.Clone()
expr = col
}
expr.GetType().Flag |= mysql.EnumSetAsIntFlag
}
if expr.GetType().EvalType() == types.ETInt {
return expr
}
Expand Down
8 changes: 8 additions & 0 deletions expression/chunk_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ func executeToInt(ctx sessionctx.Context, expr Expression, fieldType *types.Fiel
output.AppendBytes(colID, types.NewBinaryLiteralFromUint(uint64(res), -1))
return nil
}
if fieldType.Tp == mysql.TypeEnum {
e, err := types.ParseEnumValue(fieldType.Elems, uint64(res))
if err != nil {
return err
}
output.AppendEnum(colID, e)
return nil
}
if mysql.HasUnsignedFlag(fieldType.Flag) {
output.AppendUint64(colID, uint64(res))
return nil
Expand Down
16 changes: 16 additions & 0 deletions expression/distsql_builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func PbTypeToFieldType(tp *tipb.FieldType) *types.FieldType {
Decimal: int(tp.Decimal),
Charset: tp.Charset,
Collate: protoToCollation(tp.Collate),
Elems: tp.Elems,
}
}

Expand Down Expand Up @@ -1117,6 +1118,8 @@ func PBToExpr(expr *tipb.Expr, tps []*types.FieldType, sc *stmtctx.StatementCont
return convertTime(expr.Val, expr.FieldType, sc.TimeZone)
case tipb.ExprType_MysqlJson:
return convertJSON(expr.Val)
case tipb.ExprType_MysqlEnum:
return convertEnum(expr.Val, expr.FieldType)
}
if expr.Tp != tipb.ExprType_ScalarFunc {
panic("should be a tipb.ExprType_ScalarFunc")
Expand Down Expand Up @@ -1259,3 +1262,16 @@ func convertJSON(val []byte) (*Constant, error) {
}
return &Constant{Value: d, RetType: types.NewFieldType(mysql.TypeJSON)}, nil
}

func convertEnum(val []byte, tp *tipb.FieldType) (*Constant, error) {
_, uVal, err := codec.DecodeUint(val)
if err != nil {
return nil, errors.Errorf("invalid enum % x", val)
}
e, err := types.ParseEnumValue(tp.Elems, uVal)
if err != nil {
return nil, err
}
d := types.NewMysqlEnumDatum(e)
return &Constant{Value: d, RetType: FieldTypeFromPB(tp)}, nil
}
1 change: 1 addition & 0 deletions expression/distsql_builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ func toPBFieldType(ft *types.FieldType) *tipb.FieldType {
Decimal: int32(ft.Decimal),
Charset: ft.Charset,
Collate: collationToProto(ft.Collate),
Elems: ft.Elems,
}
}

Expand Down
7 changes: 6 additions & 1 deletion expression/expr_to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func (pc *PbConverter) encodeDatum(ft *types.FieldType, d types.Datum) (tipb.Exp
return tp, val, true
}
return tp, nil, false
case types.KindMysqlEnum:
tp = tipb.ExprType_MysqlEnum
val = codec.EncodeUint(nil, d.GetUint64())
default:
return tp, nil, false
}
Expand All @@ -156,6 +159,7 @@ func ToPBFieldType(ft *types.FieldType) *tipb.FieldType {
Decimal: int32(ft.Decimal),
Charset: ft.Charset,
Collate: collationToProto(ft.Collate),
Elems: ft.Elems,
}
}

Expand All @@ -168,6 +172,7 @@ func FieldTypeFromPB(ft *tipb.FieldType) *types.FieldType {
Decimal: int(ft.Decimal),
Charset: ft.Charset,
Collate: protoToCollation(ft.Collate),
Elems: ft.Elems,
}
}

Expand Down Expand Up @@ -204,7 +209,7 @@ func (pc PbConverter) columnToPBExpr(column *Column) *tipb.Expr {
return nil
}
switch column.GetType().Tp {
case mysql.TypeBit, mysql.TypeSet, mysql.TypeEnum, mysql.TypeGeometry, mysql.TypeUnspecified:
case mysql.TypeBit, mysql.TypeSet, mysql.TypeGeometry, mysql.TypeUnspecified:
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion expression/expr_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ func (s *testEvaluatorSuite) TestColumn2Pb(c *C) {

colExprs = append(colExprs, dg.genColumn(mysql.TypeBit, 1))
colExprs = append(colExprs, dg.genColumn(mysql.TypeSet, 2))
colExprs = append(colExprs, dg.genColumn(mysql.TypeEnum, 3))
colExprs = append(colExprs, dg.genColumn(mysql.TypeGeometry, 4))
colExprs = append(colExprs, dg.genColumn(mysql.TypeUnspecified, 5))

Expand Down Expand Up @@ -180,6 +179,7 @@ func (s *testEvaluatorSuite) TestColumn2Pb(c *C) {
colExprs = append(colExprs, dg.genColumn(mysql.TypeBlob, 21))
colExprs = append(colExprs, dg.genColumn(mysql.TypeVarString, 22))
colExprs = append(colExprs, dg.genColumn(mysql.TypeString, 23))
colExprs = append(colExprs, dg.genColumn(mysql.TypeEnum, 24))
pushed, remained = PushDownExprs(sc, colExprs, client, kv.UnSpecified)
c.Assert(len(pushed), Equals, len(colExprs))
c.Assert(len(remained), Equals, 0)
Expand Down Expand Up @@ -209,6 +209,7 @@ func (s *testEvaluatorSuite) TestColumn2Pb(c *C) {
"{\"tp\":201,\"val\":\"gAAAAAAAABU=\",\"sig\":0,\"field_type\":{\"tp\":252,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":63,\"charset\":\"\"},\"has_distinct\":false}",
"{\"tp\":201,\"val\":\"gAAAAAAAABY=\",\"sig\":0,\"field_type\":{\"tp\":253,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"},\"has_distinct\":false}",
"{\"tp\":201,\"val\":\"gAAAAAAAABc=\",\"sig\":0,\"field_type\":{\"tp\":254,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":46,\"charset\":\"\"},\"has_distinct\":false}",
"{\"tp\":201,\"val\":\"gAAAAAAAABg=\",\"sig\":0,\"field_type\":{\"tp\":247,\"flag\":0,\"flen\":-1,\"decimal\":-1,\"collate\":63,\"charset\":\"\"},\"has_distinct\":false}",
}
for i, pbExpr := range pbExprs {
c.Assert(pbExprs, NotNil)
Expand Down
17 changes: 13 additions & 4 deletions expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,11 +1153,20 @@ func canScalarFuncPushDown(scalarFunc *ScalarFunction, pc PbConverter, storeType
}

func canExprPushDown(expr Expression, pc PbConverter, storeType kv.StoreType) bool {
if storeType == kv.TiFlash && expr.GetType().Tp == mysql.TypeDuration {
if pc.sc.InExplainStmt {
pc.sc.AppendWarning(errors.New("Expr '" + expr.String() + "' can not be pushed to TiFlash because it contains Duration type"))
if storeType == kv.TiFlash {
switch expr.GetType().Tp {
case mysql.TypeDuration:
if pc.sc.InExplainStmt {
pc.sc.AppendWarning(errors.New("Expr '" + expr.String() + "' can not be pushed to TiFlash because it contains Duration type"))
}
return false
case mysql.TypeEnum:
if pc.sc.InExplainStmt {
pc.sc.AppendWarning(errors.New("Expr '" + expr.String() + "' can not be pushed to TiFlash because it contains Enum type"))
}
return false
default:
}
return false
}
switch x := expr.(type) {
case *CorrelatedColumn:
Expand Down
90 changes: 90 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8985,6 +8985,96 @@ func (s *testIntegrationSuite) TestClusteredIndexCorCol(c *C) {
tk.MustQuery("select (select t2.c_str from t2 where t2.c_str = t1.c_str and t2.c_int = 10 order by t2.c_str limit 1) x from t1;").Check(testkit.Rows("<nil>", "goofy mestorf"))
}

func (s *testIntegrationSuite) TestEnumPushDown(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (c_enum enum('c', 'b', 'a'))")
tk.MustExec("insert into t values ('a'), ('b'), ('c'), ('a'), ('b'), ('a')")

// test order by
tk.MustQuery("select c_enum from t order by c_enum").
Check(testkit.Rows("c", "b", "b", "a", "a", "a"))
tk.MustQuery("select c_enum from t order by c_enum desc").
Check(testkit.Rows("a", "a", "a", "b", "b", "c"))
tk.MustQuery("select c_enum from t order by if(c_enum>1, c_enum, c_enum)").
Check(testkit.Rows("a", "a", "a", "b", "b", "c"))

// test selection
tk.MustQuery("select c_enum from t where c_enum order by c_enum").
Check(testkit.Rows("c", "b", "b", "a", "a", "a"))
tk.MustQuery("select c_enum from t where c_enum > 'a' order by c_enum").
Check(testkit.Rows("c", "b", "b"))
tk.MustQuery("select c_enum from t where c_enum > 1 order by c_enum").
Check(testkit.Rows("b", "b", "a", "a", "a"))
tk.MustQuery("select c_enum from t where c_enum = 1 order by c_enum").
Check(testkit.Rows("c"))
tk.MustQuery("select c_enum from t where c_enum = 'a' order by c_enum").
Check(testkit.Rows("a", "a", "a"))
tk.MustQuery("select c_enum from t where c_enum + 1 order by c_enum").
Check(testkit.Rows("c", "b", "b", "a", "a", "a"))
tk.MustQuery("select c_enum from t where c_enum - 1 order by c_enum").
Check(testkit.Rows("b", "b", "a", "a", "a"))

// test projection
tk.MustQuery("select c_enum+1 from t order by c_enum").
Check(testkit.Rows("2", "3", "3", "4", "4", "4"))
tk.MustQuery("select c_enum, c_enum=1 from t order by c_enum").
Check(testkit.Rows("c 1", "b 0", "b 0", "a 0", "a 0", "a 0"))
tk.MustQuery("select c_enum, c_enum>1 from t order by c_enum").
Check(testkit.Rows("c 0", "b 1", "b 1", "a 1", "a 1", "a 1"))
tk.MustQuery("select c_enum, c_enum>'a' from t order by c_enum").
Check(testkit.Rows("c 1", "b 1", "b 1", "a 0", "a 0", "a 0"))

// test aggregate
tk.MustQuery("select max(c_enum) from t").
Check(testkit.Rows("c"))
tk.MustQuery("select min(c_enum) from t").
Check(testkit.Rows("a"))
tk.MustQuery("select max(c_enum+1) from t").
Check(testkit.Rows("4"))
tk.MustQuery("select min(c_enum+1) from t").
Check(testkit.Rows("2"))
tk.MustQuery("select avg(c_enum) from t").
Check(testkit.Rows("2.3333333333333335"))
tk.MustQuery("select avg(distinct c_enum) from t").
Check(testkit.Rows("2"))
tk.MustQuery("select distinct c_enum from t order by c_enum").
Check(testkit.Rows("c", "b", "a"))
tk.MustQuery("select c_enum from t group by c_enum order by c_enum").
Check(testkit.Rows("c", "b", "a"))

// test correlated
tk.MustExec("drop table if exists t1")
tk.MustExec(`CREATE TABLE t1 (
a char(3) NOT NULL default '',
e enum('a','b','c','d','e') NOT NULL default 'a'
)`)
tk.MustExec("INSERT INTO t1 VALUES ('aaa','e')")
tk.MustExec("INSERT INTO t1 VALUES ('bbb','e')")
tk.MustExec("INSERT INTO t1 VALUES ('ccc','a')")
tk.MustExec("INSERT INTO t1 VALUES ('ddd','e')")
tk.MustQuery(`SELECT DISTINCT e AS c FROM t1 outr WHERE
a <> SOME ( SELECT a FROM t1 WHERE e = outr.e)`).
Check(testkit.Rows("e"))

// no index
tk.MustExec("drop table t")
tk.MustExec("create table t(e enum('c','b','a'))")
tk.MustExec("insert into t values(1),(2),(3)")
tk.MustQuery("select e from t where e > 'b'").
Check(testkit.Rows("c"))
tk.MustQuery("select e from t where e > 2").
Check(testkit.Rows("a"))

// enable index
tk.MustExec("alter table t add index idx(e)")
tk.MustQuery("select e from t where e > 'b'").
Check(testkit.Rows("c"))
tk.MustQuery("select e from t where e > 2").
Check(testkit.Rows("a"))
}

func (s *testIntegrationSuite) TestJiraSetInnoDBDefaultRowFormat(c *C) {
// For issue #23541
// JIRA needs to be able to set this to be happy.
Expand Down
8 changes: 7 additions & 1 deletion expression/scalar_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,13 @@ func (sf *ScalarFunction) Eval(row chunk.Row) (d types.Datum, err error) {
case types.ETJson:
res, isNull, err = sf.EvalJSON(sf.GetCtx(), row)
case types.ETString:
res, isNull, err = sf.EvalString(sf.GetCtx(), row)
var str string
str, isNull, err = sf.EvalString(sf.GetCtx(), row)
if !isNull && err == nil && tp.Tp == mysql.TypeEnum {
res, err = types.ParseEnumName(tp.Elems, str, tp.Collate)
} else {
res = str
}
}

if isNull || err != nil {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ require (
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989
github.com/pingcap/kvproto v0.0.0-20210308063835-39b884695fb8
github.com/pingcap/log v0.0.0-20210317133921-96f4fcab92a4
github.com/pingcap/parser v0.0.0-20210330190622-f959a136fc19
github.com/pingcap/parser v0.0.0-20210421190254-588138d35e55
github.com/pingcap/sysutil v0.0.0-20210315073920-cc0985d983a3
github.com/pingcap/tidb-tools v4.0.9-0.20201127090955-2707c97b3853+incompatible
github.com/pingcap/tipb v0.0.0-20210422074242-57dd881b81b1
Expand Down Expand Up @@ -75,7 +75,7 @@ require (
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
golang.org/x/sys v0.0.0-20210324051608-47abb6519492
golang.org/x/text v0.3.5
golang.org/x/text v0.3.6
golang.org/x/tools v0.1.0
google.golang.org/grpc v1.27.1
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ github.com/pingcap/log v0.0.0-20200511115504-543df19646ad/go.mod h1:4rbK1p9ILyIf
github.com/pingcap/log v0.0.0-20201112100606-8f1e84a3abc8/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v0.0.0-20210317133921-96f4fcab92a4 h1:ERrF0fTuIOnwfGbt71Ji3DKbOEaP189tjym50u8gpC8=
github.com/pingcap/log v0.0.0-20210317133921-96f4fcab92a4/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/parser v0.0.0-20210330190622-f959a136fc19 h1:WQJbP0G8RL9v+rQV7/2UAImJcV6FU9gpJ1fzpyQuaXg=
github.com/pingcap/parser v0.0.0-20210330190622-f959a136fc19/go.mod h1:xZC8I7bug4GJ5KtHhgAikjTfU4kBv1Sbo3Pf1MZ6lVw=
github.com/pingcap/parser v0.0.0-20210421190254-588138d35e55 h1:J/NfwCFFPCv7h44ft+2pS3KiMyvOkHprPM5NhDJEoHc=
github.com/pingcap/parser v0.0.0-20210421190254-588138d35e55/go.mod h1:xZC8I7bug4GJ5KtHhgAikjTfU4kBv1Sbo3Pf1MZ6lVw=
github.com/pingcap/sysutil v0.0.0-20200206130906-2bfa6dc40bcd/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/sysutil v0.0.0-20210315073920-cc0985d983a3 h1:A9KL9R+lWSVPH8IqUuH1QSTRJ5FGoY1bT2IcfPKsWD8=
github.com/pingcap/sysutil v0.0.0-20210315073920-cc0985d983a3/go.mod h1:tckvA041UWP+NqYzrJ3fMgC/Hw9wnmQ/tUkp/JaHly8=
Expand Down Expand Up @@ -500,6 +500,7 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shirou/gopsutil v2.19.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shirou/gopsutil v3.21.2+incompatible h1:U+YvJfjCh6MslYlIAXvPtzhW3YZEtc9uncueUNpD/0A=
Expand Down Expand Up @@ -781,8 +782,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
2 changes: 1 addition & 1 deletion kv/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (d RequestTypeSupportedChecker) supportExpr(exprType tipb.ExprType) bool {
switch exprType {
case tipb.ExprType_Null, tipb.ExprType_Int64, tipb.ExprType_Uint64, tipb.ExprType_String, tipb.ExprType_Bytes,
tipb.ExprType_MysqlDuration, tipb.ExprType_MysqlTime, tipb.ExprType_MysqlDecimal,
tipb.ExprType_Float32, tipb.ExprType_Float64, tipb.ExprType_ColumnRef:
tipb.ExprType_Float32, tipb.ExprType_Float64, tipb.ExprType_ColumnRef, tipb.ExprType_MysqlEnum:
return true
// aggregate functions.
case tipb.ExprType_Count, tipb.ExprType_First, tipb.ExprType_Max, tipb.ExprType_Min, tipb.ExprType_Sum, tipb.ExprType_Avg,
Expand Down
6 changes: 3 additions & 3 deletions store/mockstore/unistore/cophandler/closure_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,12 +810,12 @@ func (e *closureExecutor) processSelection(needCollectDetail bool) (gotRow bool,
if d.IsNull() {
gotRow = false
} else {
isBool, err := d.ToBool(e.sc)
isBool, err = expression.HandleOverflowOnSelection(e.sc, isBool, err)
isTrue, err := d.ToBool(e.sc)
isTrue, err = expression.HandleOverflowOnSelection(e.sc, isTrue, err)
if err != nil {
return false, errors.Trace(err)
}
gotRow = isBool != 0
gotRow = isTrue != 0
}
if !gotRow {
if e.sc.WarningCount() > wc {
Expand Down
16 changes: 12 additions & 4 deletions store/mockstore/unistore/cophandler/topn.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"container/heap"

"github.com/pingcap/errors"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/types"
tipb "github.com/pingcap/tipb/go-tipb"
Expand Down Expand Up @@ -97,10 +99,16 @@ func (t *topNHeap) Less(i, j int) bool {
v1 := t.rows[i].key[index]
v2 := t.rows[j].key[index]

ret, err := v1.CompareDatum(t.sc, &v2)
if err != nil {
t.err = errors.Trace(err)
return true
var ret int
var err error
if expression.FieldTypeFromPB(by.GetExpr().GetFieldType()).Tp == mysql.TypeEnum {
ret = types.CompareUint64(v1.GetUint64(), v2.GetUint64())
} else {
ret, err = v1.CompareDatum(t.sc, &v2)
if err != nil {
t.err = errors.Trace(err)
return true
}
}

if by.Desc {
Expand Down
Loading