Solved

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

Posted on 2013-06-11
8
516 Views
Last Modified: 2013-06-13
Hi,

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.
Nologging.
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.
0
Comment
Question by:sakthikumar
8 Comments
 
LVL 73

Expert Comment

by:sdstuber
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?
0
 
LVL 34

Expert Comment

by:johnsone
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.
0
 
LVL 20

Expert Comment

by:flow01
ID: 39239432
Does the child table have an index on the foreign_key columns referring to the parent table ?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 15

Expert Comment

by:Franck Pachot
ID: 39240218
Hi,

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.

Regards,
Franck.
0
 

Author Comment

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

Accepted Solution

by:
johnsone earned 500 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.
0
 
LVL 23

Expert Comment

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

Author Closing Comment

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

Thank you very much.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql query 9 45
Can i Import Access Table Into Oracle Using Toad 36 166
Oracle Listener Not Starting 11 44
PL SQL Developer 7 32
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now