TOI during FK update fails: Error on rename of .. Table is being used in foreign key check

Bug #1381954 reported by Philip Stoev
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MySQL patches by Codership
New
Undecided
Unassigned

Bug Description

The test below performs ALTER ADD FOREIGN KEY while a concurrent UPDATE is running. TOI then fails on the node running the UPDATE:

2014-10-16 11:58:10 7fbd596be700 InnoDB: Error: in ALTER TABLE `test`.`#sql-1a99_1`
InnoDB: a FOREIGN KEY check is running.
InnoDB: Cannot rename table.
2014-10-16 11:58:10 7fbd596be700 InnoDB: You are trying to drop table `test`.`#sql-1a99_1`
InnoDB: though there is a foreign key check running on it.
InnoDB: Adding the table to the background drop queue.
2014-10-16 11:58:10 6809 [ERROR] Slave SQL: Error 'Error on rename of './test/#sql-1a99_1' to './test/child' (errno: 183 - Table is being used in foreign key check)' on query. Default database: 'test'. Query: 'ALTER TABLE child ADD FOREIGN KEY (parent_id) REFERENCES parent(id) ON UPDATE CASCADE', Error_code: 1025
2014-10-16 11:58:10 6809 [Warning] WSREP: RBR event 1 Query apply warning: 1, 7
2014-10-16 11:58:10 6809 [Warning] WSREP: Ignoring error for TO isolated action: source: 735e0b4e-5512-11e4-873a-4a70a6795b38 version: 3 local: 0 state: APPLYING flags: 65 conn_id: 7 trx_id: -1 seqnos (l: 11, g: 7, s: 6, d: 6, ts: 130859876172930)
2014-10-16 11:58:39 7fbd3bdf2700 InnoDB: Dropped table "test"."#sql-1a99_1" in background drop queue.

Test :

--source include/big_test.inc
--source include/galera_cluster.inc
--source include/have_innodb.inc

#
# This test creates a new FK constraint while an UPDATE is running
#

CREATE TABLE ten (f1 INTEGER) ENGINE=InnoDB;
INSERT INTO ten VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);

CREATE TABLE parent (
    id INT PRIMARY KEY,
    KEY (id)
) ENGINE=InnoDB;

CREATE TABLE child (
    id INT PRIMARY KEY AUTO_INCREMENT,
    parent_id INT
) ENGINE=InnoDB;

INSERT INTO parent VALUES (1);

INSERT INTO child (parent_id) SELECT 1 FROM ten AS a1, ten AS a2, ten AS a3, ten AS a4, ten AS a5;

--connection node_1
--sleep 1
--send ALTER TABLE child ADD FOREIGN KEY (parent_id) REFERENCES parent(id) ON UPDATE CASCADE;

--connection node_2
--send UPDATE parent SET id = 2 WHERE id = 1;

--connection node_1
--reap

--connection node_2
--reap

--connection node_2
SELECT COUNT(*) = 100000 FROM child WHERE parent_id = 2;

--connection node_1
SELECT COUNT(*) = 100000 FROM child WHERE parent_id = 2;

DROP TABLE child;
DROP TABLE parent;

DROP TABLE ten;

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.