![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello, I'm using an Oracle database where there are no ON DELETE CASCADE in the DDL. As a result, when you need to delete something, you have to calculate all the child tables and delete everything related there and then finally delete the parent rows. As a result, I have started to think that ON DELETE CASCADE is a good idea. Are there any drawbacks to using this when designing a database? |
#3
| |||
| |||
|
|
Hello, I'm using an Oracle database where there are no ON DELETE CASCADE in the DDL. As a result, when you need to delete something, you have to calculate all the child tables and delete everything related there and then finally delete the parent rows. As a result, I have started to think that ON DELETE CASCADE is a good idea. Are there any drawbacks to using this when designing a database? |
#4
| |||
| |||
|
|
In article<828ffbe3-14fe-49c1-a81f-5132095be443 @i31g2000yqm.googlegroups.com>, metaperl (AT) gmail (DOT) com says... Hello, I'm using an Oracle database where there are no ON DELETE CASCADE in the DDL. As a result, when you need to delete something, you have to calculate all the child tables and delete everything related there and then finally delete the parent rows. As a result, I have started to think that ON DELETE CASCADE is a good idea. Are there any drawbacks to using this when designing a database? If you've got a lot of rows in each of several tables, it can be a pretty big load on the server, and may block for quite a while while it does them all at once. If you delete from each table on its own, it's not such a performance hit. |
|
Also, NOT having deletes cascade, but still having them use a foreign key, pretty much eliminates the accidental deletion of a parent row (and thus all its thousands of child rows), because you'll get integrity violations if you try. |
#5
| ||||
| ||||
|
|
Why do you call this a "performance hit"? The single DELETE on the parent table will take longer but in sum you delete the same amount of data either way plus you have more round trips between client and DB server when doing it manually. |
|
I would rather follow Christopfer's advice to make usage of ON DELETE CASCADE dependent on the nature of the data. If there is a real whole - parts relationship and the parts must go if the whole is removed then I would use ON DELETE CASCADE because it is more robust, may be faster and also has the benefit of documenting the nature of the data. |
|
Also, NOT having deletes cascade, but still having them use a foreign key, pretty much eliminates the accidental deletion of a parent row (and thus all its thousands of child rows), because you'll get integrity violations if you try. Yes, and IMHO that is a more important aspect than performance. |
|
Kind regards robert |
#6
| |||
| |||
|
|
I'm referring to a hit on other users of the db, not the one doing the delete. If there are a lot of records to delete from many tables, it can sometimes block other users until the deletes are done. |
#7
| |||
| |||
|
|
David Kerber wrote on 13.08.2010 19:49: I'm referring to a hit on other users of the db, not the one doing the delete. If there are a lot of records to delete from many tables, it can sometimes block other users until the deletes are done. |
|
A delete should never block other users (unless they are selecting exactly those rows that are being deleted, but that would block the delete not the select). |
|
Which DBMS are you using? |
#8
| |||
| |||
|
|
In Oracle the blocking would only affect users doing UPDATE, SELECT FOR UPDATE or DELETE - and the blocking would be until the end of the transaction, not the statement! So prolonging the TX by doing more statements instead of a single DELETE may actually block others longer than with a single DELETE which cascades. |
|
A delete should never block other users (unless they are selecting exactly those rows that are being deleted, but that would block the delete not the select). In Oracle that would only block the DELETE if it was a SELECT FOR UPDATE. And blocking also works the other way round: the first TX blocks the second TX whichever of the two comes first. |
|
Which DBMS are you using? OP is using Oracle, I don't know about David. |
#9
| ||||
| ||||
|
|
In Oracle the blocking would only affect users doing UPDATE, SELECT FOR UPDATE or DELETE - and the blocking would be until the end of the transaction, not the statement! So prolonging the TX by doing more statements instead of a single DELETE may actually block others longer than with a single DELETE which cascades. But only those rows that are being deleted are (b)locked. |
|
IMHO this would be a strange business case that someone is trying to update rows that are being deleted by someone else. |
|
And if that really happens, (b)locking is the right way to handle the concurrent (and conflicting) access. |
|
A delete should never block other users (unless they are selecting exactly those rows that are being deleted, but that would block the delete not the select). In Oracle that would only block the DELETE if it was a SELECT FOR UPDATE. And blocking also works the other way round: the first TX blocks the second TX whichever of the two comes first. But again: only those rows that are affected by the DELETE (see above) are (b)locked. Which DBMS are you using? OP is using Oracle, I don't know about David. Oh, I didn't see that, thanks |
#10
| |||
| |||
|
|
The point is that David's assessment that manual deletion in multiple stages leads to shorter blocking is generally not true. |
|
IMHO this would be a strange business case that someone is trying to update rows that are being deleted by someone else. If that business case would be nonexistent we probably would not have RDBMS that support ACID properties of transactions. Point is, as this *can* happen you need a system that supports transactional integrity in some way. If not you have to deal with errors that occur from these situations yourself (as is the case with some NoSQL databases). |
|
And if that really happens, (b)locking is the right way to handle the concurrent (and conflicting) access. Absolutely! And adding to that: Oracle does it better than some other DB vendors which only recently improved their concurrency models (SQL Server comes to mind; IIRC versions up to 2000 did not handle this very gracefully). |
![]() |
| Thread Tools | |
| Display Modes | |
| |