• Thirunarayanan Balathandayuthapani's avatar
    MDEV-24971 InnoDB access freed virtual column after rollback of secondary index · cf2c6b7f
    Thirunarayanan Balathandayuthapani authored
    Problem:
    ========
     InnoDB fails to clean the index stub if it fails to add the
    virtual index which contains new virtual column. But it clears
    the newly virtual column from index in clear_added_indexes()
    during inplace_alter_table. On commit, InnoDB evicts and
    reload the table. In case of rollback, it doesn't happen.
    InnoDB clears the ABORTED index while opening the table
    or doing the DDL. In the mean time, InnoDB can access
    the dropped virtual index columns while creating prebuilt
    or rollback of concurrent DML.
    
    Solution:
    ==========
    (1) InnoDB should maintain newly added virtual column while
    rollbacking the newly added virtual index.
    (2) InnoDB must not defer the index removal
    if the alter table is executed with LOCK=EXCLUSIVE.
    (3) For LOCK=SHARED, InnoDB should check whether the table
    has any other transaction lock other than alter transaction
    before deferring the index stub.
    
    Replaced has_new_v_col with dict_add_vcol_info in dict_index_t to
    indicate whether the index has any new virtual column.
    
    dict_index_t::has_new_v_col(): Returns whether the index has
    newly added virtual column, it doesn't say which columns are
    newly added virtual column
    
    ha_innobase_inplace_ctx::is_new_vcol(): Return whether the
    given column is added as a part of the current alter.
    
    ha_innobase_inplace_ctx::clean_new_vcol_index(): Copy the newly
    added virtual column to new_vcol_info in dict_index_t. Replace
    the column in the index fields with virtual column stored
    in new_vcol_info.
    
    dict_index_t::assign_new_v_col(): Store the number of virtual
    column added in index as a part of alter table.
    
    dict_index_t::get_n_new_vcol(): Get the number of newly added
    virtual column
    
    dict_index_t::assign_drop_v_col(): Allocate the memory for
    adding new virtual column in new_vcol_info.
    
    dict_index_t::add_drop_v_col(): Add the newly added virtual
    column in new_vcol_info.
    
    dict_table_t::has_lock_for_other_trx(): Whether the table has
    any other transaction lock than given transaction.
    
    row_merge_drop_indexes(): Add parameter alter_trx and check
    whether the table has any other lock than alter transaction.
    cf2c6b7f
row0merge.h 17.3 KB