Bug #23366 | strange error when dropping schema, Foreign Key points into another schema | ||
---|---|---|---|
Submitted: | 17 Oct 2006 11:57 | Modified: | 16 Nov 2006 15:38 |
Reporter: | Matthias Leich | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Documentation | Severity: | S1 (Critical) |
Version: | 5.0 | OS: | |
Assigned to: | Paul DuBois | CPU Architecture: | Any |
[17 Oct 2006 11:57]
Matthias Leich
[17 Oct 2006 12:00]
Matthias Leich
testscript
Attachment: n2.test (application/octet-stream, text), 1.33 KiB.
[17 Oct 2006 12:01]
Matthias Leich
Expected result
Attachment: n2.result (application/octet-stream, text), 700 bytes.
[17 Oct 2006 12:04]
Matthias Leich
The current MySQL 5.1 last ChangeSet@1.2311, 2006-10-13 show the same wrong behaviour.
[17 Oct 2006 12:49]
Heikki Tuuri
Matthias, CREATE TABLE test.t2 (f1 CHAR(3), f2 CHAR(3), FOREIGN KEY (f1) REFERENCES mysqltest.t1(f1)) ENGINE = InnoDB; why should anyone be able to drop mysqltest.t1? Then the foreign key reference is broken. Dropping mysqltest.t1 should only be possible if SET FOREIGN_KEY_CHECKS=0. Regards, Heikki
[17 Oct 2006 18:09]
Matthias Leich
Heikki, you are right that a "successful" DROP SCHEMA will cause a broken foreign key reference. Excellent, I am a fan of strict modes preventing inconsistent structures. But I have some problems with the current behaviour/MySQL manual: 1. I am relatively but not 100 % sure that this behaviour was introduced after the converted NIST tests (~ April 2005) were ready for use. If this is true, than we have an incompatible change of behaviour which should be documented. If this was probably introduced after GA (autumn 2005) than it must be documented. 2. The manual is not 100 % clear about the effect of SET FOREIGN_KEY_CHECKS=0. The impression I get from the manual is that such a setting switches the FK constraint checks during INSERT/UPDATE/DELETE off. I did not found anything about DDL. If the current behaviour (server denies DROP SCHEMA) is intended and not wrong, than we have a bug within the manual. It must be mentioned within the server variables+foreign key+ drop schema chapter that the FOREIGN_KEY_CHECKS setting affects for instance DROP SCHEMA and probably also DROP TABLE. 3. Even if we assume that the current behaviour is correct (my vote) the error message 1217: Cannot delete or update a parent row: a foreign key constraint fails is at least very questionable. I fear most customers will not have the idea that they get this server response because the server denies to damage the foreign key reference. Do you secure the "internal" referential integrity within InnoDB schemas/tables by using your foreign key feature ? If yes, very clever. Regards, Matthias
[8 Nov 2006 15:52]
Heikki Tuuri
The docs should mention that FOREIGN_KEY_CHECKS=0 also affects DDL statements. If FOREIGN_KEY_CHECKS=0 then InnoDB allows one to drop the referenced table.
[16 Nov 2006 15:38]
Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products. I've added the following paragraph to http://dev.mysql.com/doc/refman/5.0/en/set-option.html: Setting FOREIGN_KEY_CHECKS to 0 also affects data definition statements: DROP DATABASE drops a database even if it contains tables that have foreign keys that are referred to by tables outside the database, and DROP TABLE drops tables that have foreign keys that are referred to by other tables.