MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Alternative to Cascase delete

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
umj
Beginner


Joined: 25 Nov 2008
Posts: 8
Topics: 4

PostPosted: Tue Nov 25, 2008 1:52 pm    Post subject: Alternative to Cascase delete Reply with quote

In my application, a cascade delete is done. There is a commit after each delete. However, this delete causes over 10,000,000 records to be deleted from the child tables. The DBA team is having an issue with this job.
I have thought of the following options:
(1)
changing the program logic to delete from child tables first and then going up the hierarchy. At the same time deleting N number of records by using a cursor.
(2)
Unload the tables into a file and then delete fromt he files and then load them again into the tables.

Can anyone suggest another option

Thanks
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Tue Nov 25, 2008 2:19 pm    Post subject: Reply with quote

umj,

Ideally I would do this

1. Declare cursor on the Parent table
2. Fetch the cursor
3. Now issue delete statements on each of the child tables with the key from parent table
4. Once step3 is complete, issue the delete on parent table

Unloading and re-loading the tables is a mute exercise

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
umj
Beginner


Joined: 25 Nov 2008
Posts: 8
Topics: 4

PostPosted: Tue Nov 25, 2008 4:57 pm    Post subject: Reply with quote

hi Kolusu

This is whaat is currently done.

but since the child tables hold huge data for each entry in parent table it is becoming a problem.

Is there a way by which we can specify the # of records to delete from the child table (in a delete stmt)
Commit and then reissue the delete stmt until no correspondng reocrds are present in the child table.


Thanks
umj
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Tue Nov 25, 2008 6:02 pm    Post subject: Reply with quote

umj,

hmm. May be a crude approach but might work faster

1. Declare cursor on the Parent table
2. Fetch the parent table cursor
3. Now open a cursor on each individual child tables with parent table key
4. Issue a delete statement with where current of
5. repeat step 3 and 4 for all the child tables
6. now delete the parent table key

Also you can minimize the steps 3 and 4 using the count of records on each child table for the parent table key.

get the count from child table for the parent table key
Code:

if count > 1000
   open cursor and delete 1 by 1
else
delete the rows directly
end-if
Back to top
View user's profile Send private message Send e-mail Visit poster's website
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Wed Nov 26, 2008 8:58 am    Post subject: Reply with quote

Deleting 10 million rows, huh? That's a big matzah ball.

Anyway. I've used the following in UDB for AIX, so I'm not sure the z/OS product will honor the syntax:
Code:
delete from (select  record_id
               from  test.delete_tbl_name
              where  <delete criteria>
              fetch first 50000 rows only) as d;
commit;


You'd have to put this in a loop keep executing the DELETE until the value of SQLERRD(3) < 50,000. Obviously, you'd be deleting from the children up to the parent table by table.

Another option to explore would be a REORG with the DISCARD option. With any DELETE solution, you'll be generating a ton of log entries which still might create headaches for your DBA's. Depending on the percentage of rows that you're deleting, your DBA's might want to run a REORG when the deletes are done anyway. Don't forget the RUNSTATS if you run the REORG.
Back to top
View user's profile Send private message
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Wed Nov 26, 2008 3:11 pm    Post subject: Reply with quote

Forget about the first option I mentioned. The z/OS product doesn't support that syntax. The REORG is probably a better solution anyway.
Back to top
View user's profile Send private message
umj
Beginner


Joined: 25 Nov 2008
Posts: 8
Topics: 4

PostPosted: Thu Nov 27, 2008 10:15 am    Post subject: Reply with quote

thansk jsharon1248

I think I'll be working on the Reorg with Discard option.

Thanks once again
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group