mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-17595 - ALTER TABLE ADD FOREIGN KEY crash
ALTER TABLE ... ADD FOREIGN KEY may trigger assertion failure when it has LOCK=EXCLUSIVE clause or concurrent FLUSH TABLES is being executed. In both cases being altered table is marked as flushed, which forces subsequent attempt to open parent table to re-open. Which in turn is not allowed while transaction is running. Rather than opening parent table, just take appropriate MDL lock. Also removed table_already_fk_prelocked() check: MDL itself has much better methods to handle duplicate locks. E.g. the former won't acquire MDL_SHARED_NO_WRITE if it already has MDL_SHARED_READ.
This commit is contained in:
@ -87,3 +87,16 @@ drop table t3;
|
||||
drop table t2;
|
||||
drop table t1;
|
||||
set debug_sync='reset';
|
||||
#
|
||||
# MDEV-17595 - Server crashes in copy_data_between_tables or
|
||||
# Assertion `thd->transaction.stmt.is_empty() ||
|
||||
# (thd->state_flags & Open_tables_state::BACKUPS_AVAIL)'
|
||||
# fails in close_tables_for_reopen upon concurrent
|
||||
# ALTER TABLE and FLUSH
|
||||
#
|
||||
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=InnoDB;
|
||||
INSERT INTO t1 VALUES(1),(2);
|
||||
CREATE TABLE t2 (b INT, KEY(b)) ENGINE=InnoDB;
|
||||
INSERT INTO t2 VALUES(2);
|
||||
ALTER TABLE t2 ADD FOREIGN KEY(b) REFERENCES t1(a), LOCK=EXCLUSIVE;
|
||||
DROP TABLE t2, t1;
|
||||
|
Reference in New Issue
Block a user