If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > OPTIMIZE for N rows

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-31-10, 12:31
prakash5686 prakash5686 is offline
Registered User
 
Join Date: May 2010
Posts: 3
OPTIMIZE for N rows

What are the disadvantages of Clause "OPTIMIZE FOR N ROWS" in SQL query?

Thanks
Reply With Quote
  #2 (permalink)  
Old 05-31-10, 16:35
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
The main benefit is when you open a cursor and only fetch some of the rows (before getting to end of cursor with SQLCODE = 100). Using OPTIMIZE FOR 1 ROWS will turn off sequential prefetch (where DB2 retrieves rows from the tablespace and puts them in the bufferpool even before they are requested, in anticipation that they will be needed soon). But if all the rows in the cursor are not fetched, then it would be a big waste to invoke sequential prefetch. Sequential prefetch usually only occurs when DB2 determines that a large number of rows will be included in the answer set (such as with with a table scan).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 06-03-10, 00:59
prakash5686 prakash5686 is offline
Registered User
 
Join Date: May 2010
Posts: 3
Thanks Marcus.

How far can we believe on EXPLAIN tool for Db2 sql queries?

Last edited by prakash5686; 06-03-10 at 01:04.
Reply With Quote
  #4 (permalink)  
Old 06-03-10, 19:22
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by prakash5686 View Post
Thanks Marcus.

How far can we believe on EXPLAIN tool for Db2 sql queries?
I don't know what you are asking. Generally the explain is accurate if done on the same system as the query is run. But you could get different results if your literals are different in the query than in the explain, or if parameter markers are used in the explain and literals are used in the query.

Also, the DB2 optimizer only estimates how many rows will be returned, and could be wrong based on the quality of statistics captured with runstats. But the access path is likely to be the same (index, table scan, etc).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On