[MDEV-9238] Wrap create_virtual_tmp_table() into a class, split into different steps Created: 2015-12-04  Updated: 2019-04-23  Resolved: 2015-12-04

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

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: refactoring

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed
Duplicate
is duplicated by MDEV-9211 Split Column_definition::init_for_tmp... Closed
Relates
relates to MDEV-12416 OOM in create_virtual_tmp_table() mak... Closed

 Description   

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()

Generated at Thu Feb 08 07:33:10 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.