Skip to content

Commit e13fa57

Browse files
expr: Support unix_timestamp pushdown to TiKV (#59498)
close #59497
1 parent cefc7cc commit e13fa57

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

pkg/expression/expr_to_pb_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,16 @@ func TestExprPushDownToTiKV(t *testing.T) {
18801880
retType: types.NewFieldType(mysql.TypeLong),
18811881
args: []Expression{NewStrConst("year"), datetimeColumn, datetimeColumn},
18821882
},
1883+
{
1884+
functionName: ast.UnixTimestamp,
1885+
retType: types.NewFieldType(mysql.TypeLong),
1886+
args: []Expression{datetimeColumn},
1887+
},
1888+
{
1889+
functionName: ast.UnixTimestamp,
1890+
retType: types.NewFieldType(mysql.TypeNewDecimal),
1891+
args: []Expression{stringColumn},
1892+
},
18831893
}
18841894

18851895
ctx = mock.NewContext()

pkg/expression/infer_pushdown.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ func scalarExprSupportedByTiKV(ctx EvalContext, sf *ScalarFunction) bool {
224224
/*ast.InetNtoa, ast.InetAton, ast.Inet6Ntoa, ast.Inet6Aton, ast.IsIPv4, ast.IsIPv4Compat, ast.IsIPv4Mapped, ast.IsIPv6,*/
225225
ast.UUID:
226226

227+
return true
228+
case ast.UnixTimestamp:
229+
if sf.Function.PbCode() == tipb.ScalarFuncSig_UnixTimestampCurrent {
230+
return false
231+
}
227232
return true
228233
// Rust use the llvm math functions, which have different precision with Golang/MySQL(cmath)
229234
// open the following switchers if we implement them in coprocessor via `cmath`

pkg/expression/scalar_function_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,15 @@ func TestScalarFunctionHash64Equals(t *testing.T) {
185185
require.NotEqual(t, hasher1.Sum64(), hasher2.Sum64())
186186
require.False(t, sf0.Equals(sf4))
187187
}
188+
189+
// To test that when argument number is 0, unix_timestamp can not be pushed down to tikv
190+
func TestForbidUnixTimestampPushdown(t *testing.T) {
191+
ctx := mock.NewContext()
192+
fc := &unixTimestampFunctionClass{baseFunctionClass{ast.UnixTimestamp, 0, 1}}
193+
bt, err := fc.getFunction(ctx, nil)
194+
require.NoError(t, err)
195+
sf := &ScalarFunction{
196+
Function: bt,
197+
}
198+
require.False(t, scalarExprSupportedByTiKV(ctx, sf))
199+
}

0 commit comments

Comments
 (0)