IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Using One big Cursor vs Multiple Cursors


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
briansheehan

New User


Joined: 02 Jun 2007
Posts: 5
Location: ireland

PostPosted: Sun Jun 03, 2007 3:09 am
Reply with quote

I am creating about 250,000 records, and writing these out to a file.

As my data is extracted from numerous tables at different levels, originally I used three big cursors and looped within them to format my data. Due the the sheer volume of data, the job took over 2 hours to run. Thus, as I figured most of the job is IO, if I combined the three cursors, it could do the IO work up front, then the job would take less time. However it took about twice as long to run this way.

Would you not expect the use of on big cursor in this instance to shorten the run time?

Thanks
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Sun Jun 03, 2007 3:24 am
Reply with quote

briansheehan wrote:
Would you not expect the use of on big cursor in this instance to shorten the run time?
You are talking cursors, so I am thinking DB2...
In the general way things go, I have found that the more complexity in the select, the higher the overhead.
Sometimes, doing simple (keyed) selects on multiple tables to temporary tables and then doing the complex select against these much smaller and simpler tables is much faster and less expensive that "one big cursor"...
But then again, the right stats, and indexes, it could go the other way.....
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Jun 03, 2007 4:19 am
Reply with quote

Hello,

If you post the predicates from the selects in the cursors and a bit of info about the tables (how indexed, how many rows, etc), we may be able to offer suggestions.

250,000 is not really a large volume of records to create, but if the db2 system has to look thru millions and millions of rows to get them, it will run unacceptably long.

Look to make sure there are not repeated full-table scans or that none of the joins is generating a cartesian product.

Depending on how the data is being processed, it may be much faster to unload some or all of the tables to sequential datasets and process externally. Some very large batch processes run exponentially faster when taken out of the database environment.
Back to top
View user's profile Send private message
munikumar
Currently Banned

New User


Joined: 18 Apr 2007
Posts: 24
Location: India

PostPosted: Thu Jun 07, 2007 10:49 am
Reply with quote

Here are some of the Query tuning tips:
1.Use the appropriate indexed predicates in select statements.
2.If you are using more than one table, better to use JOINs instead of sub-queries.
3.Do not use SELECT *
4.Try to avoid aggregate function on non-numeric columns

Also there are lot of external points that matters your query tuning.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Grouping by multiple headers DFSORT/ICETOOL 7
No new posts How to append a PS file into multiple... JCL & VSAM 3
Search our Forums:

Back to Top