• Marko Mäkelä's avatar
    MDEV-15061 TRUNCATE must honor InnoDB table locks · 92d233a5
    Marko Mäkelä authored
    Traditionally, DROP TABLE and TRUNCATE TABLE discarded any locks that
    may have been held on the table. This feels like an ACID violation.
    Probably most occurrences of it were prevented by meta-data locks (MDL)
    which were introduced in MySQL 5.5.
    
    dict_table_t::n_foreign_key_checks_running: Reduce the number of
    non-debug checks.
    
    lock_remove_all_on_table(), lock_remove_all_on_table_for_trx(): Remove.
    
    ha_innobase::truncate(): Acquire an exclusive InnoDB table lock
    before proceeding. DROP TABLE and DISCARD/IMPORT were already doing
    this.
    
    row_truncate_table_for_mysql(): Convert the already started transaction
    into a dictionary operation, and do not invoke lock_remove_all_on_table().
    
    row_mysql_table_id_reassign(): Do not call lock_remove_all_on_table().
    This function is only used in ALTER TABLE...DISCARD/IMPORT TABLESPACE,
    which is already holding an exclusive InnoDB table lock.
    
    TODO: Make n_foreign_key_checks running a debug-only variable.
    This would require two fixes:
    (1) DROP TABLE: Exclusively lock the table beforehand, to prevent
    the possibility of concurrently running foreign key checks (which
    would acquire a table IS lock and then record S locks).
    (2) RENAME TABLE: Find out if n_foreign_key_checks_running>0 actually
    constitutes a potential problem.
    92d233a5
row0trunc.cc 73.3 KB