Skip to content

Commit

Permalink
expression: fix the wrong behavior of conv function (#53681) (#53814)
Browse files Browse the repository at this point in the history
close #53505
  • Loading branch information
ti-chi-bot authored Jun 10, 2024
1 parent c761650 commit 5806632
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion expression/builtin_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions planner/core/plan_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5806632

Please sign in to comment.