mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Added typedef decimal_digits_t (uint16) for number of digits in most
aspects of decimals and integers For fields and Item's uint8 should be good enough. After discussions with Alexander Barkov we choose uint16 (for now) as some format functions may accept +256 digits. The reason for this patch was to make the usage and storage of decimal digits simlar. Before this patch decimals was stored/used as uint8, int and uint. The lengths for numbers where also using a lot of different types. Changed most decimal variables and functions to use the new typedef. squash! af7f09106b6c1dc20ae8c480bff6fd22d266b184 Use decimal_digits_t for all aspects of digits (total, precision and scale), both for decimals and integers.
This commit is contained in:
@ -397,7 +397,7 @@ public:
|
||||
{
|
||||
return m_ptr ? m_ptr->to_string(to, prec, dec, filler) : NULL;
|
||||
}
|
||||
int to_binary(uchar *bin, int prec, int scale) const
|
||||
int to_binary(uchar *bin, int prec, decimal_digits_t scale) const
|
||||
{
|
||||
return (m_ptr ? m_ptr : &decimal_zero)->to_binary(bin, prec, scale);
|
||||
}
|
||||
@ -420,12 +420,13 @@ class Dec_ptr_and_buffer: public Dec_ptr
|
||||
protected:
|
||||
my_decimal m_buffer;
|
||||
public:
|
||||
/* scale is int as it can be negative here */
|
||||
int round_to(my_decimal *to, int scale, decimal_round_mode mode)
|
||||
{
|
||||
DBUG_ASSERT(m_ptr);
|
||||
return m_ptr->round_to(to, scale, mode);
|
||||
}
|
||||
int round_self(uint scale, decimal_round_mode mode)
|
||||
int round_self(decimal_digits_t scale, decimal_round_mode mode)
|
||||
{
|
||||
return round_to(&m_buffer, scale, mode);
|
||||
}
|
||||
@ -437,7 +438,7 @@ public:
|
||||
m_ptr= &m_buffer;
|
||||
return res;
|
||||
}
|
||||
String *to_string_round(String *to, uint dec)
|
||||
String *to_string_round(String *to, decimal_digits_t dec)
|
||||
{
|
||||
/*
|
||||
decimal_round() allows from==to
|
||||
@ -3048,28 +3049,27 @@ char_to_byte_length_safe(size_t char_length_arg, uint32 mbmaxlen_arg)
|
||||
return tmp > UINT_MAX32 ? (uint32) UINT_MAX32 : static_cast<uint32>(tmp);
|
||||
}
|
||||
|
||||
|
||||
class Type_numeric_attributes
|
||||
{
|
||||
public:
|
||||
static uint count_unsigned(Item **item, uint nitems);
|
||||
static uint32 find_max_char_length(Item **item, uint nitems);
|
||||
static uint32 find_max_octet_length(Item **item, uint nitems);
|
||||
static int find_max_decimal_int_part(Item **item, uint nitems);
|
||||
static uint find_max_decimals(Item **item, uint nitems);
|
||||
static decimal_digits_t find_max_decimal_int_part(Item **item, uint nitems);
|
||||
static decimal_digits_t find_max_decimals(Item **item, uint nitems);
|
||||
public:
|
||||
/*
|
||||
The maximum value length in characters multiplied by collation->mbmaxlen.
|
||||
Almost always it's the maximum value length in bytes.
|
||||
*/
|
||||
uint32 max_length;
|
||||
uint decimals;
|
||||
decimal_digits_t decimals;
|
||||
bool unsigned_flag;
|
||||
public:
|
||||
Type_numeric_attributes()
|
||||
:max_length(0), decimals(0), unsigned_flag(false)
|
||||
{ }
|
||||
Type_numeric_attributes(uint32 max_length_arg, uint decimals_arg,
|
||||
Type_numeric_attributes(uint32 max_length_arg, decimal_digits_t decimals_arg,
|
||||
bool unsigned_flag_arg)
|
||||
:max_length(max_length_arg),
|
||||
decimals(decimals_arg),
|
||||
@ -3086,9 +3086,10 @@ protected:
|
||||
class Type_temporal_attributes: public Type_numeric_attributes
|
||||
{
|
||||
public:
|
||||
Type_temporal_attributes(uint int_part_length, uint dec, bool unsigned_arg)
|
||||
Type_temporal_attributes(uint32 int_part_length, decimal_digits_t dec, bool unsigned_arg)
|
||||
:Type_numeric_attributes(int_part_length + (dec ? 1 : 0),
|
||||
MY_MIN(dec, TIME_SECOND_PART_DIGITS),
|
||||
MY_MIN(dec,
|
||||
(decimal_digits_t) TIME_SECOND_PART_DIGITS),
|
||||
unsigned_arg)
|
||||
{
|
||||
max_length+= decimals;
|
||||
@ -3099,7 +3100,7 @@ public:
|
||||
class Type_temporal_attributes_not_fixed_dec: public Type_numeric_attributes
|
||||
{
|
||||
public:
|
||||
Type_temporal_attributes_not_fixed_dec(uint32 int_part_length, uint dec,
|
||||
Type_temporal_attributes_not_fixed_dec(uint32 int_part_length, decimal_digits_t dec,
|
||||
bool unsigned_flag)
|
||||
:Type_numeric_attributes(int_part_length, dec, unsigned_flag)
|
||||
{
|
||||
@ -3154,7 +3155,7 @@ public:
|
||||
max_length= char_to_byte_length_safe(max_char_length_arg,
|
||||
collation.collation->mbmaxlen);
|
||||
}
|
||||
void fix_attributes_temporal(uint32 int_part_length, uint dec)
|
||||
void fix_attributes_temporal(uint32 int_part_length, decimal_digits_t dec)
|
||||
{
|
||||
*this= Type_std_attributes(
|
||||
Type_temporal_attributes(int_part_length, dec, false),
|
||||
@ -3164,11 +3165,11 @@ public:
|
||||
{
|
||||
fix_attributes_temporal(MAX_DATE_WIDTH, 0);
|
||||
}
|
||||
void fix_attributes_time(uint dec)
|
||||
void fix_attributes_time(decimal_digits_t dec)
|
||||
{
|
||||
fix_attributes_temporal(MIN_TIME_WIDTH, dec);
|
||||
}
|
||||
void fix_attributes_datetime(uint dec)
|
||||
void fix_attributes_datetime(decimal_digits_t dec)
|
||||
{
|
||||
fix_attributes_temporal(MAX_DATETIME_WIDTH, dec);
|
||||
}
|
||||
@ -3307,7 +3308,7 @@ public:
|
||||
virtual ~Type_all_attributes() {}
|
||||
virtual void set_maybe_null(bool maybe_null_arg)= 0;
|
||||
// Returns total number of decimal digits
|
||||
virtual uint decimal_precision() const= 0;
|
||||
virtual decimal_digits_t decimal_precision() const= 0;
|
||||
virtual const TYPELIB *get_typelib() const= 0;
|
||||
virtual void set_typelib(const TYPELIB *typelib)= 0;
|
||||
};
|
||||
@ -3458,7 +3459,7 @@ class Information_schema_numeric_attributes
|
||||
ATTR_PRECISION_AND_SCALE= (ATTR_PRECISION|ATTR_SCALE)
|
||||
};
|
||||
uint m_precision;
|
||||
uint m_scale;
|
||||
decimal_digits_t m_scale;
|
||||
enum_attr m_available_attributes;
|
||||
public:
|
||||
Information_schema_numeric_attributes()
|
||||
@ -3469,7 +3470,7 @@ public:
|
||||
:m_precision(precision), m_scale(0),
|
||||
m_available_attributes(ATTR_PRECISION)
|
||||
{ }
|
||||
Information_schema_numeric_attributes(uint precision, uint scale)
|
||||
Information_schema_numeric_attributes(uint precision, decimal_digits_t scale)
|
||||
:m_precision(precision), m_scale(scale),
|
||||
m_available_attributes(ATTR_PRECISION_AND_SCALE)
|
||||
{ }
|
||||
@ -3480,10 +3481,10 @@ public:
|
||||
DBUG_ASSERT(has_precision());
|
||||
return (uint) m_precision;
|
||||
}
|
||||
uint scale() const
|
||||
decimal_digits_t scale() const
|
||||
{
|
||||
DBUG_ASSERT(has_scale());
|
||||
return (uint) m_scale;
|
||||
return m_scale;
|
||||
}
|
||||
};
|
||||
|
||||
@ -3830,15 +3831,15 @@ public:
|
||||
virtual bool can_return_extract_source(interval_type type) const;
|
||||
virtual bool is_bool_type() const { return false; }
|
||||
virtual bool is_general_purpose_string_type() const { return false; }
|
||||
virtual uint Item_time_precision(THD *thd, Item *item) const;
|
||||
virtual uint Item_datetime_precision(THD *thd, Item *item) const;
|
||||
virtual uint Item_decimal_scale(const Item *item) const;
|
||||
virtual uint Item_decimal_precision(const Item *item) const= 0;
|
||||
virtual decimal_digits_t Item_time_precision(THD *thd, Item *item) const;
|
||||
virtual decimal_digits_t Item_datetime_precision(THD *thd, Item *item) const;
|
||||
virtual decimal_digits_t Item_decimal_scale(const Item *item) const;
|
||||
virtual decimal_digits_t Item_decimal_precision(const Item *item) const= 0;
|
||||
/*
|
||||
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;
|
||||
virtual decimal_digits_t 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.
|
||||
@ -4480,7 +4481,7 @@ public:
|
||||
}
|
||||
bool Item_eq_value(THD *thd, const Type_cmp_attributes *attr,
|
||||
Item *a, Item *b) const override;
|
||||
uint Item_decimal_precision(const Item *item) const override
|
||||
decimal_digits_t Item_decimal_precision(const Item *item) const override
|
||||
{
|
||||
DBUG_ASSERT(0);
|
||||
return DECIMAL_MAX_PRECISION;
|
||||
@ -4806,7 +4807,7 @@ public:
|
||||
bool binary_cmp) const override;
|
||||
bool Item_eq_value(THD *thd, const Type_cmp_attributes *attr,
|
||||
Item *a, Item *b) const override;
|
||||
uint Item_decimal_precision(const Item *item) const override;
|
||||
decimal_digits_t Item_decimal_precision(const Item *item) const override;
|
||||
bool Item_save_in_value(THD *thd, Item *item, st_value *value) const override;
|
||||
bool Item_param_set_from_value(THD *thd,
|
||||
Item_param *param,
|
||||
@ -4935,7 +4936,7 @@ public:
|
||||
VDec va(a), vb(b);
|
||||
return va.ptr() && vb.ptr() && !va.cmp(vb);
|
||||
}
|
||||
uint Item_decimal_precision(const Item *item) const override;
|
||||
decimal_digits_t Item_decimal_precision(const Item *item) const override;
|
||||
bool Item_save_in_value(THD *thd, Item *item, st_value *value) const override;
|
||||
void Item_param_set_param_func(Item_param *param,
|
||||
uchar **pos, ulong len) const override;
|
||||
@ -5177,7 +5178,7 @@ public:
|
||||
bool binary_cmp) const override;
|
||||
bool Item_eq_value(THD *thd, const Type_cmp_attributes *attr,
|
||||
Item *a, Item *b) const override;
|
||||
uint Item_decimal_precision(const Item *item) const override;
|
||||
decimal_digits_t Item_decimal_precision(const Item *item) const override;
|
||||
bool Item_save_in_value(THD *thd, Item *item, st_value *value) const override;
|
||||
bool Item_param_set_from_value(THD *thd,
|
||||
Item_param *param,
|
||||
@ -5263,8 +5264,8 @@ 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;
|
||||
decimal_digits_t Item_decimal_scale_with_seconds(const Item *item) const;
|
||||
decimal_digits_t Item_divisor_precision_increment_with_seconds(const Item *) const;
|
||||
public:
|
||||
Item_result result_type() const override { return STRING_RESULT; }
|
||||
Item_result cmp_type() const override { return TIME_RESULT; }
|
||||
@ -5351,7 +5352,7 @@ public:
|
||||
|
||||
class Type_handler_string_result: public Type_handler
|
||||
{
|
||||
uint Item_temporal_precision(THD *thd, Item *item, bool is_time) const;
|
||||
decimal_digits_t Item_temporal_precision(THD *thd, Item *item, bool is_time) const;
|
||||
public:
|
||||
const Name &default_value() const override;
|
||||
protocol_send_type_t protocol_send_type() const override
|
||||
@ -5411,15 +5412,15 @@ public:
|
||||
bool binary_cmp) const override;
|
||||
bool Item_eq_value(THD *thd, const Type_cmp_attributes *attr,
|
||||
Item *a, Item *b) const override;
|
||||
uint Item_time_precision(THD *thd, Item *item) const override
|
||||
decimal_digits_t Item_time_precision(THD *thd, Item *item) const override
|
||||
{
|
||||
return Item_temporal_precision(thd, item, true);
|
||||
}
|
||||
uint Item_datetime_precision(THD *thd, Item *item) const override
|
||||
decimal_digits_t Item_datetime_precision(THD *thd, Item *item) const override
|
||||
{
|
||||
return Item_temporal_precision(thd, item, false);
|
||||
}
|
||||
uint Item_decimal_precision(const Item *item) const override;
|
||||
decimal_digits_t Item_decimal_precision(const Item *item) const override;
|
||||
void Item_update_null_value(Item *item) const override;
|
||||
bool Item_save_in_value(THD *thd, Item *item, st_value *value) const override;
|
||||
void Item_param_setup_conversion(THD *thd, Item_param *) const override;
|
||||
@ -6102,12 +6103,12 @@ public:
|
||||
const override;
|
||||
bool Item_eq_value(THD *thd, const Type_cmp_attributes *attr,
|
||||
Item *a, Item *b) const override;
|
||||
uint Item_decimal_scale(const Item *item) const override
|
||||
decimal_digits_t Item_decimal_scale(const Item *item) const override
|
||||
{
|
||||
return Item_decimal_scale_with_seconds(item);
|
||||
}
|
||||
uint Item_decimal_precision(const Item *item) const override;
|
||||
uint Item_divisor_precision_increment(const Item *item) const override
|
||||
decimal_digits_t Item_decimal_precision(const Item *item) const override;
|
||||
decimal_digits_t Item_divisor_precision_increment(const Item *item) const override
|
||||
{
|
||||
return Item_divisor_precision_increment_with_seconds(item);
|
||||
}
|
||||
@ -6317,7 +6318,7 @@ public:
|
||||
void
|
||||
Column_definition_attributes_frm_pack(const Column_definition_attributes *at,
|
||||
uchar *buff) const override;
|
||||
uint Item_decimal_precision(const Item *item) const override;
|
||||
decimal_digits_t Item_decimal_precision(const Item *item) const override;
|
||||
String *print_item_value(THD *thd, Item *item, String *str) const override;
|
||||
Item_cache *Item_get_cache(THD *thd, const Item *item) const override;
|
||||
String *Item_func_min_max_val_str(Item_func_min_max *, String *) const override;
|
||||
@ -6446,12 +6447,12 @@ public:
|
||||
const uchar *buffer,
|
||||
LEX_CUSTRING *gis_options)
|
||||
const override;
|
||||
uint Item_decimal_scale(const Item *item) const override
|
||||
decimal_digits_t Item_decimal_scale(const Item *item) const override
|
||||
{
|
||||
return Item_decimal_scale_with_seconds(item);
|
||||
}
|
||||
uint Item_decimal_precision(const Item *item) const override;
|
||||
uint Item_divisor_precision_increment(const Item *item) const override
|
||||
decimal_digits_t Item_decimal_precision(const Item *item) const override;
|
||||
decimal_digits_t Item_divisor_precision_increment(const Item *item) const override
|
||||
{
|
||||
return Item_divisor_precision_increment_with_seconds(item);
|
||||
}
|
||||
@ -6608,12 +6609,12 @@ public:
|
||||
const Type_std_attributes *item,
|
||||
SORT_FIELD_ATTR *attr) const override;
|
||||
bool Column_definition_fix_attributes(Column_definition *c) const override;
|
||||
uint Item_decimal_scale(const Item *item) const override
|
||||
decimal_digits_t Item_decimal_scale(const Item *item) const override
|
||||
{
|
||||
return Item_decimal_scale_with_seconds(item);
|
||||
}
|
||||
uint Item_decimal_precision(const Item *item) const override;
|
||||
uint Item_divisor_precision_increment(const Item *item) const override
|
||||
decimal_digits_t Item_decimal_precision(const Item *item) const override;
|
||||
decimal_digits_t Item_divisor_precision_increment(const Item *item) const override
|
||||
{
|
||||
return Item_divisor_precision_increment_with_seconds(item);
|
||||
}
|
||||
|
Reference in New Issue
Block a user