Skip to content

Commit

Permalink
expression: use maximum length for integer display (pingcap#56463) (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Dec 3, 2024
1 parent 3fd908a commit bf0766b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
23 changes: 18 additions & 5 deletions pkg/expression/builtin_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,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 {
Expand Down
6 changes: 6 additions & 0 deletions tests/integrationtest/r/expression/issues.result
Original file line number Diff line number Diff line change
Expand Up @@ -2814,3 +2814,9 @@ SELECT @@GLOBAL.information_schema_stats_expiry;
0
set @@SESSION.information_schema_stats_expiry=default;
set @@GLOBAL.information_schema_stats_expiry=default;
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
6 changes: 6 additions & 0 deletions tests/integrationtest/t/expression/issues.test
Original file line number Diff line number Diff line change
Expand Up @@ -1918,3 +1918,9 @@ SELECT @@GLOBAL.information_schema_stats_expiry;
SELECT @@GLOBAL.information_schema_stats_expiry;
set @@SESSION.information_schema_stats_expiry=default;
set @@GLOBAL.information_schema_stats_expiry=default;

# 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;

0 comments on commit bf0766b

Please sign in to comment.