From 8003f50c472256f081866344bdf3559dac749ee7 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Mon, 11 Nov 2024 16:44:27 +0800 Subject: [PATCH] expression: use maximum length for integer display (#56463) (#56926) close pingcap/tidb#41719, close pingcap/tidb#45338, close pingcap/tidb#56462 --- expression/builtin_control.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/expression/builtin_control.go b/expression/builtin_control.go index ac2d21d0044b9..7e38e1bab8375 100644 --- a/expression/builtin_control.go +++ b/expression/builtin_control.go @@ -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 {