Bug #61515 | slow drop foreign key | ||
---|---|---|---|
Submitted: | 14 Jun 2011 16:32 | Modified: | 11 Jul 2013 5:33 |
Reporter: | Cyril SCETBON | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: InnoDB Plugin storage engine | Severity: | S4 (Feature request) |
Version: | 5.5.9 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | alter, Drop, fk, slow |
[14 Jun 2011 16:32]
Cyril SCETBON
[14 Jun 2011 16:45]
Cyril SCETBON
here is a way to reproduce it : CREATE TABLE `t7` ( `id` int(11) NOT NULL AUTO_INCREMENT, `c` char(255) DEFAULT NULL, PRIMARY KEY (`id`), KEY `c` (`c`) ) ENGINE=InnoDB; CREATE TABLE `t8` ( `id` int(11) NOT NULL AUTO_INCREMENT, `c` char(255) DEFAULT NULL, PRIMARY KEY (`id`), KEY `c` (`c`), CONSTRAINT `fk1` FOREIGN KEY (`c`) REFERENCES `t7` (`c`) ON UPDATE CASCADE ) ENGINE=InnoDB; insert into t7(c) values('c'); insert into t8(c) values('c'); insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; insert into t8(c) select c from t8; alter table t8 drop foreign key fk1; when doing the alter table, "show processlist" shows : +----+------+-----------+------+---------+------+-------------------+-------------------------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+------+---------+------+-------------------+-------------------------------------+ | 20 | root | localhost | test | Query | 1 | copy to tmp table | alter table t8 drop foreign key fk1 |
[15 Jun 2011 9:14]
Valeriy Kravchuk
I think this is a clearly documented limitation. Check http://dev.mysql.com/doc/refman/5.5/en/innodb-create-index-limitations.html, please: "MySQL 5.5 does not support efficient creation or dropping of FOREIGN KEY constraints. Therefore, if you use ALTER TABLE to add or remove a REFERENCES constraint, the child table is copied, rather than using Fast Index Creation."
[15 Jun 2011 12:31]
Cyril SCETBON
You're right Valeriy, I missed it in the documentation :( It's really disappointing that removing a constraint needs to recreate my 10GB table ....
[15 Jun 2011 13:59]
Valeriy Kravchuk
Yes, that's unfortunate, but prevents some bugs...
[7 Dec 2011 15:03]
Arnaud Adant
Adding and dropping FK constraints is way too slow. 6 hours for a 16G table when no data is modified / changed in the base table. InnoDB should be smarter than that.
[7 Dec 2011 15:04]
Arnaud Adant
set to FR, verified
[10 May 2012 22:07]
Bogdan Yurov
Any fix?
[11 May 2012 18:57]
Arnaud Adant
The problem is being addressed. Although I can not communicate on future release calendar, it should be solved in 5.6 or later.
[14 May 2012 9:00]
Cyril SCETBON
great news !
[8 Jul 2013 5:53]
Jimmy Yang
This issue should be addressed in latest 5.6 release with new online alter interface. The drop FK no longer require table rebuild
[8 Jul 2013 13:36]
Cyril Scetbon
I like it :)