[MDEV-20331] Add class Type_numeric_attributes Created: 2019-08-12  Updated: 2019-08-12  Resolved: 2019-08-12

Status: Closed
Project: MariaDB Server
Component/s: Data types
Fix Version/s: 10.5.0

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None


 Description   

We should eventually remove DTCollation from non-string items, as it's always initialized to DTCollation_numeric() and therefore wastes memory.

As a step to this, let's move the following members from Type_std_attributes:

  • max_length
  • decimals
  • unsigned_flag

into a new class Type_numeric_attributes and derive Type_std_attributes from it.

Let's also add a new virtual method in Field:

virtual Type_numeric_attributes type_numeric_attributes() const;

and turn Field::type_std_attributes() from a virtual to a non-virtual method like this:

  Type_std_attributes type_std_attributes() const
  {
    return Type_std_attributes(type_numeric_attributes(), dtcollation());
  }

All former Type_std_attributes methods that operate on only the moved members should also move to class Type_numeric_attributes.

As a result, the classes will look about like this:

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);
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;
  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,
                          bool unsigned_flag_arg)
   :max_length(max_length_arg),
    decimals(decimals_arg),
    unsigned_flag(unsigned_flag_arg)
  { }
protected:
  void aggregate_numeric_attributes_real(Item **item, uint nitems);
  void aggregate_numeric_attributes_decimal(Item **item, uint nitems,
                                            bool unsigned_arg);
};

class Type_std_attributes: public Type_numeric_attributes
{
public:
  DTCollation collation;
  Type_std_attributes()
   :collation(&my_charset_bin, DERIVATION_COERCIBLE)
  { }
  Type_std_attributes(const Type_numeric_attributes &nattr,
                      const DTCollation &dtc)
   :Type_numeric_attributes(nattr), collation(dtc)
  { }
  ...
};


Generated at Thu Feb 08 08:58:39 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.