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 Sqrt, Ceil, Floor and CastIntAsReal push down to TiFlash (#25085) #25178

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 51 additions & 0 deletions expression/expr_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,57 @@ func (s *testEvaluatorSuite) TestExprPushDownToFlash(c *C) {
c.Assert(err, IsNil)
exprs = append(exprs, function)

// sqrt
function, err = NewFunction(mock.NewContext(), ast.Sqrt, types.NewFieldType(mysql.TypeDouble), realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// ScalarFuncSig_CeilReal
function, err = NewFunction(mock.NewContext(), ast.Ceil, types.NewFieldType(mysql.TypeDouble), realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// ScalarFuncSig_CeilIntToInt
function, err = NewFunction(mock.NewContext(), ast.Ceil, types.NewFieldType(mysql.TypeLonglong), intColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// ScalarFuncSig_CeilDecimalToInt
function, err = NewFunction(mock.NewContext(), ast.Ceil, types.NewFieldType(mysql.TypeLonglong), decimalColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// ScalarFuncSig_CeilDecimalToDecimal
function, err = NewFunction(mock.NewContext(), ast.Ceil, types.NewFieldType(mysql.TypeNewDecimal), decimalColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// ScalarFuncSig_FloorReal
function, err = NewFunction(mock.NewContext(), ast.Floor, types.NewFieldType(mysql.TypeDouble), realColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// ScalarFuncSig_FloorIntToInt
function, err = NewFunction(mock.NewContext(), ast.Floor, types.NewFieldType(mysql.TypeLonglong), intColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// ScalarFuncSig_FloorDecimalToInt
function, err = NewFunction(mock.NewContext(), ast.Floor, types.NewFieldType(mysql.TypeLonglong), decimalColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// ScalarFuncSig_FloorDecimalToDecimal
function, err = NewFunction(mock.NewContext(), ast.Floor, types.NewFieldType(mysql.TypeNewDecimal), decimalColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// Replace
function, err = NewFunction(mock.NewContext(), ast.Replace, types.NewFieldType(mysql.TypeString), stringColumn, stringColumn, stringColumn)
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)
Expand Down
9 changes: 8 additions & 1 deletion expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,13 +996,20 @@ func scalarExprSupportedByTiKV(sf *ScalarFunction) bool {

func scalarExprSupportedByFlash(function *ScalarFunction) bool {
switch function.FuncName.L {
case ast.Floor, ast.Ceil, ast.Ceiling:
switch function.Function.PbCode() {
case tipb.ScalarFuncSig_FloorIntToDec, tipb.ScalarFuncSig_CeilIntToDec:
return false
default:
return true
}
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.Month,
ast.TimestampDiff, ast.DateFormat, ast.FromUnixTime,
ast.Sqrt,
ast.JSONLength:
return true
case ast.Substr, ast.Substring:
Expand Down