Skip to content

Commit

Permalink
expression: unset the flen for string type builtin control (#38845) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Nov 3, 2022
1 parent 5f53904 commit 752bc44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion expression/builtin_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ func InferType4ControlFuncs(ctx sessionctx.Context, funcName string, lexp, rexp
}
flen := maxlen(lhsFlen, rhsFlen) + resultFieldType.GetDecimal() + 1 // account for -1 len fields
resultFieldType.SetFlen(mathutil.Min(flen, mysql.MaxDecimalWidth)) // make sure it doesn't overflow

} else if evalType == types.ETString {
lhsLen, rhsLen := lhs.GetFlen(), rhs.GetFlen()
if lhsLen != types.UnspecifiedLength && rhsLen != types.UnspecifiedLength {
resultFieldType.SetFlen(mathutil.Max(lhsLen, rhsLen))
}
} else {
resultFieldType.SetFlen(maxlen(lhs.GetFlen(), rhs.GetFlen()))
}
Expand Down
12 changes: 12 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7394,3 +7394,15 @@ func TestIssue31569(t *testing.T) {
tk.MustQuery("show warnings").Check([][]interface{}{})
tk.MustExec("drop table t")
}

func TestIfNullParamMarker(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t (c1 varchar(100), c2 varchar(128));")
tk.MustExec(`prepare pr1 from "insert into t values(ifnull(?,' '),ifnull(?,' '))";`)
tk.MustExec(`set @a='1',@b=repeat('x', 80);`)
// Should not report 'Data too long for column' error.
tk.MustExec(`execute pr1 using @a,@b;`)
}

0 comments on commit 752bc44

Please sign in to comment.