Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: Disallow conv fuction with hybrid type argement to be pushed down to TiKV #53502

Merged
merged 3 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/expression/expr_to_pb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,7 @@ func TestExprPushDownToTiKV(t *testing.T) {
//datetimeColumn := genColumn(mysql.TypeDatetime, 6)
binaryStringColumn := genColumn(mysql.TypeString, 7)
dateColumn := genColumn(mysql.TypeDate, 8)
byteColumn := genColumn(mysql.TypeBit, 9)
binaryStringColumn.RetType.SetCollate(charset.CollationBin)

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

// Test Conv function
exprs = exprs[:0]
function, err = NewFunction(mock.NewContext(), ast.Conv, types.NewFieldType(mysql.TypeString), stringColumn, intColumn, intColumn)
require.NoError(t, err)
exprs = append(exprs, function)
pushed, remained = PushDownExprs(pushDownCtx, exprs, kv.TiKV)
require.Len(t, pushed, len(exprs))
require.Len(t, remained, 0)
exprs = exprs[:0]
castByteAsStringFunc, err := NewFunction(mock.NewContext(), ast.Cast, types.NewFieldType(mysql.TypeString), byteColumn)
require.NoError(t, err)
function, err = NewFunction(mock.NewContext(), ast.Conv, types.NewFieldType(mysql.TypeString), castByteAsStringFunc, intColumn, intColumn)
require.NoError(t, err)
exprs = append(exprs, function)
pushed, remained = PushDownExprs(pushDownCtx, exprs, kv.TiKV)
require.Len(t, pushed, 0)
require.Len(t, remained, len(exprs))

// Test exprs that can be pushed.
exprs = exprs[:0]
pushed = pushed[:0]
Expand Down
13 changes: 12 additions & 1 deletion pkg/expression/infer_pushdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func scalarExprSupportedByTiKV(sf *ScalarFunction) bool {
// Rust use the llvm math functions, which have different precision with Golang/MySQL(cmath)
// open the following switchers if we implement them in coprocessor via `cmath`
ast.Sin, ast.Asin, ast.Cos, ast.Acos /* ast.Tan */, ast.Atan, ast.Atan2, ast.Cot,
ast.Radians, ast.Degrees, ast.Conv, ast.CRC32,
ast.Radians, ast.Degrees, ast.CRC32,

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

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