• Nikita Malyavin's avatar
    MDEV-30902 Server crash in LEX::first_lists_tables_same · 6f78efc0
    Nikita Malyavin authored
    ONLINE ALTER TABLE uses binlog events like the replication does.
    
    Before it was never used outside of replication, so significant
    change was required. For example, a single event had a statement-like
    befavior: it locked the tables, opened it, and closed them in the end. But
    for ONLINE ALTER we use preopened table.
    
    A crash scenario is following: lex->query_tables was set to NULL in
    restore_empty_query_table_list when alter event is applied.
    Then lex->query_tables->prev_global was write-accessed in
    LEX::first_lists_tables_same, leading to a segfault.
    
    In replication restore_empty_query_table_list would mean resetting lex
    before next query or event.
    
    In ONLINE ALTER TABLE we reuse a locked table between the events, so
    we should avoid it. Here the need to reset lex state (or close the tables)
    can be determined by nonzero rgi->tables_to_lock_count.
    If no table is locked, then event doesn't own the tables.
    
    The same was already done before for rgi->slave_close_thread_tables call.
    6f78efc0
alter_table_online_debug.result 31.7 KB