There is a function
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:
- Add new methods in Type_handler:
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()