Skip to content

Commit

Permalink
Merge branch 'master' into not_pushdown_to_tiflash_in_some_cases
Browse files Browse the repository at this point in the history
  • Loading branch information
windtalker authored Mar 12, 2021
2 parents 5691d88 + 689a598 commit 2ecaf80
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
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
9 changes: 9 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6301,6 +6301,15 @@ func (s *testIntegrationSerialSuite) TestCollationBasic(c *C) {
tk.MustQuery("select a from t_ci where a='A'").Check(testkit.Rows("a"))
tk.MustQuery("select a from t_ci where a='a '").Check(testkit.Rows("a"))
tk.MustQuery("select a from t_ci where a='a '").Check(testkit.Rows("a"))

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(c set('A', 'B') collate utf8mb4_general_ci);")
tk.MustExec("insert into t values('a');")
tk.MustExec("insert into t values('B');")
tk.MustQuery("select c from t where c = 'a';").Check(testkit.Rows("A"))
tk.MustQuery("select c from t where c = 'A';").Check(testkit.Rows("A"))
tk.MustQuery("select c from t where c = 'b';").Check(testkit.Rows("B"))
tk.MustQuery("select c from t where c = 'B';").Check(testkit.Rows("B"))
}

func (s *testIntegrationSerialSuite) TestWeightString(c *C) {
Expand Down
3 changes: 2 additions & 1 deletion planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,8 @@ func getNameValuePairs(stmtCtx *stmtctx.StatementContext, tbl *model.TableInfo,
}
}
// The converted result must be same as original datum.
cmp, err := d.CompareDatum(stmtCtx, &dVal)
// Compare them based on the dVal's type.
cmp, err := dVal.CompareDatum(stmtCtx, &d)
if err != nil {
return nil, false
} else if cmp != 0 {
Expand Down

0 comments on commit 2ecaf80

Please sign in to comment.