Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: fix incorrect copy of flag in truncate function #55284

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/expression/builtin_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,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;