Skip to content

Commit

Permalink
expression: fix incorrect copy of flag in truncate function (pingcap#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tuziemon authored Nov 15, 2024
1 parent 938ed70 commit 4272a56
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/expression/builtin_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,10 @@ func (c *truncateFunctionClass) getFunction(ctx BuildContext, args []Expression)
bf.tp.SetDecimalUnderLimit(calculateDecimal4RoundAndTruncate(ctx, args, argTp))
bf.tp.SetFlenUnderLimit(args[0].GetType(ctx.GetEvalCtx()).GetFlen() - args[0].GetType(ctx.GetEvalCtx()).GetDecimal() + bf.tp.GetDecimal())
}
bf.tp.AddFlag(args[0].GetType(ctx.GetEvalCtx()).GetFlag())
argFieldTp := args[0].GetType(ctx.GetEvalCtx())
if mysql.HasUnsignedFlag(argFieldTp.GetFlag()) {
bf.tp.AddFlag(mysql.UnsignedFlag)
}

var sig builtinFunc
switch argTp {
Expand Down
6 changes: 6 additions & 0 deletions tests/integrationtest/r/expression/constant_fold.result
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ utf8mb4_general_ci
select collation(ifnull(concat(NULL),ifnull(concat(NULL),id))) from t1;
collation(ifnull(concat(NULL),ifnull(concat(NULL),id)))
utf8mb4_general_ci
drop table if exists t1;
create table t1 (c1 int);
insert into t1 values (null);
select truncate(1,c1), truncate(1,c1) is not NULL from t1;
truncate(1,c1) truncate(1,c1) is not NULL
NULL 0
6 changes: 6 additions & 0 deletions tests/integrationtest/t/expression/constant_fold.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ select collation(ifnull(concat(NULL),ifnull(concat(id),'~'))) from t;
select collation(ifnull(concat(id),ifnull(concat(id),'~'))) from t;
select collation(ifnull(concat(NULL),id)) from t1;
select collation(ifnull(concat(NULL),ifnull(concat(NULL),id))) from t1;

# https://github.com/pingcap/tidb/issues/53546
drop table if exists t1;
create table t1 (c1 int);
insert into t1 values (null);
select truncate(1,c1), truncate(1,c1) is not NULL from t1;

0 comments on commit 4272a56

Please sign in to comment.