From 4829ff288c1b10d5525312da2d18407ff597c5be Mon Sep 17 00:00:00 2001 From: Tong Zhigao Date: Tue, 2 Jun 2020 17:37:05 +0800 Subject: [PATCH] cherry pick #17588 to release-4.0 Signed-off-by: sre-bot --- expression/expr_to_pb_test.go | 19 +++++++++++++++++++ expression/expression.go | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/expression/expr_to_pb_test.go b/expression/expr_to_pb_test.go index 078b6046eb1af..784ae74e171b3 100644 --- a/expression/expr_to_pb_test.go +++ b/expression/expr_to_pb_test.go @@ -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) diff --git a/expression/expression.go b/expression/expression.go index 578a6caf8f700..96f243d6a2394 100644 --- a/expression/expression.go +++ b/expression/expression.go @@ -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) { @@ -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() {