Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
jiawen li
tidb
Commits
90f4c5d1
Unverified
Commit
90f4c5d1
authored
3 years ago
by
Song Gao
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
expression: support push down tikv supported functions (#32348)
ref pingcap/tidb#31846
parent
4dfa95b7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
expression/expr_to_pb_test.go
+25
-0
expression/expr_to_pb_test.go
expression/expression.go
+7
-4
expression/expression.go
expression/integration_serial_test.go
+1
-1
expression/integration_serial_test.go
planner/core/integration_test.go
+20
-0
planner/core/integration_test.go
with
53 additions
and
5 deletions
+53
-5
expression/expr_to_pb_test.go
+
25
-
0
View file @
90f4c5d1
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
expression/expression.go
+
7
-
4
View file @
90f4c5d1
...
@@ -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
,
...
...
This diff is collapsed.
Click to expand it.
expression/integration_serial_test.go
+
1
-
1
View file @
90f4c5d1
...
@@ -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);`
)
...
...
This diff is collapsed.
Click to expand it.
planner/core/integration_test.go
+
20
-
0
View file @
90f4c5d1
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment