1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-12770 Add Type_handler::decimal_precision() + MDEV-12769

This patch for MDEV-12770 is also fixing:

MDEV-12769 Arithmetic operators with temporal types create excessive column types
This commit is contained in:
Alexander Barkov
2017-05-10 08:30:56 +04:00
parent 18ad176809
commit cd32f84214
9 changed files with 107 additions and 56 deletions

View File

@ -3953,6 +3953,62 @@ uint Type_handler_temporal_result::
/***************************************************************************/
uint Type_handler_string_result::Item_decimal_precision(const Item *item) const
{
uint res= item->max_char_length();
/*
Return at least one decimal digit, even if Item::max_char_length()
returned 0. This is important to avoid attempts to create fields of types
INT(0) or DECIMAL(0,0) when converting NULL or empty strings to INT/DECIMAL:
CREATE TABLE t1 AS SELECT CONVERT(NULL,SIGNED) AS a;
*/
return res ? MY_MIN(res, DECIMAL_MAX_PRECISION) : 1;
}
uint Type_handler_real_result::Item_decimal_precision(const Item *item) const
{
uint res= item->max_char_length();
return res ? MY_MIN(res, DECIMAL_MAX_PRECISION) : 1;
}
uint Type_handler_decimal_result::Item_decimal_precision(const Item *item) const
{
uint prec= my_decimal_length_to_precision(item->max_char_length(),
item->decimals,
item->unsigned_flag);
return MY_MIN(prec, DECIMAL_MAX_PRECISION);
}
uint Type_handler_int_result::Item_decimal_precision(const Item *item) const
{
uint prec= my_decimal_length_to_precision(item->max_char_length(),
item->decimals,
item->unsigned_flag);
return MY_MIN(prec, DECIMAL_MAX_PRECISION);
}
uint Type_handler_time_common::Item_decimal_precision(const Item *item) const
{
return 7 + MY_MIN(item->decimals, TIME_SECOND_PART_DIGITS);
}
uint Type_handler_date_common::Item_decimal_precision(const Item *item) const
{
return 8;
}
uint Type_handler_datetime_common::Item_decimal_precision(const Item *item) const
{
return 14 + MY_MIN(item->decimals, TIME_SECOND_PART_DIGITS);
}
uint Type_handler_timestamp_common::Item_decimal_precision(const Item *item) const
{
return 14 + MY_MIN(item->decimals, TIME_SECOND_PART_DIGITS);
}
/***************************************************************************/
bool Type_handler_real_result::
subquery_type_allows_materialization(const Item *inner,
const Item *outer) const