diff --git a/pkg/expression/builtin_control.go b/pkg/expression/builtin_control.go index 099d0b7443249..31fd16d25c43f 100644 --- a/pkg/expression/builtin_control.go +++ b/pkg/expression/builtin_control.go @@ -87,12 +87,25 @@ func setFlenFromArgs(evalType types.EvalType, resultFieldType *types.FieldType, } else if evalType == types.ETString { maxLen := 0 for i := range argTps { - argFlen := argTps[i].GetFlen() - if argFlen == types.UnspecifiedLength { - resultFieldType.SetFlen(types.UnspecifiedLength) - return + switch argTps[i].GetType() { + case mysql.TypeTiny: + maxLen = maxlen(4, maxLen) + case mysql.TypeShort: + maxLen = maxlen(6, maxLen) + case mysql.TypeInt24: + maxLen = maxlen(9, maxLen) + case mysql.TypeLong: + maxLen = maxlen(11, maxLen) + case mysql.TypeLonglong: + maxLen = maxlen(20, maxLen) + default: + argFlen := argTps[i].GetFlen() + if argFlen == types.UnspecifiedLength { + resultFieldType.SetFlen(types.UnspecifiedLength) + return + } + maxLen = maxlen(argFlen, maxLen) } - maxLen = maxlen(argFlen, maxLen) } resultFieldType.SetFlen(maxLen) } else { diff --git a/tests/integrationtest/r/expression/issues.result b/tests/integrationtest/r/expression/issues.result index 3ec501556b26c..40c90698a0d3b 100644 --- a/tests/integrationtest/r/expression/issues.result +++ b/tests/integrationtest/r/expression/issues.result @@ -3224,3 +3224,9 @@ Warning 1292 Truncated incorrect DOUBLE value: 'a' Warning 1292 Truncated incorrect DOUBLE value: 'a' Warning 1292 Truncated incorrect DOUBLE value: 'b' Warning 1292 Truncated incorrect DOUBLE value: 'b' +DROP TABLE IF EXISTS test.t; +CREATE TABLE test.t (id bigint(11) UNSIGNED PRIMARY KEY); +INSERT INTO test.t VALUES (1234567890123456); +SELECT IFNULL(id, 'abcdef') FROM test.t; +IFNULL(id, 'abcdef') +1234567890123456 diff --git a/tests/integrationtest/t/expression/issues.test b/tests/integrationtest/t/expression/issues.test index ea4b347876c93..1b73368e5da79 100644 --- a/tests/integrationtest/t/expression/issues.test +++ b/tests/integrationtest/t/expression/issues.test @@ -2176,3 +2176,9 @@ select (cast(f1 as float) = 1) or (cast(f1 as float) = 2) from test.t; SHOW WARNINGS; select (cast(f1 as float) != 1) and (cast(f1 as float) != 2) from test.t; SHOW WARNINGS; + +# TestIssue56462 +DROP TABLE IF EXISTS test.t; +CREATE TABLE test.t (id bigint(11) UNSIGNED PRIMARY KEY); +INSERT INTO test.t VALUES (1234567890123456); +SELECT IFNULL(id, 'abcdef') FROM test.t;