Commit 7a19c59c authored by Alexander Barkov's avatar Alexander Barkov

MDEV-9395 Add Type_handler::Item_decimal_scale() and Item_divisor_precision_increment()

parent ea18b112
...@@ -525,27 +525,6 @@ inline bool is_temporal_type(enum_field_types type) ...@@ -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 enum enum_vcol_info_type
{ {
VCOL_GENERATED_VIRTUAL, VCOL_GENERATED_STORED, VCOL_GENERATED_VIRTUAL, VCOL_GENERATED_STORED,
......
...@@ -1162,10 +1162,7 @@ class Item: public Value_source, ...@@ -1162,10 +1162,7 @@ class Item: public Value_source,
*/ */
uint decimal_scale() const uint decimal_scale() const
{ {
return decimals < NOT_FIXED_DEC ? decimals : return type_handler()->Item_decimal_scale(this);
is_temporal_type_with_time(field_type()) ?
TIME_SECOND_PART_DIGITS :
MY_MIN(max_length, DECIMAL_MAX_SCALE);
} }
/* /*
Returns how many digits a divisor adds into a division result. Returns how many digits a divisor adds into a division result.
...@@ -1186,10 +1183,7 @@ class Item: public Value_source, ...@@ -1186,10 +1183,7 @@ class Item: public Value_source,
*/ */
uint divisor_precision_increment() const uint divisor_precision_increment() const
{ {
return decimals < NOT_FIXED_DEC ? decimals : return type_handler()->Item_divisor_precision_increment(this);
is_temporal_type_with_time(field_type()) ?
TIME_SECOND_PART_DIGITS :
decimals;
} }
/** /**
TIME or DATETIME precision of the item: 0..6 TIME or DATETIME precision of the item: 0..6
......
...@@ -3696,6 +3696,36 @@ uint Type_handler_string_result::Item_temporal_precision(Item *item, ...@@ -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:: bool Type_handler_real_result::
subquery_type_allows_materialization(const Item *inner, subquery_type_allows_materialization(const Item *inner,
const Item *outer) const const Item *outer) const
......
...@@ -479,6 +479,12 @@ class Type_handler ...@@ -479,6 +479,12 @@ class Type_handler
} }
virtual uint Item_time_precision(Item *item) const; virtual uint Item_time_precision(Item *item) const;
virtual uint Item_datetime_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, Makes a temporary table Field to handle numeric aggregate functions,
e.g. SUM(DISTINCT expr), AVG(DISTINCT expr), etc. e.g. SUM(DISTINCT expr), AVG(DISTINCT expr), etc.
...@@ -1110,6 +1116,9 @@ class Type_handler_int_result: public Type_handler_numeric ...@@ -1110,6 +1116,9 @@ class Type_handler_int_result: public Type_handler_numeric
class Type_handler_temporal_result: public Type_handler 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: public:
Item_result result_type() const { return STRING_RESULT; } Item_result result_type() const { return STRING_RESULT; }
Item_result cmp_type() const { return TIME_RESULT; } Item_result cmp_type() const { return TIME_RESULT; }
...@@ -1441,6 +1450,14 @@ class Type_handler_time_common: public Type_handler_temporal_result ...@@ -1441,6 +1450,14 @@ class Type_handler_time_common: public Type_handler_temporal_result
{ {
return MYSQL_TIMESTAMP_TIME; 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; const Type_handler *type_handler_for_comparison() const;
int Item_save_in_field(Item *item, Field *field, bool no_conversions) 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; String *print_item_value(THD *thd, Item *item, String *str) const;
...@@ -1543,6 +1560,14 @@ class Type_handler_datetime_common: public Type_handler_temporal_with_date ...@@ -1543,6 +1560,14 @@ class Type_handler_datetime_common: public Type_handler_temporal_with_date
{ {
return MYSQL_TIMESTAMP_DATETIME; 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; String *print_item_value(THD *thd, Item *item, String *str) const;
bool Item_hybrid_func_fix_attributes(THD *thd, Item_hybrid_func *func, bool Item_hybrid_func_fix_attributes(THD *thd, Item_hybrid_func *func,
Item **items, uint nitems) const; Item **items, uint nitems) const;
...@@ -1587,6 +1612,14 @@ class Type_handler_timestamp_common: public Type_handler_temporal_with_date ...@@ -1587,6 +1612,14 @@ class Type_handler_timestamp_common: public Type_handler_temporal_with_date
{ {
return MYSQL_TIMESTAMP_DATETIME; 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; String *print_item_value(THD *thd, Item *item, String *str) const;
bool Item_hybrid_func_fix_attributes(THD *thd, Item_hybrid_func *func, bool Item_hybrid_func_fix_attributes(THD *thd, Item_hybrid_func *func,
Item **items, uint nitems) const; Item **items, uint nitems) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment