[MDEV-9217] Split Item::tmp_table_field_from_field_type() into virtual methods in Type_handler Created: 2015-12-01  Updated: 2017-05-17  Resolved: 2017-04-24

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Fix Version/s: 10.3.1

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

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed
Relates
relates to MDEV-9218 Add a helper class Record_addr Closed

 Description   

Currently Item::tmp_table_field_from_field_type() has this code:

  switch (field_type()) {
  case MYSQL_TYPE_DECIMAL:
  case MYSQL_TYPE_NEWDECIMAL:
  ...
  case MYSQL_TYPE_TINY:
  ...
  case MYSQL_TYPE_SHORT:
  ...

This is not friendly to pluggable data types.

We'll introduce a new method in Type_handler:

virtual Field *make_table_field(const LEX_CSTRING *name,
                                const Record_addr &addr,
                                const Type_all_attributes &attr,
                                TABLE *table) const= 0;

and move all switch pieces into implementations of make_table_field of the corresponding Type_handler_xxx.

Note, the new method for now will be used to create only fields for temporary tables, but later we'll reuse it for make_field() purposes in field.cc. Therefore, the API for the new method contains a new class Record_addr which describes pointer and null-pointer of this field in the record.

class Record_addr
{
public:
  uchar *ptr;      // Position to field in record
  /**
     Byte where the @c NULL bit is stored inside a record. If this Field is a
     @c NOT @c NULL field, this member is @c NULL.
  */
  uchar *null_ptr;
  uchar null_bit;  // Bit used to test null bit
  Record_addr(uchar *ptr_arg,
              uchar *null_ptr_arg,
              uchar null_bit_arg)
   :ptr(ptr_arg),
    null_ptr(null_ptr_arg),
    null_bit(null_bit_arg)
  { }
  Record_addr(bool maybe_null)
   :ptr(NULL),
    null_ptr(maybe_null ? (uchar*) "" : 0),
    null_bit(0)
  { }
};

Additionally we'll remove the fixed_length and set_blob_packlength parameters from Item::tmp_table_field_from_field_type.
Reproducing these parameters in the new method make_table_field would look too dirty.

Removing fixed_length is easy: it's not really used, the code checking fixed_length in Item::tmp_table_field_from_field_type is dead code.

Removing set_blob_packlength is less trivial. This parameter was needed to choose a proper blob type handler (type_handler_blob, type_handler_tiny_blob, type_handler_medium_blob, type_handler_long_blob) depending on max_length. So instead of choosing the exact data type during tmp_table_field_from_type(), we'll fix all affected Item_xxx::type_handler() to return a correct type handler, which is in sync with max_length. Some Item_xxx will need to fix type_handler() or field_type(), other will need to fix fix_length_and_dec().



 Comments   
Comment by Oleksandr Byelkin [ 2017-04-24 ]

OK to push after changing the constant and running all tests.

Generated at Thu Feb 08 07:33:01 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.