[MDEV-15597] Add class Load_data_outvar and avoid using Item::STRING_ITEM for Item_user_var_as_out_param detection Created: 2018-03-19  Updated: 2019-02-23  Resolved: 2018-03-20

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

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
blocks MDEV-12927 Allow SP variables as LOAD DATA out p... Open
blocks MDEV-14630 Replace {STRING|INT|REAL|DECIMAL|DATE... Closed

 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.



 Comments   
Comment by Alexander Barkov [ 2019-02-23 ]

Backported to 10.2.23, as a part of MDEV-18045.

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