mirror of
https://github.com/MariaDB/server.git
synced 2026-05-05 14:45:31 +02:00
Bug #45261 : Crash, stored procedure + decimal
Bug #48370 Absolutely wrong calculations with GROUP BY and decimal fields when using IF Added the test cases in the above two bugs for regression testing. Added additional tests that demonstrate a incomplete fix. Added a new factory method for Field_new_decimal to create a field from an (decimal returning) Item. In the new method made sure that all the precision and length variables are capped in a proper way. This is required because Item's can have larger precision than the decimal fields and thus need to be capped when creating a field based on an Item type. Fixed the wrong typecast to Item_decimal.
This commit is contained in:
parent
fad34c34cf
commit
a21cd97c35
8 changed files with 560 additions and 85 deletions
|
|
@ -451,45 +451,8 @@ Field *Item_func::tmp_table_field(TABLE *table)
|
|||
return make_string_field(table);
|
||||
break;
|
||||
case DECIMAL_RESULT:
|
||||
{
|
||||
uint8 dec= decimals;
|
||||
uint8 intg= decimal_precision() - dec;
|
||||
uint32 len= max_length;
|
||||
|
||||
/*
|
||||
Trying to put too many digits overall in a DECIMAL(prec,dec)
|
||||
will always throw a warning. We must limit dec to
|
||||
DECIMAL_MAX_SCALE however to prevent an assert() later.
|
||||
*/
|
||||
|
||||
if (dec > 0)
|
||||
{
|
||||
int overflow;
|
||||
|
||||
dec= min(dec, DECIMAL_MAX_SCALE);
|
||||
|
||||
/*
|
||||
If the value still overflows the field with the corrected dec,
|
||||
we'll throw out decimals rather than integers. This is still
|
||||
bad and of course throws a truncation warning.
|
||||
*/
|
||||
|
||||
const int required_length=
|
||||
my_decimal_precision_to_length(intg + dec, dec,
|
||||
unsigned_flag);
|
||||
|
||||
overflow= required_length - len;
|
||||
|
||||
if (overflow > 0)
|
||||
dec= max(0, dec - overflow); // too long, discard fract
|
||||
else
|
||||
/* Corrected value fits. */
|
||||
len= required_length;
|
||||
}
|
||||
|
||||
field= new Field_new_decimal(len, maybe_null, name, dec, unsigned_flag);
|
||||
field= Field_new_decimal::create_from_item(this);
|
||||
break;
|
||||
}
|
||||
case ROW_RESULT:
|
||||
default:
|
||||
// This case should never be chosen
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue