Skip to content

Commit bf0766b

Browse files
authored
expression: use maximum length for integer display (pingcap#56463) (pingcap#56929)
close pingcap#41719, close pingcap#45338, close pingcap#56462
1 parent 3fd908a commit bf0766b

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

pkg/expression/builtin_control.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,25 @@ func setFlenFromArgs(evalType types.EvalType, resultFieldType *types.FieldType,
8484
} else if evalType == types.ETString {
8585
maxLen := 0
8686
for i := range argTps {
87-
argFlen := argTps[i].GetFlen()
88-
if argFlen == types.UnspecifiedLength {
89-
resultFieldType.SetFlen(types.UnspecifiedLength)
90-
return
87+
switch argTps[i].GetType() {
88+
case mysql.TypeTiny:
89+
maxLen = maxlen(4, maxLen)
90+
case mysql.TypeShort:
91+
maxLen = maxlen(6, maxLen)
92+
case mysql.TypeInt24:
93+
maxLen = maxlen(9, maxLen)
94+
case mysql.TypeLong:
95+
maxLen = maxlen(11, maxLen)
96+
case mysql.TypeLonglong:
97+
maxLen = maxlen(20, maxLen)
98+
default:
99+
argFlen := argTps[i].GetFlen()
100+
if argFlen == types.UnspecifiedLength {
101+
resultFieldType.SetFlen(types.UnspecifiedLength)
102+
return
103+
}
104+
maxLen = maxlen(argFlen, maxLen)
91105
}
92-
maxLen = maxlen(argFlen, maxLen)
93106
}
94107
resultFieldType.SetFlen(maxLen)
95108
} else {

tests/integrationtest/r/expression/issues.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,3 +2814,9 @@ SELECT @@GLOBAL.information_schema_stats_expiry;
28142814
0
28152815
set @@SESSION.information_schema_stats_expiry=default;
28162816
set @@GLOBAL.information_schema_stats_expiry=default;
2817+
DROP TABLE IF EXISTS test.t;
2818+
CREATE TABLE test.t (id bigint(11) UNSIGNED PRIMARY KEY);
2819+
INSERT INTO test.t VALUES (1234567890123456);
2820+
SELECT IFNULL(id, 'abcdef') FROM test.t;
2821+
IFNULL(id, 'abcdef')
2822+
1234567890123456

tests/integrationtest/t/expression/issues.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,3 +1918,9 @@ SELECT @@GLOBAL.information_schema_stats_expiry;
19181918
SELECT @@GLOBAL.information_schema_stats_expiry;
19191919
set @@SESSION.information_schema_stats_expiry=default;
19201920
set @@GLOBAL.information_schema_stats_expiry=default;
1921+
1922+
# TestIssue56462
1923+
DROP TABLE IF EXISTS test.t;
1924+
CREATE TABLE test.t (id bigint(11) UNSIGNED PRIMARY KEY);
1925+
INSERT INTO test.t VALUES (1234567890123456);
1926+
SELECT IFNULL(id, 'abcdef') FROM test.t;

0 commit comments

Comments
 (0)