Skip to content

Commit 4272a56

Browse files
authored
expression: fix incorrect copy of flag in truncate function (#55284)
close #53546
1 parent 938ed70 commit 4272a56

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

pkg/expression/builtin_math.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,10 @@ func (c *truncateFunctionClass) getFunction(ctx BuildContext, args []Expression)
20472047
bf.tp.SetDecimalUnderLimit(calculateDecimal4RoundAndTruncate(ctx, args, argTp))
20482048
bf.tp.SetFlenUnderLimit(args[0].GetType(ctx.GetEvalCtx()).GetFlen() - args[0].GetType(ctx.GetEvalCtx()).GetDecimal() + bf.tp.GetDecimal())
20492049
}
2050-
bf.tp.AddFlag(args[0].GetType(ctx.GetEvalCtx()).GetFlag())
2050+
argFieldTp := args[0].GetType(ctx.GetEvalCtx())
2051+
if mysql.HasUnsignedFlag(argFieldTp.GetFlag()) {
2052+
bf.tp.AddFlag(mysql.UnsignedFlag)
2053+
}
20512054

20522055
var sig builtinFunc
20532056
switch argTp {

tests/integrationtest/r/expression/constant_fold.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ utf8mb4_general_ci
2424
select collation(ifnull(concat(NULL),ifnull(concat(NULL),id))) from t1;
2525
collation(ifnull(concat(NULL),ifnull(concat(NULL),id)))
2626
utf8mb4_general_ci
27+
drop table if exists t1;
28+
create table t1 (c1 int);
29+
insert into t1 values (null);
30+
select truncate(1,c1), truncate(1,c1) is not NULL from t1;
31+
truncate(1,c1) truncate(1,c1) is not NULL
32+
NULL 0

tests/integrationtest/t/expression/constant_fold.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ select collation(ifnull(concat(NULL),ifnull(concat(id),'~'))) from t;
1111
select collation(ifnull(concat(id),ifnull(concat(id),'~'))) from t;
1212
select collation(ifnull(concat(NULL),id)) from t1;
1313
select collation(ifnull(concat(NULL),ifnull(concat(NULL),id))) from t1;
14+
15+
# https://github.com/pingcap/tidb/issues/53546
16+
drop table if exists t1;
17+
create table t1 (c1 int);
18+
insert into t1 values (null);
19+
select truncate(1,c1), truncate(1,c1) is not NULL from t1;

0 commit comments

Comments
 (0)