diff --git a/expression/expr_to_pb_test.go b/expression/expr_to_pb_test.go index a0e05f48fc919..6b10a692d90bd 100644 --- a/expression/expr_to_pb_test.go +++ b/expression/expr_to_pb_test.go @@ -1035,6 +1035,24 @@ func TestExprPushDownToFlash(t *testing.T) { require.NoError(t, err) exprs = append(exprs, function) + // greatest + function, err = NewFunction(mock.NewContext(), ast.Greatest, types.NewFieldType(mysql.TypeLonglong), int32Column, intColumn) + require.NoError(t, err) + exprs = append(exprs, function) + + function, err = NewFunction(mock.NewContext(), ast.Greatest, types.NewFieldType(mysql.TypeDouble), float32Column, intColumn) + require.NoError(t, err) + exprs = append(exprs, function) + + // least + function, err = NewFunction(mock.NewContext(), ast.Least, types.NewFieldType(mysql.TypeLonglong), int32Column, intColumn) + require.NoError(t, err) + exprs = append(exprs, function) + + function, err = NewFunction(mock.NewContext(), ast.Least, types.NewFieldType(mysql.TypeDouble), float32Column, intColumn) + require.NoError(t, err) + exprs = append(exprs, function) + pushed, remained = PushDownExprs(sc, exprs, client, kv.TiFlash) require.Len(t, pushed, len(exprs)) require.Len(t, remained, 0) diff --git a/expression/expression.go b/expression/expression.go index 92583380aa723..f47808b446e55 100644 --- a/expression/expression.go +++ b/expression/expression.go @@ -1151,6 +1151,12 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool { return true case ast.Sysdate: return true + case ast.Least, ast.Greatest: + switch function.Function.PbCode() { + case tipb.ScalarFuncSig_GreatestInt, tipb.ScalarFuncSig_GreatestReal, + tipb.ScalarFuncSig_LeastInt, tipb.ScalarFuncSig_LeastReal: + return true + } } return false }