How to speed up deleting rows, when there are child tables?

Posted on 2013-06-11
Medium Priority
Last Modified: 2013-06-13

I want to delete nearly 9000 rows from a table of 4 million rows.

The table is having two child tables.
The table is having primary key.
primary key is used when deleting.

I tried the following, but still it is taking 3 hours
Forall statement.
Delete using ROWID.

Please let me know is there any other  general approach, I can try.

If you want I want, I can post more details tomorrow.
Question by:sakthikumar
LVL 74

Expert Comment

ID: 39239024
How many total rows are you deleting?  parent + child?

Based on 9000/4000000,  that's should be quick.
Less than a minute even with full table scans.

Any triggers firing?

And the most likely cause - any blocking locks from other sessions on the parent or any of the children?
LVL 35

Expert Comment

ID: 39239087
I assume you have cascading constraints.  If that is the case, don't use the constraints to do the deletes of the child tables.  Delete them yourself.  Locking down the parent child tree and then deleting back up the tree takes a lot of time.  We have found that deleting children first, then parents is much faster.
LVL 21

Expert Comment

ID: 39239432
Does the child table have an index on the foreign_key columns referring to the parent table ?
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

LVL 15

Expert Comment

by:Franck Pachot
ID: 39240218

The forall approach is ok if you want to do it online. You can do intermediate commits and run it ad several times for few rows. And as you can do it online, the duration should not matter.

Note that NOLOGGING has no meaning here for the delete statement.


Author Comment

ID: 39241388
If I disable the constraints, it is very fast. let me check the other things.
LVL 35

Accepted Solution

johnsone earned 2000 total points
ID: 39241558
Disable which constraints?  The foreign key constraints?  If so, were they cascade delete constraints?  If they are not cascading constraints, then I would venture a guess that the key field of the parent table is not indexed in the child table.  That would cause a significant slow down in deletes.
LVL 23

Expert Comment

ID: 39243130
Please post the entire SQL statement, changing names as necessary.

Author Closing Comment

ID: 39244753
Correct. It was not indexed, When it is indexed, it is fast.

Thank you very much.

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question