diff --git a/expression/builtin_math.go b/expression/builtin_math.go index 35914aa21cd94..39277b813cff6 100644 --- a/expression/builtin_math.go +++ b/expression/builtin_math.go @@ -1186,7 +1186,11 @@ func (b *builtinConvSig) evalString(row chunk.Row) (res string, isNull bool, err switch x := b.args[0].(type) { case *Constant: if x.Value.Kind() == types.KindBinaryLiteral { - str = x.Value.GetBinaryLiteral().ToBitLiteralString(true) + datum, err := x.Eval(row) + if err != nil { + return "", false, err + } + str = datum.GetBinaryLiteral().ToBitLiteralString(true) } case *ScalarFunction: if x.FuncName.L == ast.Cast { diff --git a/planner/core/plan_cache_test.go b/planner/core/plan_cache_test.go index 091f3834f3766..ae493a7f9ab55 100644 --- a/planner/core/plan_cache_test.go +++ b/planner/core/plan_cache_test.go @@ -294,6 +294,20 @@ func TestIssue38710(t *testing.T) { tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0")) // can not use the cache because the types for @a and @b are not equal to the cached plan } +func TestIssue53505(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec(`create table t (v varchar(16))`) + tk.MustExec(`insert into t values ('156')`) + tk.MustExec(`prepare stmt7 from 'select * from t where v = conv(?, 16, 8)'`) + tk.MustExec(`set @arg=0x6E`) + tk.MustQuery(`execute stmt7 using @arg`).Check(testkit.Rows("156")) + tk.MustQuery(`execute stmt7 using @arg`).Check(testkit.Rows("156")) + tk.MustExec(`set @arg=0x70`) + tk.MustQuery(`execute stmt7 using @arg`).Check(testkit.Rows()) // empty +} + func TestPlanCacheDiagInfo(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store)