Bug #57768 | FOREIGN KEY ON UPDATE CASCADE does not work with self-reference | ||
---|---|---|---|
Submitted: | 27 Oct 2010 11:58 | Modified: | 29 Oct 2010 5:00 |
Reporter: | Luca Esculapio | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S2 (Serious) |
Version: | 5.1.41 | OS: | Windows (Win 7) |
Assigned to: | CPU Architecture: | Any | |
Tags: | foreign key on update cascade self-reference |
[27 Oct 2010 11:58]
Luca Esculapio
[27 Oct 2010 12:33]
MySQL Verification Team
See bug: http://bugs.mysql.com/bug.php?id=47417.
[27 Oct 2010 12:50]
Valeriy Kravchuk
Doesn't our manual (http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html) explain this: "Deviation from SQL standards: If ON UPDATE CASCADE or ON UPDATE SET NULL recurses to update the same table it has previously updated during the cascade, it acts like RESTRICT. This means that you cannot use self-referential ON UPDATE CASCADE or ON UPDATE SET NULL operations. This is to prevent infinite loops resulting from cascaded updates. A self-referential ON DELETE SET NULL, on the other hand, is possible, as is a self-referential ON DELETE CASCADE."
[27 Oct 2010 21:58]
Luca Esculapio
Dear Miguel and Valeriy, you're right. Your replies have been perfectly accurate and exceptionally fast. Thanks a lot for your kindness. I apologize for not consulting http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html carefully enough and thus being time-consuming. As to the seriousness of the issue, well.. on one hand, to worsen my position even more, I cannot see the recursion, though: if in my example I could update the id field of a parent row and this would cause the update of the parent_id field of its child rows, it seems to me the action would stop there. On the other hand, I was about to ask you if you think this point may be overcome, but anyway I think it can be handled in the application that's using MySQL. So I apologize and thank you a lot again. Very Best Luca Esculapio
[27 Oct 2010 21:59]
Luca Esculapio
Dear Miguel and Valeriy, you're right. Your replies have been perfectly accurate and exceptionally fast. Thanks a lot for your kindness. I apologize for not consulting http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html carefully enough and thus being time-consuming. As to the seriousness of the issue, well.. on one hand, to worsen my position even more, I cannot see the recursion, though: if in my example I could update the id field of a parent row and this would cause the update of the parent_id field of its child rows, it seems to me the action would stop there. On the other hand, do you agree that being able to have fully functional parent and child records within the same table would be a valuable feature? Then I was about to ask you if you think this point may be overcome, but I came to think it may be handled in the application that's using MySQL. Anyway, I apologize and thank you a lot again. Very Best Luca Esculapio