473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

TIps on Delete Cascade performance

Greetings,

I have to delete older policies and its related records in other
tables.

The deletion from the parent table will trigger the deletion of
relevant records from about 30 something tables that are defined with
DELETE CASCADE.

The delete SQL goes like this:

delete from policy p1
where (p1.tranid, p1.extract_dt)
in ( select p2.tranid, min(p2.extract_dt)
from policy p2
group by p2.tranid);

The size for policy table is about 150K rows and there may be 1:1 or
1:few records ratio between parent and child tables.

All foreign keys are indexed and clustred.

The SQL did not return result for a few hours.

Any suggestions to speed up the query?

Many Thanks!

Apr 20 '06 #1
2 7634
ne*****@hotmail.com wrote:
Greetings,

I have to delete older policies and its related records in other
tables.

The deletion from the parent table will trigger the deletion of
relevant records from about 30 something tables that are defined with
DELETE CASCADE.

The delete SQL goes like this:

delete from policy p1
where (p1.tranid, p1.extract_dt)
in ( select p2.tranid, min(p2.extract_dt)
from policy p2
group by p2.tranid);

The size for policy table is about 150K rows and there may be 1:1 or
1:few records ratio between parent and child tables.

All foreign keys are indexed and clustred.

The SQL did not return result for a few hours.

Any suggestions to speed up the query?

Many Thanks!

Which platform?
On DB2 V8.1.4 and later let's first get rid of the self join:

delete from
(select row_number() over(partition by tranid order by extract_dt) as rn
from policy) AS D
where rn = 1

Do any of the tables or policy itself have any additional fancyness
(more delete cascade/restrict/no action), after delete triggers)?

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Apr 20 '06 #2
Hi Serge,

It is on AIX 5.3 DB2 V8.2.2

The Policy table is parent table. The dependant tables could have more
than one RI (ie more than one 'delete cascade') with other tables in
addition to Policy table. Other RI relationship is 'on update no
action'. That will be it.

I'll test out the SQL as suggested.

Thanks again!

Serge Rielau wrote:
ne*****@hotmail.com wrote:
Greetings,

I have to delete older policies and its related records in other
tables.

The deletion from the parent table will trigger the deletion of
relevant records from about 30 something tables that are defined with
DELETE CASCADE.

The delete SQL goes like this:

delete from policy p1
where (p1.tranid, p1.extract_dt)
in ( select p2.tranid, min(p2.extract_dt)
from policy p2
group by p2.tranid);

The size for policy table is about 150K rows and there may be 1:1 or
1:few records ratio between parent and child tables.

All foreign keys are indexed and clustred.

The SQL did not return result for a few hours.

Any suggestions to speed up the query?

Many Thanks!

Which platform?
On DB2 V8.1.4 and later let's first get rid of the self join:

delete from
(select row_number() over(partition by tranid order by extract_dt) as rn
from policy) AS D
where rn = 1

Do any of the tables or policy itself have any additional fancyness
(more delete cascade/restrict/no action), after delete triggers)?

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab


Apr 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
3
by: cfxchange | last post by:
I am looking into work-arounds for what seems to be a flaw, or "undocumented feature" of SQL Server replication and Instead of Delete triggers not playing together. It seems that if you want to...
2
by: P.B. via SQLMonster.com | last post by:
I cannot execute my sql to create a table with ON DELETE CASCADE option. Here is my sql: CREATE TABLE Employees (Name Text(10) not null, Age number, CONSTRAINT pkEmployees PRIMARY KEY (Name)); ...
9
by: Robert Schneider | last post by:
Hi to all, I don't understand that: I try to delete a record via JDBC. But I always get the error SQL7008 with the error code 3. It seems that this has something to do with journaling, since the...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
3
by: John Rivers | last post by:
Hello, I think this will apply to alot of web applications: users want the ability to delete a record in table x this record is related to records in other tables and those to others in...
14
by: Karl O. Pinc | last post by:
Hi, Thought perhaps some other eyes than mine can tell if I'm doing something wrong here or if there's a bug somewhere. I've never passed a ROWTYPE varaible to a function but I don't see where...
2
by: R.Welz | last post by:
Hello. I want to discuss a problem I have with my database design becourse I feel I cannot decide wheather I am on the right way of doing things. First of all, I am writing a literature and...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.