diff --git a/expression/expr_to_pb_test.go b/expression/expr_to_pb_test.go index d997e9cf1691f..1a60a1266b8df 100644 --- a/expression/expr_to_pb_test.go +++ b/expression/expr_to_pb_test.go @@ -729,14 +729,41 @@ func (s *testEvaluatorSuite) TestExprPushDownToFlash(c *C) { c.Assert(err, IsNil) exprs = append(exprs, function) + // ScalarFuncSig_RoundReal function, err = NewFunction(mock.NewContext(), ast.Round, types.NewFieldType(mysql.TypeDouble), realColumn) c.Assert(err, IsNil) exprs = append(exprs, function) + // ScalarFuncSig_RoundInt function, err = NewFunction(mock.NewContext(), ast.Round, types.NewFieldType(mysql.TypeLonglong), intColumn) c.Assert(err, IsNil) exprs = append(exprs, function) + // concat + function, err = NewFunction(mock.NewContext(), ast.Concat, types.NewFieldType(mysql.TypeString), stringColumn, intColumn, realColumn) + c.Assert(err, IsNil) + exprs = append(exprs, function) + + // UnixTimestampCurrent + function, err = NewFunction(mock.NewContext(), ast.UnixTimestamp, types.NewFieldType(mysql.TypeLonglong)) + c.Assert(err, IsNil) + _, ok := function.(*Constant) + c.Assert(ok, IsTrue) + + // UnixTimestampInt + datetimeColumn.RetType.Decimal = 0 + function, err = NewFunction(mock.NewContext(), ast.UnixTimestamp, types.NewFieldType(mysql.TypeLonglong), datetimeColumn) + c.Assert(err, IsNil) + c.Assert(function.(*ScalarFunction).Function.PbCode(), Equals, tipb.ScalarFuncSig_UnixTimestampInt) + exprs = append(exprs, function) + + // UnixTimestampDecimal + datetimeColumn.RetType.Decimal = types.UnspecifiedLength + function, err = NewFunction(mock.NewContext(), ast.UnixTimestamp, types.NewFieldType(mysql.TypeNewDecimal), datetimeColumn) + c.Assert(err, IsNil) + c.Assert(function.(*ScalarFunction).Function.PbCode(), Equals, tipb.ScalarFuncSig_UnixTimestampDec) + exprs = append(exprs, function) + canPush := CanExprsPushDown(sc, exprs, client, kv.TiFlash) c.Assert(canPush, Equals, true) diff --git a/expression/expression.go b/expression/expression.go index 20178919a89b4..9a14537cac248 100644 --- a/expression/expression.go +++ b/expression/expression.go @@ -1001,6 +1001,7 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool { 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.Concat, ast.Month, ast.TimestampDiff, ast.DateFormat, ast.FromUnixTime, ast.JSONLength: @@ -1026,6 +1027,11 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool { case tipb.ScalarFuncSig_AddDateDatetimeInt, tipb.ScalarFuncSig_AddDateStringInt: return true } + case ast.UnixTimestamp: + switch function.Function.PbCode() { + case tipb.ScalarFuncSig_UnixTimestampInt, tipb.ScalarFuncSig_UnixTimestampDec: + return true + } case ast.Round: switch function.Function.PbCode() { case tipb.ScalarFuncSig_RoundInt, tipb.ScalarFuncSig_RoundReal: