Skip to content

Commit

Permalink
planner: consider Unspecified length when setting length for unhex (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Oct 16, 2023
1 parent c3b8757 commit f7b0710
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions expression/builtin_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,9 @@ func (c *unhexFunctionClass) getFunction(ctx sessionctx.Context, args []Expressi
default:
return nil, errors.Errorf("Unhex invalid args, need int or string but get %s", argType)
}
if argType.GetFlen() == types.UnspecifiedLength {
retFlen = types.UnspecifiedLength
}

bf, err := newBaseBuiltinFuncWithTp(ctx, c.funcName, args, types.ETString, types.ETString)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions planner/core/plan_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,19 @@ func TestIssue45253(t *testing.T) {
tk.MustQuery(`SELECT c1 FROM t1 WHERE TO_BASE64('')`).Check(testkit.Rows())
}

func TestIssue45378(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec(`set tidb_enable_non_prepared_plan_cache=1`)
tk.MustExec(`CREATE TABLE t1(c1 INT)`)
tk.MustExec(`INSERT INTO t1 VALUES (1)`)

tk.MustQuery(`SELECT c1 FROM t1 WHERE UNHEX(2038330881)`).Check(testkit.Rows("1"))
tk.MustQuery(`SELECT c1 FROM t1 WHERE UNHEX(2038330881)`).Check(testkit.Rows("1"))
tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1"))
}

func TestNonPreparedPlanCacheBuiltinFuncs(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down

0 comments on commit f7b0710

Please sign in to comment.