Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Fetch First n rows / Optimize / simple Fetch

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
jackare

New User


Joined: 27 Aug 2008
Posts: 32
Location: Brazil

PostPosted: Thu Oct 02, 2008 6:30 am    Post subject: Fetch First n rows / Optimize / simple Fetch
Reply with quote

Hello,
I have some questions about performance.I developed a Cobol program to fetch e return 100 rows, per Call, from a DB2 Table.
In this program there are four simple SQL commands:
Code:
   
   DECLARE CURSOR  with a simple clause :
           SELECT COD, DATE_CTR FROM TAB WHERE COD >= :cod   ORDER BY COD

    OPEN CURSOR

    FETCH CURSOR

    CLOSE  CURSOR


So, my table have arround 50.000 rows, and each execution of this program returns a array with 100 occurrences (100 rows), deppending on WHERE Clause (host variable cod). Can I reach best performance using DB2 options in DECLARE sentence? Or the best way is using a simple DECLARE and FETCH (until 100 rows)?
I'm talking about options: "Fetch First n rows and Optimize.
Could you me?

Thanks a lot!
Back to top
View user's profile Send private message

ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Thu Oct 02, 2008 4:12 pm    Post subject:
Reply with quote

Fetch first 100 rows doesnt mean the cursor will fetch 100 rows at a time ... if 150 rows satisfies your where clause the result set when you open the cursor will have only first 100 rows .... 50 rows will be discarded .... this clause wont help you in performance improvement ....
If you need to return your 50k rows to the calling program y not open the cursor and return the control back to the calling program ..let it fetch data from the cursor ... you need to declare your cursor with return ...this will reduce traffic also as you dont have to return an array ...
Back to top
View user's profile Send private message
jackare

New User


Joined: 27 Aug 2008
Posts: 32
Location: Brazil

PostPosted: Fri Oct 03, 2008 7:49 am    Post subject: Reply to: Fetch First n rows / Optimize / simple Fetch
Reply with quote

OK,
Thanks a lot.
Back to top
View user's profile Send private message
ulfnsc

New User


Joined: 15 Jan 2004
Posts: 19
Location: Stockholm, SWEDEN

PostPosted: Fri Oct 03, 2008 2:34 pm    Post subject:
Reply with quote

Here is a cool article if you use DB2 v8.

http://www.ibmdatabasemag.com/story/showArticle.jhtml?articleID=180206476
Back to top
View user's profile Send private message
jackare

New User


Joined: 27 Aug 2008
Posts: 32
Location: Brazil

PostPosted: Wed Oct 08, 2008 8:50 am    Post subject:
Reply with quote

It's very good. I am going to try this. Thaks again!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts Conditional highlighting of rows in I... packerm CLIST & REXX 2 Thu Sep 21, 2017 6:50 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm
No new posts Optimize sort inrec parse vishwakotin DFSORT/ICETOOL 6 Mon Jun 26, 2017 11:15 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us