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! 2 7666 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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 automatically deletes also all those rows in
the child table whose foreign key values are equal to the referenced
key value in the parent row.
However:
|
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 use
replication then you cannot use Instead Of triggers as it prohibits the
replication triggers from firing. My delima is that I need to cascade
delete, but first have the record and all child records inserted into
associated delete tables...
|
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)); <--- This is ok!
CREATE TABLE CanTake (Name Text(10) not null, Make Text(10) not null,
CONSTRAINT pkCanTake
PRIMARY KEY (Name, Make),
|
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 table from which I want to
delete has two foreign keys that references two other tables and it is
also referenced by another table. But this shouldn't be a problem, since I
set the commit mode to none (or *none) at all places where this makes...
|
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 table, or perhaps bytes, being updated where the engine just
decides, screw it, i'll just make a new one.
surfed this group and google, but couldn't find anything.
the context: we have some java folk who like to parametize/
| |
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 other tables etc.
in other words we must use cascade delete to do
|
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
the problem is.
I keep getting errors like (the first is my debug output):
NOTICE: last cycle is: 11
WARNING: Error occurred while executing PL/pgSQL function
|
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 magazine database with web
(PHP) and C++ Interface, serving over the web and in a very fast LAN.
So my concern is about performance (and aestaetic by doing the things
as optimal as possible.) This is my first database at all, but I have
read a lot of...
|
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
"Generations"), and it allows the user to add, edit and delete the
various records of the table.
"Generations" table has the following fields:
"IDPerson", NamePerson", "AgePerson" and "IDParent".
A record contains the information about a person (his name, his...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |