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: push down EXTRACT to TiFlash #22832

Merged
Merged
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
15 changes: 13 additions & 2 deletions expression/expr_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,11 @@ func (s *testEvaluatorSuite) TestExprPushDownToFlash(c *C) {
c.Assert(err, IsNil)
exprs = append(exprs, function)

// ExtractDatetime: can be pushed
function, err = NewFunction(mock.NewContext(), ast.Extract, types.NewFieldType(mysql.TypeLonglong), stringColumn, datetimeColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// CastIntAsInt
function, err = NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeLonglong), intColumn)
c.Assert(err, IsNil)
Expand Down Expand Up @@ -725,9 +730,15 @@ func (s *testEvaluatorSuite) TestExprPushDownToFlash(c *C) {
function, err = NewFunction(mock.NewContext(), ast.JSONDepth, types.NewFieldType(mysql.TypeLonglong), jsonColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

// ExtractDatetimeFromString: can not be pushed
function, err = NewFunction(mock.NewContext(), ast.Extract, types.NewFieldType(mysql.TypeLonglong), stringColumn, stringColumn)
c.Assert(err, IsNil)
exprs = append(exprs, function)

pushed, remained := PushDownExprs(sc, exprs, client, kv.TiFlash)
c.Assert(len(pushed), Equals, len(exprs)-1)
c.Assert(len(remained), Equals, 1)
c.Assert(len(pushed), Equals, len(exprs)-2)
c.Assert(len(remained), Equals, 2)
}

func (s *testEvaluatorSuite) TestExprOnlyPushDownToFlash(c *C) {
Expand Down
10 changes: 9 additions & 1 deletion expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,7 @@ func canFuncBePushed(sf *ScalarFunction, storeType kv.StoreType) bool {
ast.TimestampDiff,
ast.DateAdd,
ast.FromUnixTime,
ast.Extract,

// encryption functions.
ast.MD5,
Expand Down Expand Up @@ -1243,7 +1244,7 @@ func CanExprsPushDown(sc *stmtctx.StatementContext, exprs []Expression, client k
func scalarExprSupportedByTiKV(function *ScalarFunction) bool {
switch function.FuncName.L {
case ast.Substr, ast.Substring, ast.DateAdd, ast.TimestampDiff,
ast.FromUnixTime:
ast.FromUnixTime, ast.Extract:
return false
default:
return true
Expand Down Expand Up @@ -1295,6 +1296,13 @@ func scalarExprSupportedByFlash(function *ScalarFunction) bool {
default:
return false
}
case ast.Extract:
switch function.Function.PbCode() {
case tipb.ScalarFuncSig_ExtractDatetime:
return true
default:
return false
}
default:
return false
}
Expand Down