Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-9217

Split Item::tmp_table_field_from_field_type() into virtual methods in Type_handler

    XMLWordPrintable

Details

    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().

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.