[MDEV-17440] ON DELETE CASCADE does not always delete rows even if it could Created: 2018-10-12 Updated: 2023-10-08 |
|
| Status: | Confirmed |
| Project: | MariaDB Server |
| Component/s: | Data Manipulation - Delete, Storage Engine - InnoDB |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2, 10.3 |
| Fix Version/s: | 10.4 |
| Type: | Bug | Priority: | Minor |
| Reporter: | Renat Golubchyk | Assignee: | Aleksey Midenkov |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | foreign-keys | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
When defining foreign key constraints with ON DELETE clauses it is possible to create a situation where MariaDB does not automatically delete data even if it could. This forces the user to perform the deletion manually. Consider following example:
Both tables b and c reference a. Deletions from b get rejected because of the foreign key in c. When deleting a row from a it also gets rejected, because the first dependent row to be deleted is in b and deletions from b are rejected. But this is not the only order in which referencing rows can be deleted. If MariaDB would first delete the row in c then the row in b also could be deleted. So it seems MariaDB processes the keys depth-first. In this case breadth-first would have been better. But it wouldn't always work. The best algorithm would be probably to build a dependency graph and then delete those rows first that don't have dependencies. Then dependent rows, then their dependents and so no. Circular references would probably stop the whole process, and the deletion would be rejected. |