planner: fix incorrect flen for the to_base64 function (#45363)

close pingcap/tidb#45253
This commit is contained in:
Yuanjia Zhang
2023-07-14 16:47:14 +08:00
committed by GitHub
parent de99f81e58
commit 752f6d1b9d
2 changed files with 22 additions and 1 deletions

View File

@ -3531,7 +3531,12 @@ func (c *toBase64FunctionClass) getFunction(ctx sessionctx.Context, args []Expre
charset, collate := ctx.GetSessionVars().GetCharsetInfo()
bf.tp.SetCharset(charset)
bf.tp.SetCollate(collate)
bf.tp.SetFlen(base64NeededEncodedLength(bf.args[0].GetType().GetFlen()))
if bf.args[0].GetType().GetFlen() == types.UnspecifiedLength {
bf.tp.SetFlen(types.UnspecifiedLength)
} else {
bf.tp.SetFlen(base64NeededEncodedLength(bf.args[0].GetType().GetFlen()))
}
valStr, _ := ctx.GetSessionVars().GetSystemVar(variable.MaxAllowedPacket)
maxAllowedPacket, err := strconv.ParseUint(valStr, 10, 64)

View File

@ -2417,6 +2417,22 @@ func TestIssue43667(t *testing.T) {
tk.MustQueryWithContext(tctx, `select (val) from cycle where pk = 4`).Check(testkit.Rows("4"))
}
func TestIssue45253(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 TO_BASE64('牵')`).Check(testkit.Rows("1"))
tk.MustQuery(`SELECT c1 FROM t1 WHERE TO_BASE64('牵')`).Check(testkit.Rows("1"))
tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1"))
tk.MustQuery(`SELECT c1 FROM t1 WHERE TO_BASE64('哈')`).Check(testkit.Rows("1"))
tk.MustQuery(`select @@last_plan_from_cache`).Check(testkit.Rows("1"))
tk.MustQuery(`SELECT c1 FROM t1 WHERE TO_BASE64('')`).Check(testkit.Rows())
}
func TestNonPreparedPlanCacheBuiltinFuncs(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)