| 1 |
SET DEBUG_SYNC='RESET'; |
| 2 |
CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT, INDEX(c2)) ENGINE = InnoDB; |
| 3 |
CREATE TABLE t2 ( |
| 4 |
c2 INT PRIMARY KEY, |
| 5 |
CONSTRAINT t2c2 FOREIGN KEY (c2) REFERENCES t1 (c2)) |
| 6 |
ENGINE = InnoDB; |
| 7 |
DROP INDEX c2 ON t1; |
| 8 |
ERROR HY000: Cannot drop index 'c2': needed in a foreign key constraint |
| 9 |
DROP TABLE t2; |
| 10 |
SET DEBUG_SYNC = 'innodb_after_inplace_alter_table SIGNAL drop WAIT_FOR fk'; |
| 11 |
DROP INDEX c2 ON t1; |
| 12 |
# Establish session con1 (user=root) |
| 13 |
# Session con1 |
| 14 |
SET DEBUG_SYNC = 'now WAIT_FOR drop'; |
| 15 |
CREATE TABLE t2 ( |
| 16 |
c2 INT PRIMARY KEY, |
| 17 |
CONSTRAINT t2c2 FOREIGN KEY (c2) REFERENCES t1 (c2)) |
| 18 |
ENGINE = InnoDB; |
| 19 |
# Establish session con2 (user=root) |
| 20 |
# After WL#6049 CREATE TABLE t2 must be blocked while trying |
| 21 |
# to acquire exclusive metadata lock on t1. |
| 22 |
SET DEBUG_SYNC = 'now SIGNAL fk'; |
| 23 |
# Switching to connection con1. |
| 24 |
# So no chance for CREATE TABLE t2 to sneak before DROP INDEX |
| 25 |
# is committed in and succeed. |
| 26 |
/* reap */ CREATE TABLE t2 ... |
| 27 |
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 't2c2' in the referenced table 't1' |
| 28 |
# Session default |
| 29 |
/* reap */ DROP INDEX c2 ON t1; |
| 30 |
CREATE TABLE t2 ( |
| 31 |
c2 INT PRIMARY KEY, |
| 32 |
CONSTRAINT t2c2 FOREIGN KEY (c2) REFERENCES t1 (c2)) |
| 33 |
ENGINE = InnoDB; |
| 34 |
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 't2c2' in the referenced table 't1' |
| 35 |
SET DEBUG_SYNC='RESET'; |
| 36 |
DROP TABLE t1; |