| 1 |
# Test for Bug 14006907 - FOREIGN KEY PROBLEMS AFTER DROP INDEX |
| 2 |
--source include/have_debug_sync.inc |
| 3 |
|
| 4 |
# Save the initial number of concurrent sessions. |
| 5 |
--source include/count_sessions.inc |
| 6 |
|
| 7 |
SET DEBUG_SYNC='RESET'; |
| 8 |
CREATE TABLE t1 (c1 INT PRIMARY KEY, c2 INT, INDEX(c2)) ENGINE = InnoDB; |
| 9 |
|
| 10 |
CREATE TABLE t2 ( |
| 11 |
c2 INT PRIMARY KEY, |
| 12 |
CONSTRAINT t2c2 FOREIGN KEY (c2) REFERENCES t1 (c2)) |
| 13 |
ENGINE = InnoDB; |
| 14 |
|
| 15 |
--error ER_DROP_INDEX_FK |
| 16 |
DROP INDEX c2 ON t1; |
| 17 |
|
| 18 |
DROP TABLE t2; |
| 19 |
|
| 20 |
SET DEBUG_SYNC = 'innodb_after_inplace_alter_table SIGNAL drop WAIT_FOR fk'; |
| 21 |
--send |
| 22 |
DROP INDEX c2 ON t1; |
| 23 |
|
| 24 |
--echo # Establish session con1 (user=root) |
| 25 |
connect (con1,localhost,root,,); |
| 26 |
--echo # Session con1 |
| 27 |
connection con1; |
| 28 |
|
| 29 |
SET DEBUG_SYNC = 'now WAIT_FOR drop'; |
| 30 |
--send |
| 31 |
CREATE TABLE t2 ( |
| 32 |
c2 INT PRIMARY KEY, |
| 33 |
CONSTRAINT t2c2 FOREIGN KEY (c2) REFERENCES t1 (c2)) |
| 34 |
ENGINE = InnoDB; |
| 35 |
|
| 36 |
--echo # Establish session con2 (user=root) |
| 37 |
connect (con2,localhost,root,,); |
| 38 |
|
| 39 |
--echo # After WL#6049 CREATE TABLE t2 must be blocked while trying |
| 40 |
--echo # to acquire exclusive metadata lock on t1. |
| 41 |
let $wait_condition= |
| 42 |
SELECT COUNT(*) = 1 FROM information_schema.processlist |
| 43 |
WHERE state = "Waiting for table metadata lock" AND |
| 44 |
info LIKE "CREATE TABLE t2 %"; |
| 45 |
--source include/wait_condition.inc |
| 46 |
|
| 47 |
SET DEBUG_SYNC = 'now SIGNAL fk'; |
| 48 |
disconnect con2; |
| 49 |
|
| 50 |
--echo # Switching to connection con1. |
| 51 |
connection con1; |
| 52 |
|
| 53 |
--echo # So no chance for CREATE TABLE t2 to sneak before DROP INDEX |
| 54 |
--echo # is committed in and succeed. |
| 55 |
--echo /* reap */ CREATE TABLE t2 ... |
| 56 |
--error ER_FK_NO_INDEX_PARENT |
| 57 |
--reap |
| 58 |
disconnect con1; |
| 59 |
|
| 60 |
--echo # Session default |
| 61 |
connection default; |
| 62 |
--echo /* reap */ DROP INDEX c2 ON t1; |
| 63 |
reap; |
| 64 |
|
| 65 |
--error ER_FK_NO_INDEX_PARENT |
| 66 |
CREATE TABLE t2 ( |
| 67 |
c2 INT PRIMARY KEY, |
| 68 |
CONSTRAINT t2c2 FOREIGN KEY (c2) REFERENCES t1 (c2)) |
| 69 |
ENGINE = InnoDB; |
| 70 |
|
| 71 |
SET DEBUG_SYNC='RESET'; |
| 72 |
DROP TABLE t1; |
| 73 |
|
| 74 |
# Check that all connections opened by test cases in this file are really |
| 75 |
# gone so execution of other tests won't be affected by their presence. |
| 76 |
--source include/wait_until_count_sessions.inc |