1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-23032 FLOOR()/CEIL() incorrectly calculate the precision of a DECIMAL(M,D) column

The code in Item_func_int_val::fix_length_and_dec_int_or_decimal()
calculated badly the result data type for FLOOR()/CEIL(), so for example
the decimal(38,10) input created a decimal(28,0) result.
That was not correct, because one extra integer digit is needed.
   floor(-9.9) -> -10
   ceil(9.9)   ->  10

Rewritting the code in a more straightforward way.
Additional changes:
- FLOOR() now takes into account the presence of the UNSIGNED
flag of the argument: FLOOR(unsigned decimal) does not need an extra digits.
- FLOOR()/CEILING() now preserve the unsigned flag in the result
  data type is decimal.
These changes give nicer data types.
This commit is contained in:
Alexander Barkov
2020-08-03 13:56:10 +04:00
parent 706a7101bf
commit 6a2ee9c8bb
11 changed files with 535 additions and 156 deletions

View File

@@ -194,12 +194,12 @@ show create table t1;
drop table t1;
select hex(concat(ceiling(0.5)));
create table t1 as select concat(ceiling(0.5)) as c1;
create table t1 as select ceiling(0.5) as c0, concat(ceiling(0.5)) as c1;
show create table t1;
drop table t1;
select hex(concat(floor(0.5)));
create table t1 as select concat(floor(0.5)) as c1;
create table t1 as select floor(0.5) as c0, concat(floor(0.5)) as c1;
show create table t1;
drop table t1;