Skip to content

Commit

Permalink
expression: enable greatest/least push down to tiflash (#32788)
Browse files Browse the repository at this point in the history
close #32787
  • Loading branch information
guo-shaoge authored Mar 3, 2022
1 parent 41c1cc9 commit 6bc9cd3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions expression/expr_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 6bc9cd3

Please sign in to comment.