1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

MDEV-23337 Rounding functions create a wrong data type for integer input

1. Fixing ROUND(x) and TRUNCATE(x,0) with TINYINT, SMALLINT, MEDIUMINT, BIGINT
   input to preserve the exact data type of the argument when it's possible.

2. Fixing FLOOR(x) and CEILING(x) with TINYINT, SMALLINT, MEDIUMINT, BIGINT
  to preserve the exact data type of the argument.

3. Adding dedicated Type_handler_year::Item_func_round_fix_length_and_dec()
  to easier handle ROUND(x) and TRUNCATE(x,y) for the YEAR(2) and YEAR(4)
  input. They still return INT(2) UNSIGNED and INT(4) UNSIGNED correspondingly,
  as before.
This commit is contained in:
Alexander Barkov
2020-07-30 14:30:21 +04:00
parent c3958ae407
commit a874b6c445
9 changed files with 381 additions and 30 deletions

View File

@ -5659,7 +5659,15 @@ bool Type_handler_row::
bool Type_handler_int_result::
Item_func_round_fix_length_and_dec(Item_func_round *item) const
{
item->fix_arg_int();
item->fix_arg_int(this);
return false;
}
bool Type_handler_year::
Item_func_round_fix_length_and_dec(Item_func_round *item) const
{
item->fix_arg_int(&type_handler_long); // 10.5 merge: fix to type_handler_ulong
return false;
}
@ -5667,7 +5675,7 @@ bool Type_handler_int_result::
bool Type_handler_hex_hybrid::
Item_func_round_fix_length_and_dec(Item_func_round *item) const
{
item->fix_arg_int();
item->fix_arg_int(NULL);
return false;
}
@ -5766,7 +5774,17 @@ bool Type_handler_row::
bool Type_handler_int_result::
Item_func_int_val_fix_length_and_dec(Item_func_int_val *item) const
{
item->fix_length_and_dec_int_or_decimal();
item->Type_std_attributes::set(item->arguments()[0]);
item->set_handler(this);
return false;
}
bool Type_handler_year::
Item_func_int_val_fix_length_and_dec(Item_func_int_val *item) const
{
item->Type_std_attributes::set(item->arguments()[0]);
item->set_handler(&type_handler_long);
return false;
}