Skip to content

Commit

Permalink
support functions push down.
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleFall committed Mar 19, 2021
1 parent 058e52a commit 49415a0
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@ func canFuncBePushed(sf *ScalarFunction, storeType kv.StoreType) bool {
ast.DateFormat,
ast.FromDays,
// ast.ToDays,
ast.Day,
ast.DayOfYear,
ast.DayOfMonth,
ast.Year,
Expand All @@ -1039,8 +1040,10 @@ func canFuncBePushed(sf *ScalarFunction, storeType kv.StoreType) bool {
ast.PeriodAdd,
ast.PeriodDiff,
ast.TimestampDiff,
ast.DateDiff,
ast.DateAdd,
ast.FromUnixTime,
ast.UnixTimestamp,

// encryption functions.
ast.MD5,
Expand All @@ -1056,7 +1059,7 @@ func canFuncBePushed(sf *ScalarFunction, storeType kv.StoreType) bool {
ast.Inet6Aton,
ast.IsIPv4,
ast.IsIPv4Compat,
ast.IsIPv4Mapped,
ast.IsIPv4Mapped,leiyu
ast.IsIPv6:
ret = true

Expand Down Expand Up @@ -1202,7 +1205,7 @@ func CanExprsPushDown(sc *stmtctx.StatementContext, exprs []Expression, client k

func scalarExprSupportedByTiKV(function *ScalarFunction) bool {
switch function.FuncName.L {
case ast.Substr, ast.Substring, ast.DateAdd, ast.TimestampDiff,
case ast.Substr, ast.Substring, ast.DateAdd, ast.TimestampDiff, ast.DateDiff, ast.UnixTimestamp,
ast.FromUnixTime:
return false
default:
Expand All @@ -1212,7 +1215,7 @@ func scalarExprSupportedByTiKV(function *ScalarFunction) bool {

func scalarExprSupportedByTiDB(function *ScalarFunction) bool {
switch function.FuncName.L {
case ast.Substr, ast.Substring, ast.DateAdd, ast.TimestampDiff,
case ast.Substr, ast.Substring, ast.DateAdd, ast.TimestampDiff, ast.DateDiff, ast.UnixTimestamp,
ast.FromUnixTime:
return false
default:
Expand All @@ -1222,20 +1225,24 @@ func scalarExprSupportedByTiDB(function *ScalarFunction) bool {

func scalarExprSupportedByFlash(function *ScalarFunction) bool {
switch function.FuncName.L {
case ast.Plus, ast.Minus, ast.Div, ast.Mul, ast.GE, ast.LE,
ast.EQ, ast.NE, ast.LT, ast.GT, ast.Ifnull, ast.IsNull,
ast.Or, ast.In, ast.Mod, ast.And, ast.LogicOr, ast.LogicAnd,
ast.Like, ast.UnaryNot, ast.Case, ast.Month, ast.Substr,
ast.Substring, ast.TimestampDiff, ast.DateFormat, ast.FromUnixTime,
ast.JSONLength, ast.If, ast.BitNeg, ast.Xor:
case
ast.LogicOr, ast.LogicAnd, ast.UnaryNot, ast.BitNeg, ast.Xor, ast.And, ast.Or,
ast.GE, ast.LE, ast.EQ, ast.NE, ast.LT, ast.GT, ast.In, ast.IsNull, ast.Like,
ast.Plus, ast.Minus, ast.Div, ast.Mul, /*ast.Mod,*/
ast.If, ast.Ifnull, ast.Case,
ast.Substr, ast.Substring, ast.Concat, ast.ConcatWS,
ast.Year, ast.Month, ast.Day, ast.Hour,
ast.TimestampDiff, ast.DateDiff, ast.DateFormat, ast.FromUnixTime, ast.UnixTimestamp,
ast.JSONLength,
ast.AggFuncApproxCountDistinct:
return true
case ast.Cast:
switch function.Function.PbCode() {
case tipb.ScalarFuncSig_CastIntAsInt, tipb.ScalarFuncSig_CastIntAsDecimal, tipb.ScalarFuncSig_CastIntAsString, tipb.ScalarFuncSig_CastIntAsTime,
tipb.ScalarFuncSig_CastRealAsInt, tipb.ScalarFuncSig_CastRealAsDecimal, tipb.ScalarFuncSig_CastRealAsString, tipb.ScalarFuncSig_CastRealAsTime,
tipb.ScalarFuncSig_CastStringAsInt, tipb.ScalarFuncSig_CastStringAsDecimal, tipb.ScalarFuncSig_CastStringAsString, tipb.ScalarFuncSig_CastStringAsTime,
tipb.ScalarFuncSig_CastDecimalAsInt, tipb.ScalarFuncSig_CastDecimalAsDecimal, tipb.ScalarFuncSig_CastDecimalAsTime,
tipb.ScalarFuncSig_CastTimeAsInt, tipb.ScalarFuncSig_CastTimeAsDecimal, tipb.ScalarFuncSig_CastTimeAsTime:
tipb.ScalarFuncSig_CastTimeAsInt, tipb.ScalarFuncSig_CastTimeAsDecimal, tipb.ScalarFuncSig_CastTimeAsTime, tipb.ScalarFuncSig_CastTimeAsString:
return true
default:
return false
Expand Down

0 comments on commit 49415a0

Please sign in to comment.