mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-9395 Add Type_handler::Item_decimal_scale() and Item_divisor_precision_increment()
This commit is contained in:
21
sql/field.h
21
sql/field.h
@ -525,27 +525,6 @@ inline bool is_temporal_type(enum_field_types type)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Tests if field type is temporal and has time part,
|
||||
i.e. represents TIME, DATETIME or TIMESTAMP types in SQL.
|
||||
|
||||
@param type Field type, as returned by field->type().
|
||||
@retval true If field type is temporal type with time part.
|
||||
@retval false If field type is not temporal type with time part.
|
||||
*/
|
||||
inline bool is_temporal_type_with_time(enum_field_types type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case MYSQL_TYPE_TIME:
|
||||
case MYSQL_TYPE_DATETIME:
|
||||
case MYSQL_TYPE_TIMESTAMP:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
enum enum_vcol_info_type
|
||||
{
|
||||
VCOL_GENERATED_VIRTUAL, VCOL_GENERATED_STORED,
|
||||
|
10
sql/item.h
10
sql/item.h
@ -1162,10 +1162,7 @@ public:
|
||||
*/
|
||||
uint decimal_scale() const
|
||||
{
|
||||
return decimals < NOT_FIXED_DEC ? decimals :
|
||||
is_temporal_type_with_time(field_type()) ?
|
||||
TIME_SECOND_PART_DIGITS :
|
||||
MY_MIN(max_length, DECIMAL_MAX_SCALE);
|
||||
return type_handler()->Item_decimal_scale(this);
|
||||
}
|
||||
/*
|
||||
Returns how many digits a divisor adds into a division result.
|
||||
@ -1186,10 +1183,7 @@ public:
|
||||
*/
|
||||
uint divisor_precision_increment() const
|
||||
{
|
||||
return decimals < NOT_FIXED_DEC ? decimals :
|
||||
is_temporal_type_with_time(field_type()) ?
|
||||
TIME_SECOND_PART_DIGITS :
|
||||
decimals;
|
||||
return type_handler()->Item_divisor_precision_increment(this);
|
||||
}
|
||||
/**
|
||||
TIME or DATETIME precision of the item: 0..6
|
||||
|
@ -3696,6 +3696,36 @@ uint Type_handler_string_result::Item_temporal_precision(Item *item,
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
uint Type_handler::Item_decimal_scale(const Item *item) const
|
||||
{
|
||||
return item->decimals < NOT_FIXED_DEC ?
|
||||
item->decimals :
|
||||
MY_MIN(item->max_length, DECIMAL_MAX_SCALE);
|
||||
}
|
||||
|
||||
uint Type_handler_temporal_result::
|
||||
Item_decimal_scale_with_seconds(const Item *item) const
|
||||
{
|
||||
return item->decimals < NOT_FIXED_DEC ?
|
||||
item->decimals :
|
||||
TIME_SECOND_PART_DIGITS;
|
||||
}
|
||||
|
||||
uint Type_handler::Item_divisor_precision_increment(const Item *item) const
|
||||
{
|
||||
return item->decimals;
|
||||
}
|
||||
|
||||
uint Type_handler_temporal_result::
|
||||
Item_divisor_precision_increment_with_seconds(const Item *item) const
|
||||
{
|
||||
return item->decimals < NOT_FIXED_DEC ?
|
||||
item->decimals :
|
||||
TIME_SECOND_PART_DIGITS;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
bool Type_handler_real_result::
|
||||
subquery_type_allows_materialization(const Item *inner,
|
||||
const Item *outer) const
|
||||
|
@ -479,6 +479,12 @@ public:
|
||||
}
|
||||
virtual uint Item_time_precision(Item *item) const;
|
||||
virtual uint Item_datetime_precision(Item *item) const;
|
||||
virtual uint Item_decimal_scale(const Item *item) const;
|
||||
/*
|
||||
Returns how many digits a divisor adds into a division result.
|
||||
See Item::divisor_precision_increment() in item.h for more comments.
|
||||
*/
|
||||
virtual uint Item_divisor_precision_increment(const Item *) const;
|
||||
/**
|
||||
Makes a temporary table Field to handle numeric aggregate functions,
|
||||
e.g. SUM(DISTINCT expr), AVG(DISTINCT expr), etc.
|
||||
@ -1110,6 +1116,9 @@ public:
|
||||
|
||||
class Type_handler_temporal_result: public Type_handler
|
||||
{
|
||||
protected:
|
||||
uint Item_decimal_scale_with_seconds(const Item *item) const;
|
||||
uint Item_divisor_precision_increment_with_seconds(const Item *) const;
|
||||
public:
|
||||
Item_result result_type() const { return STRING_RESULT; }
|
||||
Item_result cmp_type() const { return TIME_RESULT; }
|
||||
@ -1441,6 +1450,14 @@ public:
|
||||
{
|
||||
return MYSQL_TIMESTAMP_TIME;
|
||||
}
|
||||
uint Item_decimal_scale(const Item *item) const
|
||||
{
|
||||
return Item_decimal_scale_with_seconds(item);
|
||||
}
|
||||
uint Item_divisor_precision_increment(const Item *item) const
|
||||
{
|
||||
return Item_divisor_precision_increment_with_seconds(item);
|
||||
}
|
||||
const Type_handler *type_handler_for_comparison() const;
|
||||
int Item_save_in_field(Item *item, Field *field, bool no_conversions) const;
|
||||
String *print_item_value(THD *thd, Item *item, String *str) const;
|
||||
@ -1543,6 +1560,14 @@ public:
|
||||
{
|
||||
return MYSQL_TIMESTAMP_DATETIME;
|
||||
}
|
||||
uint Item_decimal_scale(const Item *item) const
|
||||
{
|
||||
return Item_decimal_scale_with_seconds(item);
|
||||
}
|
||||
uint Item_divisor_precision_increment(const Item *item) const
|
||||
{
|
||||
return Item_divisor_precision_increment_with_seconds(item);
|
||||
}
|
||||
String *print_item_value(THD *thd, Item *item, String *str) const;
|
||||
bool Item_hybrid_func_fix_attributes(THD *thd, Item_hybrid_func *func,
|
||||
Item **items, uint nitems) const;
|
||||
@ -1587,6 +1612,14 @@ public:
|
||||
{
|
||||
return MYSQL_TIMESTAMP_DATETIME;
|
||||
}
|
||||
uint Item_decimal_scale(const Item *item) const
|
||||
{
|
||||
return Item_decimal_scale_with_seconds(item);
|
||||
}
|
||||
uint Item_divisor_precision_increment(const Item *item) const
|
||||
{
|
||||
return Item_divisor_precision_increment_with_seconds(item);
|
||||
}
|
||||
String *print_item_value(THD *thd, Item *item, String *str) const;
|
||||
bool Item_hybrid_func_fix_attributes(THD *thd, Item_hybrid_func *func,
|
||||
Item **items, uint nitems) const;
|
||||
|
Reference in New Issue
Block a user