Skip to content

Commit

Permalink
expression: fix the wrong behavior of conv function (#53681) (#54945)
Browse files Browse the repository at this point in the history
close #53505
  • Loading branch information
ti-chi-bot authored Jul 31, 2024
1 parent c6aac6d commit a5befaa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/expression/builtin_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,11 @@ func (b *builtinConvSig) evalString(ctx EvalContext, row chunk.Row) (res string,
switch x := b.args[0].(type) {
case *Constant:
if x.Value.Kind() == types.KindBinaryLiteral {
str = x.Value.GetBinaryLiteral().ToBitLiteralString(true)
datum, err := x.Eval(ctx, 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 pkg/planner/core/plan_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,20 @@ func TestPlanCacheBindingIgnore(t *testing.T) {
tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("0"))
}

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 TestBuiltinFuncFlen(t *testing.T) {
// same as TestIssue45378 and TestIssue45253
store := testkit.CreateMockStore(t)
Expand Down

0 comments on commit a5befaa

Please sign in to comment.