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

Add class Load_data_outvar and avoid using Item::STRING_ITEM for Item_user_var_as_out_param detection

    Details

    • Type: Task
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Fix Version/s: 10.3.6
    • Component/s: OTHER
    • Labels:
      None

      Description

      This task is a self-contained change which is going to simplify MDEV-12927 and MDEV-14630.

      Under terms of MDEV-14630 we're going to replace data-type dependent constants STRING_ITEM, INT_ITEM, REAL_ITEM, DECIMAL_ITEM, DATE_ITEM to an universal constant LITERAL_ITEM.

      In order to do it easier, we'll clean up the code in sql_load.cc not to use Item::STRING_ITEM for Item_user_var_as_out_param detection.

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

      • Introduce a new class:

        class Load_data_outvar
        {
        public:
          virtual ~Load_data_outvar() {}
          virtual bool load_data_set_null(THD *thd, const Load_data_param *param)= 0;
          virtual bool load_data_set_value(THD *thd, const char *pos, uint length,
                                           const Load_data_param *param)= 0;
          virtual bool load_data_set_no_data(THD *thd, const Load_data_param *param)= 0
          virtual void load_data_print_for_log_event(THD *thd, class String *to) const=0;
          virtual bool load_data_add_outvar(THD *thd, Load_data_param *param) const= 0;
          virtual uint load_data_field_length() const= 0;
        };
        

      • Derive Item_field and Item_user_var_as_out_param from Load_data_outvar.
      • Move Item_field- and Item_user_var_as_out_param specific pieces of the code in sql_load.cc into virtual implementations of these Load_data_outvar derived classes.

      Code blocks like this (they repeat multiple times):

            Item *real_item= item->real_item();
       
            if (item->type() == Item::STRING_ITEM)
            {
              ((Item_user_var_as_out_param *)item)->set_value((char*) pos, length,
                                                              read_info.read_charset);
            }
            else if (!real_item)
            {
              my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), item->name);
              DBUG_RETURN(1);
            }
            else
            {
              ...
              field->store((char *) tag->value.ptr(), tag->value.length(), cs);
              ...
            }
      

      will be simplified to one line:

        item->load_data_set_value(...)
      

      Additionally, replacing dangerous tests for Item::STRING_ITEM and dangerous casts to Item_user_var_as_out_param to virtual calls will remove potential bugs like MDEV-12696, when the code works fine for LOAD DATA but crashes/fails for LOAD XML.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bar Alexander Barkov
                Reporter:
                bar Alexander Barkov
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: