• Marko Mäkelä's avatar
    MDEV-17938 ALTER TABLE reports ER_TABLESPACE_EXISTS after failed ALTER TABLE · 0d7cf06a
    Marko Mäkelä authored
    There was a race condition in the error handling of ALTER TABLE when
    the table contains FULLTEXT INDEX.
    
    During the error handling of an erroneous ALTER TABLE statement,
    when InnoDB would drop the internally created tables for FULLTEXT INDEX,
    it could happen that one of the hidden tables was being concurrently
    accessed by a background thread. Because of this, InnoDB would defer
    the drop operation to the background.
    
    However, related to MDEV-13564 backup-safe TRUNCATE TABLE and its
    prerequisite MDEV-14585, we had to make the background drop table queue
    crash-safe by renaming the table to a temporary name before enqueueing it.
    This renaming was introduced in a follow-up of the MDEV-13407 fix.
    As part of this rename operation, we were unnecessarily parsing the
    current SQL statement, because the same rename operation could also be
    executed as part of ALTER TABLE via ha_innobase::rename_table().
    
    If an ALTER TABLE statement was being refused due to incorrectly formed
    FOREIGN KEY constraint, then it could happen that the renaming of the hidden
    internal tables for FULLTEXT INDEX could also fail, triggering a host of
    error log messages, and causing a subsequent table-rebuilding ALTER TABLE
    operation to fail due to the tablespace already existing.
    
    innobase_rename_table(), row_rename_table_for_mysql(): Add the parameter
    use_fk for suppressing the parsing of FOREIGN KEY constraints. It
    will only be passed as use_fk=true by ha_innobase::rename_table(),
    which can be invoked as part of ALTER TABLE...ALGORITHM=COPY.
    0d7cf06a
ha_innodb.cc 635 KB