MySQL Forums
Forum List  »  Optimizer & Parser

Table reordering of multi-table DELETE
Posted by: Saverio Miroddi
Date: May 26, 2009 03:43PM

I have to delete records from some tables in parent-child relationship, with the constraint that the tables can't have the ON DELETE CASCADE option.

The reference of MySQL 5.0 clearly states that the query optimizer is free to reorder the tables, so that the behavior of deletion of parents and children is not deterministic:

DELETE c.*, p.*
FROM children c JOIN parents p ON p.id = c.parent_id
WHERE p.attribute = 'aaa'

this query could delete from table_b, leaving orphans in table_a.

But here's the catch.
DELETE accepts STRAIGHT JOINs, which are guaranteed to access the tables in the given order.
But even if I use them:

DELETE c.*, p.*
FROM children c STRAIGHT JOIN parents p ON p.id = c.parent_id
WHERE p.attribute = 'aaa'

The behavior is still non-deterministic.

Is this a bug?

The real query I used had 5 joined tables.



Edited 2 time(s). Last edit at 05/27/2009 02:11AM by Saverio Miroddi.

Options: ReplyQuote


Subject
Views
Written By
Posted
Table reordering of multi-table DELETE
4082
May 26, 2009 03:43PM


Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.