• Thirunarayanan Balathandayuthapani's avatar
    MDEV-24621 In bulk insert, pre-sort and build indexes one page at a time · 045757af
    Thirunarayanan Balathandayuthapani authored
    When inserting a number of rows into an empty table,
    InnoDB will buffer and pre-sort the records for each index, and
    build the indexes one page at a time.
    
    For each index, a buffer of innodb_sort_buffer_size will be created.
    
    If the buffer ran out of memory then we will create temporary files
    for storing the data.
    
    At the end of the statement, we will sort and apply the buffered
    records. Ideally, we would do this at the end of the transaction
    or only when starting to execute a non-INSERT statement on the table.
    However, it could be awkward if duplicate keys or similar errors
    would be reported during the execution of a later statement.
    This will be addressed in MDEV-25036.
    
    Any columns longer than 2000 bytes will buffered in temporary files.
    
    innodb_prepare_commit_versioned(): Apply all bulk buffered insert
    operation, at the end of each statement.
    
    ha_commit_trans(): Handle errors from innodb_prepare_commit_versioned().
    
    row_merge_buf_write(): This function should accept blob
    file handle too and it should write the field data which are
    greater than 2000 bytes
    
    row_merge_bulk_t: Data structure to maintain the data during
    bulk insert operation.
    
    trx_mod_table_time_t::start_bulk_insert(): Notify the start of
    bulk insert operation and create new buffer for the given table
    
    trx_mod_table_time_t::add_tuple(): Buffer a record.
    
    trx_mod_table_time_t::write_bulk(): Do bulk insert operation
    present in the transaction
    
    trx_mod_table_time_t::bulk_buffer_exist(): Whether the buffer
    storage exist for the bulk transaction
    
    trx_mod_table_time_t::write_bulk(): Write all buffered insert
    operation for the transaction and the table.
    
    row_ins_clust_index_entry_low(): Insert the data into the
    bulk buffer if it is already exist.
    
    row_ins_sec_index_entry(): Insert the secondary tuple
    if the bulk buffer already exist.
    
    row_merge_bulk_buf_add(): Insert the tuple into bulk buffer
    insert operation.
    
    row_merge_buf_blob(): Write the field data whose length is
    more than 2000 bytes into blob temporary file. Write the
    file offset and length into the tuple field.
    
    row_merge_copy_blob_from_file(): Copy the blob from blob file
    handler based on reference of the given tuple.
    
    row_merge_insert_index_tuples(): Handle blob for bulk insert
    operation.
    
    row_merge_bulk_t::row_merge_bulk_t(): Constructor. Initialize
    the buffer and file for all the indexes expect fts index.
    
    row_merge_bulk_t::create_tmp_file(): Create new temporary file
    for the given index.
    
    row_merge_bulk_t::write_to_tmp_file(): Write the content from
    buffer to disk file for the given index.
    
    row_merge_bulk_t::add_tuple(): Insert the tuple into the merge
    buffer for the given index. If the memory ran out then InnoDB
    should sort the buffer and write into file.
    
    row_merge_bulk_t::write_to_index(): Do bulk insert operation
    from merge file/merge buffer for the given index
    
    row_merge_bulk_t::write_to_table(): Do bulk insert operation
    for all the indexes.
    
    dict_stats_update(): If a bulk insert transaction is in progress,
    treat the table as empty. The index creation could hold latches
    for extended amounts of time.
    045757af
handler.cc 258 KB