Skip to content

Commit 26d1843

Browse files
authored
expression: Disallow conv fuction with hybrid type argement to be pushed down to TiKV (#53502) (#59293)
close #51877
1 parent ec11b8f commit 26d1843

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

expression/expr_to_pb_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,7 @@ func TestExprPushDownToTiKV(t *testing.T) {
14041404
//datetimeColumn := genColumn(mysql.TypeDatetime, 6)
14051405
binaryStringColumn := genColumn(mysql.TypeString, 7)
14061406
dateColumn := genColumn(mysql.TypeDate, 8)
1407+
byteColumn := genColumn(mysql.TypeBit, 9)
14071408
binaryStringColumn.RetType.SetCollate(charset.CollationBin)
14081409

14091410
// Test exprs that cannot be pushed.
@@ -1443,6 +1444,24 @@ func TestExprPushDownToTiKV(t *testing.T) {
14431444
require.Len(t, pushed, 0)
14441445
require.Len(t, remained, len(exprs))
14451446

1447+
// Test Conv function
1448+
exprs = exprs[:0]
1449+
function, err = NewFunction(mock.NewContext(), ast.Conv, types.NewFieldType(mysql.TypeString), stringColumn, intColumn, intColumn)
1450+
require.NoError(t, err)
1451+
exprs = append(exprs, function)
1452+
pushed, remained = PushDownExprs(sc, exprs, client, kv.TiKV)
1453+
require.Len(t, pushed, len(exprs))
1454+
require.Len(t, remained, 0)
1455+
exprs = exprs[:0]
1456+
castByteAsStringFunc, err := NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeString), byteColumn)
1457+
require.NoError(t, err)
1458+
function, err = NewFunction(mock.NewContext(), ast.Conv, types.NewFieldType(mysql.TypeString), castByteAsStringFunc, intColumn, intColumn)
1459+
require.NoError(t, err)
1460+
exprs = append(exprs, function)
1461+
pushed, remained = PushDownExprs(sc, exprs, client, kv.TiKV)
1462+
require.Len(t, pushed, 0)
1463+
require.Len(t, remained, len(exprs))
1464+
14461465
// Test exprs that can be pushed.
14471466
exprs = exprs[:0]
14481467
pushed = pushed[:0]

expression/expression.go

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

10581058
// control flow functions.
10591059
ast.Case, ast.If, ast.Ifnull, ast.Coalesce,
@@ -1096,6 +1096,17 @@ func scalarExprSupportedByTiKV(sf *ScalarFunction) bool {
10961096
/*ast.InetNtoa, ast.InetAton, ast.Inet6Ntoa, ast.Inet6Aton, ast.IsIPv4, ast.IsIPv4Compat, ast.IsIPv4Mapped, ast.IsIPv6,*/
10971097
ast.UUID:
10981098

1099+
return true
1100+
// Rust use the llvm math functions, which have different precision with Golang/MySQL(cmath)
1101+
// open the following switchers if we implement them in coprocessor via `cmath`
1102+
case ast.Conv:
1103+
arg0 := sf.GetArgs()[0]
1104+
// To be aligned with MySQL, tidb handles hybrid type argument and binary literal specially, tikv can't be consistent with tidb now.
1105+
if f, ok := arg0.(*ScalarFunction); ok {
1106+
if f.FuncName.L == ast.Cast && (f.GetArgs()[0].GetType().Hybrid() || IsBinaryLiteral(f.GetArgs()[0])) {
1107+
return false
1108+
}
1109+
}
10991110
return true
11001111
case ast.Round:
11011112
switch sf.Function.PbCode() {

0 commit comments

Comments
 (0)