pt-online-schema-change dropping FK limitation isn't documented
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Percona Toolkit moved to https://jira.percona.com/projects/PT |
Fix Released
|
Medium
|
Daniel Nichter |
Bug Description
Using pt-online-
Dropping a foreign key constraint fails, probably due to the change in 2.1 that moves away from CREATE TABLE LIKE, in favor of recreating the new table explicitly with renamed FK constraints.
(Docs say, "Due to a limitation in MySQL, foreign keys will not have the same names after the ALTER that they did prior to it. The tool has to rename the foreign key when it redefines it, which adds a leading underscore to the name.")
# Steps to reproduce:
CREATE DATABASE osc_fk_testing;
use osc_fk_testing;
CREATE TABLE `foo` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
);
CREATE TABLE `bar` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`foo_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
CONSTRAINT `foo_ibfk_1` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`)
);
INSERT INTO `foo` VALUES(1), (2), (3), (4), (5);
INSERT INTO `bar` (foo_id) VALUES(1), (2), (3), (4);
pt-online-
# Result:
Altering `osc_fk_
Creating new table...
CREATE TABLE `osc_fk_
`id` int(11) NOT NULL AUTO_INCREMENT,
`foo_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `foo_ibfk_1` (`foo_id`),
CONSTRAINT `_foo_ibfk_1` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
Created new table osc_fk_
Altering new table...
ALTER TABLE `osc_fk_
Dropping new table...
DROP TABLE IF EXISTS `osc_fk_
Dropped new table OK.
`osc_fk_
Error altering new table `osc_fk_
Expected result:
pt-online-schema changes uses the modified name of the new constraint (`_foo_ibfk_1`) when modifying the new table, and the constraint is removed successfully.
MySQL: 5.5.12, on Amazon RDS.
Related branches
- Daniel Nichter: Approve
-
Diff: 21 lines (+11/-0)1 file modifiedbin/pt-online-schema-change (+11/-0)
tags: | added: crash mysql-5.5 pt-online-schema-change |
Changed in percona-toolkit: | |
status: | New → Triaged |
Changed in percona-toolkit: | |
milestone: | none → 2.1.4 |
importance: | Undecided → Medium |
Changed in percona-toolkit: | |
assignee: | nobody → Daniel Nichter (daniel-nichter) |
summary: |
- pt-online-schema-change can't drop foreign key constraints + pt-online-schema-change dropping FK limitation isn't documented |
tags: |
added: foreign-keys removed: mysql-5.5 |
Changed in percona-toolkit: | |
status: | Triaged → Fix Committed |
Changed in percona-toolkit: | |
status: | Fix Committed → Fix Released |
I think we will need to 'fix' this one by documenting it, because we don't parse the ALTER statement, so we don't know its contents. The documentation can mention that the user should modify the DROP FOREIGN KEY clause to refer to the key's modified name.