[MDEV-12833] Split Column_definition::create_length_to_internal_length() to virtual methods in Type_handler Created: 2017-05-17  Updated: 2017-05-17  Resolved: 2017-05-17

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: None

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed
Relates
relates to MDEV-9397 Split field.cc:calc_pack_length() int... Closed

 Description   

This code is not friendly to pluggable data types:

void Column_definition::create_length_to_internal_length(void)
{
  switch (real_field_type()) {
  case MYSQL_TYPE_TINY_BLOB:
  ...
  }
}

As of MDEV creation time, the only place where create_length_to_internal_length() is used (see bb-10.2-ext and 10.3 branches) is a loop inside mysql_prepare_create_table():

/* Check if we have used the same field name before */
for (dup_no=0; (dup_field=it2++) != sql_field; dup_no++)
{
...
    if (!(sql_field->flags & NOT_NULL_FLAG))
      null_fields--;
    sql_field->flags=             dup_field->flags;
    sql_field->create_length_to_internal_length();
    sql_field->interval=          dup_field->interval;
    sql_field->vcol_info=         dup_field->vcol_info;
...
}

This code is responsible for queries like this:

CREATE TABLE t2 (a INT) AS SELECT a FROM t1;

I.e. t1.a is queried, but its data type is redefined.

Under terms of this task we'll do the following:

  • Introduce a new virtual method in Type_handler:

    virtual bool Column_definition_redefine_stage1(Column_definition *def,
                                                   const Column_definition *dup,
                                                   const handler *file,
                                                   const Schema_specification_st *)
                                                   const;
    

  • Move the entire redefinition code (responsible for copying members from dup_field to sql_field):
  • Data type independent code will go into a shared method Column_definition::redefine_stage1_common()
  • Data type specific code will go to relevant virtual implementations of Column_definition_redefine_stage1. Every implementation will include a call for redefine_stage1_common() followed by data specific code. For example, the method responsible for handling DECIMAL, will look like:

    bool Type_handler_newdecimal::
           Column_definition_redefine_stage1(Column_definition *def,
                                             const Column_definition *dup,
                                             const handler *file,
                                             const Schema_specification_st *schema)
                                             const
    {
      def->redefine_stage1_common(dup, file, schema);
      def->create_length_to_internal_length_newdecimal();
      return false;
    }
    

  • Remove Column_definition::create_length_to_internal_length()


 Comments   
Comment by Alexander Barkov [ 2017-05-17 ]

Pushed to bb-10.2-ext

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