• Marko Mäkelä's avatar
    MDEV-14585 Automatically remove #sql- tables in InnoDB dictionary during recovery · 73ed19e4
    Marko Mäkelä authored
    This is a backport of the following commits:
    commit b4165985
    commit 69e88de0
    commit 40f4525f
    commit 656f66de
    
    Now that MDEV-14717 made RENAME TABLE crash-safe within InnoDB,
    it should be safe to drop the #sql- tables within InnoDB during
    crash recovery. These tables can be one of two things:
    
    (1) #sql-ib related to deferred DROP TABLE (follow-up to MDEV-13407)
    or to table-rebuilding ALTER TABLE...ALGORITHM=INPLACE
    (since MDEV-14378, only related to the intermediate copy of a table),
    
    (2) #sql- related to the intermediate copy of a table during
    ALTER TABLE...ALGORITHM=COPY
    
    We will not drop tables whose name starts with #sql2, because
    the server can be killed during an ALGORITHM=COPY operation at
    a point where the original table was renamed to #sql2 but the
    finished intermediate copy was not yet renamed from #sql-
    to the original table name.
    
    If an old version of MariaDB Server before 10.2.13 (MDEV-11415)
    was killed while ALTER TABLE...ALGORITHM=COPY was in progress,
    after recovery there could be undo log records for some records that were
    inserted into an intermediate copy of the table. Due to these undo log
    records, InnoDB would resurrect locks at recovery, and the intermediate
    table would be locked while we are trying to drop it. This would cause
    a call to row_rename_table_for_mysql(), either from
    row_mysql_drop_garbage_tables() or from the rollback of a RENAME
    operation that was part of the ALTER TABLE.
    
    row_rename_table_for_mysql(): Do not attempt to parse FOREIGN KEY
    constraints when renaming from #sql-something to #sql-something-else,
    because it does not make any sense.
    
    row_drop_table_for_mysql(): When deferring DROP TABLE due to locks,
    do not rename the table if its name already starts with the #sql-
    prefix, which is what row_mysql_drop_garbage_tables() uses.
    Previously, the too strict prefix #sql-ib was used, and some
    tables were renamed unnecessarily.
    73ed19e4
truncate_crash.result 341 Bytes