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

Split Item_sum::create_tmp_field() into virtual methods in Type_handler

    XMLWordPrintable

Details

    • Task
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • Data types
    • None

    Description

      It seems we need a new method in Type_handler, like this:

      virtual const *Type_handler tmp_table_handler(const Type_std_attributes&,
                                                    const Type_ext_attrubutes) const;
      

      The logic for the traditional Item types is hard coded in Item::create_tmp_field() in the switch by cmp_type(). It performs conversion to a super-type which has the same cmp_type(), with a special code for GEOMETRY.

      Note, conversion to a super-type can often be excessive. For example, for INT-alike types we create Field_long or Field_longlong. But under certain circumstances smaller types should be enough (e.g. when the result is not exposed as a field of a permanent table). An additional "what_for" parameter will possibly be needed for tmp_table_handler().

      For example, if data type of "this" is MYSQL_TYPE_SHORT, and the field is needed only for internal purposes and is know not to overflow, we could create Field_short instead of Field_long.

      In order to do this, the code needs to be fixed first to make sure that type_handler()/field_type() are always in sync with max_length for all Item types, which now is not always true.

      Update

      After this commit:

      commit 109bc47084c72164130fc2e735ffe371713ede43
      Date:   Thu May 25 15:15:39 2017 +0400
          Fixing a few data type related problems: MDEV-12875, MDEV-12886, MDEV-12916
          This is a joint patch fixing the following problems: 
          MDEV-12875 Wrong VIEW column data type for COALESCE(int_column)
          MDEV-12886 Different default for INT and BIGINT column in a VIEW for a SELECT with ROLLUP
          MDEV-12916 Wrong column data type for an INT field of a cursor-anchored ROW variable
      

      this code was moved from Item::create_tmp_field() to Item_sum::create_tmp_field().

      So this task becomes lower priority, because only numeric data types are now affected.
      Adding string-alike data types like INET6 and UUID do not seem to need this change.

      Update#2

      As of 2018-06-19, the code of the subject looks like this:

      Field *Item_sum::create_tmp_field(bool group, TABLE *table)
      {
        Field *UNINIT_VAR(new_field);
        MEM_ROOT *mem_root= table->in_use->mem_root;
       
        switch (cmp_type()) {
        case REAL_RESULT:
        {
          new_field= new (mem_root)
            Field_double(max_char_length(), maybe_null, &name, decimals, TRUE);
          break;
        }
        case INT_RESULT:
        case TIME_RESULT:
        case DECIMAL_RESULT:
        case STRING_RESULT:
          new_field= tmp_table_field_from_field_type(table);
          break;
        case ROW_RESULT:
          // This case should never be choosen
          DBUG_ASSERT(0);
          new_field= 0;
          break;
        }
        if (new_field)
          new_field->init(table);
        return new_field;
      }
      

      There is no special GEOMETRY code any more.
      There is only a piece of special code for REAL_RESULT.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:

              Git Integration

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