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

Wrap create_virtual_tmp_table() into a class, split into different steps




      There is a function

      create_virtual_tmp_table(THD *, List<Column_definition> &)

      which is used to handle:

      • SP variables
      • SUM(DISTINCT expr)
      • Conversion table for RBR binlog

      Notice, it accepts list of Column_definition (a parent class of Create_field).
      In case of SP variables the field descriptions are indeed stored in Column_definition format.
      However, the other two cases the field descriptions are stored in different formats:
      1. In case of SUM(DISTINCT) the field description is stored in Item. Aggregator_distinct::setup() does the following:

      • Creates a Column_definition instance from Item.
      • Puts the created Column_definition into a List.
      • Calls create_virtual_tmp_table() for the list consisting of a single field.

      2. In case of RBR conversion table the field description is collected from binlog type code with binlog metadata, and from the target field of the slave table. table_def::create_conversion_table() does the following:

      • For every field:
        • Allocates a new Column_definition instance
        • Initializes it from the binlog information (field type and metadata) and from the target field.
        • Puts the initialized Column_definition
      • Calls create_virtual_tmp_table()

      There is a lot of redundant work done. We'll do the following changes:

      • Wrap the function create_virtual_tmp_table() into a class
      • Split it into multiple methods:

        bool allocate_buffers(uint field_count);
        bool add(const Item *);
        bool add(TABLE *TABLE, uint metadata, const Field *target_field_on_slave);
        bool open();

      • Add new methods in Type_handler:

        virtual Field *make_num_distinct_aggregator_field(MEM_ROOT *, const Item *) const;
        virtual Field *make_conversion_table_field(TABLE *TABLE, uint metadata, const Field *target) const;

        This will help to:

      • Save on creating of temporary Column_definition and its List (create the table directly from the original data in Item and in binlog event)
      • Make the code look similar for built-in and pluggable data types:
        • Get rid of switch(field_type()) in Column_definition::init_for_tmp_table()
        • Get rid of the entire Column_definition::init_for_tmp_table()


          Issue Links



              bar Alexander Barkov
              bar Alexander Barkov
              0 Vote for this issue
              2 Start watching this issue



                  Git Integration