Unverified Commit 90f4c5d1 authored by Song Gao's avatar Song Gao Committed by GitHub
Browse files

expression: support push down tikv supported functions (#32348)

ref pingcap/tidb#31846
parent 4dfa95b7
Showing with 53 additions and 5 deletions
+53 -5
...@@ -1327,6 +1327,31 @@ func TestExprPushDownToTiKV(t *testing.T) { ...@@ -1327,6 +1327,31 @@ func TestExprPushDownToTiKV(t *testing.T) {
retType: types.NewFieldType(mysql.TypeString), retType: types.NewFieldType(mysql.TypeString),
args: []Expression{stringColumn, intColumn}, args: []Expression{stringColumn, intColumn},
}, },
{
functionName: ast.Date,
retType: types.NewFieldType(mysql.TypeDate),
args: []Expression{dateColumn},
},
{
functionName: ast.Week,
retType: types.NewFieldType(mysql.TypeDate),
args: []Expression{dateColumn},
},
{
functionName: ast.YearWeek,
retType: types.NewFieldType(mysql.TypeDate),
args: []Expression{dateColumn},
},
{
functionName: ast.ToSeconds,
retType: types.NewFieldType(mysql.TypeDate),
args: []Expression{dateColumn},
},
{
functionName: ast.DateDiff,
retType: types.NewFieldType(mysql.TypeDate),
args: []Expression{dateColumn, dateColumn},
},
} }
for _, tc := range testcases { for _, tc := range testcases {
......
...@@ -983,10 +983,13 @@ func scalarExprSupportedByTiKV(sf *ScalarFunction) bool { ...@@ -983,10 +983,13 @@ func scalarExprSupportedByTiKV(sf *ScalarFunction) bool {
ast.JSONUnquote, ast.JSONUnquote,
// date functions. // date functions.
ast.DateFormat, /* Date */ ast.Date, ast.Week, ast.YearWeek, ast.ToSeconds, ast.DateDiff,
ast.Hour, ast.Minute, ast.Second, ast.MicroSecond, ast.Month, /* ast.MonthName */ /* ast.TimeDiff, ast.AddTime, ast.SubTime, */
/* ast.DayName */ ast.DayOfMonth, ast.DayOfWeek, ast.DayOfYear, /* ast.Week */ ast.MonthName, ast.MakeDate, ast.TimeToSec, ast.MakeTime,
ast.Weekday, ast.WeekOfYear, ast.Year, /* ast.YearWeek */ ast.DateFormat,
ast.Hour, ast.Minute, ast.Second, ast.MicroSecond, ast.Month,
/* ast.DayName */ ast.DayOfMonth, ast.DayOfWeek, ast.DayOfYear,
ast.Weekday, ast.WeekOfYear, ast.Year,
ast.FromDays, ast.ToDays, ast.FromDays, ast.ToDays,
ast.PeriodAdd, ast.PeriodDiff, /*ast.TimestampDiff, ast.DateAdd, ast.FromUnixTime,*/ ast.PeriodAdd, ast.PeriodDiff, /*ast.TimestampDiff, ast.DateAdd, ast.FromUnixTime,*/
ast.LastDay, ast.LastDay,
......
...@@ -1912,7 +1912,7 @@ func TestTimeBuiltin(t *testing.T) { ...@@ -1912,7 +1912,7 @@ func TestTimeBuiltin(t *testing.T) {
_, err = tk.Exec(`update t set a = week("aa", 1)`) _, err = tk.Exec(`update t set a = week("aa", 1)`)
require.True(t, terror.ErrorEqual(err, types.ErrWrongValue)) require.True(t, terror.ErrorEqual(err, types.ErrWrongValue))
_, err = tk.Exec(`delete from t where a = week("aa", 1)`) _, err = tk.Exec(`delete from t where a = week("aa", 1)`)
require.True(t, terror.ErrorEqual(err, types.ErrWrongValue)) require.Equal(t, types.ErrWrongValue.Code(), errors.Cause(err).(*terror.Error).Code(), "err %v", err)
// for weekofyear // for weekofyear
result = tk.MustQuery(`select weekofyear("2012-12-22"), weekofyear("2008-02-20"), weekofyear("aa"), weekofyear(null), weekofyear(11), weekofyear(12.99);`) result = tk.MustQuery(`select weekofyear("2012-12-22"), weekofyear("2008-02-20"), weekofyear("aa"), weekofyear(null), weekofyear(11), weekofyear(12.99);`)
......
...@@ -2690,6 +2690,26 @@ func (s *testIntegrationSuite) TestScalarFunctionPushDown(c *C) { ...@@ -2690,6 +2690,26 @@ func (s *testIntegrationSuite) TestScalarFunctionPushDown(c *C) {
tk.MustQuery("explain analyze select /*+read_from_storage(tikv[t])*/ * from t where round(b,2)"). tk.MustQuery("explain analyze select /*+read_from_storage(tikv[t])*/ * from t where round(b,2)").
CheckAt([]int{0, 3, 6}, rows) CheckAt([]int{0, 3, 6}, rows)
rows[1][2] = "date(test.t.d)"
tk.MustQuery("explain analyze select /*+read_from_storage(tikv[t])*/ * from t where date(d)").
CheckAt([]int{0, 3, 6}, rows)
rows[1][2] = "week(test.t.d)"
tk.MustQuery("explain analyze select /*+read_from_storage(tikv[t])*/ * from t where week(d)").
CheckAt([]int{0, 3, 6}, rows)
rows[1][2] = "yearweek(test.t.d)"
tk.MustQuery("explain analyze select /*+read_from_storage(tikv[t])*/ * from t where yearweek(d)").
CheckAt([]int{0, 3, 6}, rows)
rows[1][2] = "to_seconds(test.t.d)"
tk.MustQuery("explain analyze select /*+read_from_storage(tikv[t])*/ * from t where to_seconds(d)").
CheckAt([]int{0, 3, 6}, rows)
rows[1][2] = "datediff(test.t.d, test.t.d)"
tk.MustQuery("explain analyze select /*+read_from_storage(tikv[t])*/ * from t where datediff(d,d)").
CheckAt([]int{0, 3, 6}, rows)
} }
func (s *testIntegrationSuite) TestDistinctScalarFunctionPushDown(c *C) { func (s *testIntegrationSuite) TestDistinctScalarFunctionPushDown(c *C) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment