Skip to content

Commit

Permalink
expression: push down expr json_length to tiflash (#17588)
Browse files Browse the repository at this point in the history
  • Loading branch information
solotzg authored Jun 2, 2020
1 parent 219f99a commit f03677c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 19 additions & 0 deletions expression/expr_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,25 @@ func (s *testEvaluatorSuite) TestOtherFunc2Pb(c *C) {
}
}

func (s *testEvaluatorSuite) TestExprPushDownToFlash(c *C) {
sc := new(stmtctx.StatementContext)
client := new(mock.Client)
dg := new(dataGen4Expr2PbTest)
exprs := make([]Expression, 0)
function, err := NewFunction(mock.NewContext(), ast.JSONLength, types.NewFieldType(mysql.TypeLonglong), dg.genColumn(mysql.TypeJSON, 1))
c.Assert(err, IsNil)
exprs = append(exprs, function)
canPush := CanExprsPushDown(sc, exprs, client, kv.TiFlash)
c.Assert(canPush, Equals, true)

function, err = NewFunction(mock.NewContext(), ast.JSONDepth, types.NewFieldType(mysql.TypeLonglong), dg.genColumn(mysql.TypeJSON, 2))
c.Assert(err, IsNil)
exprs = append(exprs, function)
pushed, remained := PushDownExprs(sc, exprs, client, kv.TiFlash)
c.Assert(len(pushed), Equals, 1)
c.Assert(len(remained), Equals, 1)
}

func (s *testEvaluatorSuite) TestExprOnlyPushDownToFlash(c *C) {
sc := new(stmtctx.StatementContext)
client := new(mock.Client)
Expand Down
5 changes: 3 additions & 2 deletions expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ func canScalarFuncPushDown(scalarFunc *ScalarFunction, pc PbConverter, storeType
}

func canExprPushDown(expr Expression, pc PbConverter, storeType kv.StoreType) bool {
if storeType == kv.TiFlash && (expr.GetType().Tp == mysql.TypeDuration || expr.GetType().Tp == mysql.TypeJSON || collate.NewCollationEnabled()) {
if storeType == kv.TiFlash && (expr.GetType().Tp == mysql.TypeDuration || collate.NewCollationEnabled()) {
return false
}
switch x := expr.(type) {
Expand Down Expand Up @@ -1119,7 +1119,8 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool {
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.Substring, ast.TimestampDiff, ast.DateFormat, ast.FromUnixTime,
ast.JSONLength:
return true
case ast.Cast:
switch function.Function.PbCode() {
Expand Down

0 comments on commit f03677c

Please sign in to comment.