Skip to content

Commit c973157

Browse files
authored
expression: Disallow conv fuction with hybrid type argement to be pushed down to TiKV (#53502)
close #51877
1 parent 3004c07 commit c973157

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

pkg/expression/expr_to_pb_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,7 @@ func TestExprPushDownToTiKV(t *testing.T) {
14561456
//datetimeColumn := genColumn(mysql.TypeDatetime, 6)
14571457
binaryStringColumn := genColumn(mysql.TypeString, 7)
14581458
dateColumn := genColumn(mysql.TypeDate, 8)
1459+
byteColumn := genColumn(mysql.TypeBit, 9)
14591460
binaryStringColumn.RetType.SetCollate(charset.CollationBin)
14601461

14611462
// Test exprs that cannot be pushed.
@@ -1497,6 +1498,24 @@ func TestExprPushDownToTiKV(t *testing.T) {
14971498
require.Len(t, pushed, 0)
14981499
require.Len(t, remained, len(exprs))
14991500

1501+
// Test Conv function
1502+
exprs = exprs[:0]
1503+
function, err = NewFunction(mock.NewContext(), ast.Conv, types.NewFieldType(mysql.TypeString), stringColumn, intColumn, intColumn)
1504+
require.NoError(t, err)
1505+
exprs = append(exprs, function)
1506+
pushed, remained = PushDownExprs(pushDownCtx, exprs, kv.TiKV)
1507+
require.Len(t, pushed, len(exprs))
1508+
require.Len(t, remained, 0)
1509+
exprs = exprs[:0]
1510+
castByteAsStringFunc, err := NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeString), byteColumn)
1511+
require.NoError(t, err)
1512+
function, err = NewFunction(mock.NewContext(), ast.Conv, types.NewFieldType(mysql.TypeString), castByteAsStringFunc, intColumn, intColumn)
1513+
require.NoError(t, err)
1514+
exprs = append(exprs, function)
1515+
pushed, remained = PushDownExprs(pushDownCtx, exprs, kv.TiKV)
1516+
require.Len(t, pushed, 0)
1517+
require.Len(t, remained, len(exprs))
1518+
15001519
// Test exprs that can be pushed.
15011520
exprs = exprs[:0]
15021521
pushed = pushed[:0]

pkg/expression/infer_pushdown.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func scalarExprSupportedByTiKV(sf *ScalarFunction) bool {
177177
// Rust use the llvm math functions, which have different precision with Golang/MySQL(cmath)
178178
// open the following switchers if we implement them in coprocessor via `cmath`
179179
ast.Sin, ast.Asin, ast.Cos, ast.Acos /* ast.Tan */, ast.Atan, ast.Atan2, ast.Cot,
180-
ast.Radians, ast.Degrees, ast.Conv, ast.CRC32,
180+
ast.Radians, ast.Degrees, ast.CRC32,
181181

182182
// control flow functions.
183183
ast.Case, ast.If, ast.Ifnull, ast.Coalesce,
@@ -221,6 +221,17 @@ func scalarExprSupportedByTiKV(sf *ScalarFunction) bool {
221221
/*ast.InetNtoa, ast.InetAton, ast.Inet6Ntoa, ast.Inet6Aton, ast.IsIPv4, ast.IsIPv4Compat, ast.IsIPv4Mapped, ast.IsIPv6,*/
222222
ast.UUID:
223223

224+
return true
225+
// Rust use the llvm math functions, which have different precision with Golang/MySQL(cmath)
226+
// open the following switchers if we implement them in coprocessor via `cmath`
227+
case ast.Conv:
228+
arg0 := sf.GetArgs()[0]
229+
// To be aligned with MySQL, tidb handles hybrid type argument and binary literal specially, tikv can't be consistent with tidb now.
230+
if f, ok := arg0.(*ScalarFunction); ok {
231+
if f.FuncName.L == ast.Cast && (f.GetArgs()[0].GetType().Hybrid() || IsBinaryLiteral(f.GetArgs()[0])) {
232+
return false
233+
}
234+
}
224235
return true
225236
case ast.Round:
226237
switch sf.Function.PbCode() {

0 commit comments

Comments
 (0)