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 > Runstats - Does not help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-23-04, 13:02
dollar489 dollar489 is offline
Registered User
 
Join Date: Sep 2002
Posts: 456
Runstats - Does not help

Hi, I have a query like this:

select min(col1)
from tab
where somedate between 'date1' and 'date2'

Now, I have one index on column col1 and another one on somedate column. When I do runstats (I tried six different combinations) the query execution time goes up (more than couple of minutes) and access plan revealed it's using the index with col1.

I have also kept old statistics of production (a year back) and when I apply that script and then run the query again it works fine (less than one second). This time access plan revealed that it's making using of index on column somedate!!!

So, does the notion that DB2 optimizer will pick the best possible path when provided with updated statistics is wrong? Or there are some flaws in the RUNSTATS or Optimizer code?

Your comments are appreciated.

dollar
Reply With Quote
  #2 (permalink)  
Old 01-23-04, 16:51
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
This sounds like a familiar question posted recently?

What is the clustering index or the index used for reorgs. Maybe that has changed since when you had good response time? If somedate is the clustering index, it is more likely to pick that one for access. Make sure the table is reorged, then do runstats again.

You could also try different query optimization levels (higher or lower).

Lastly, I would check for APAR's in FP4 or APAR's yet to be fixed.
http://www-3.ibm.com/cgi-bin/db2www/...lib.d2w/report
__________________
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 01-26-04, 05:39
Walter Janissen Walter Janissen is offline
Registered User
 
Join Date: Nov 2003
Location: Germany
Posts: 62
I would say, the best index for that query is:

(someday, col1)

Then you will get an index only access.
Reply With Quote
  #4 (permalink)  
Old 01-26-04, 11:16
cchattoraj cchattoraj is offline
Registered User
 
Join Date: Mar 2003
Posts: 343
I didn't think a between could be resolved with an index only access though.
Reply With Quote
  #5 (permalink)  
Old 01-26-04, 11:30
dollar489 dollar489 is offline
Registered User
 
Join Date: Sep 2002
Posts: 456
Well, the query is making use of index but not the right one. When it makes use of index with time column (one in where clause), the result is instant but when it's using the index with ID column (one in select clause), it takes over 10 minutes.


dollar


Quote:
Originally posted by cchattoraj

I didn't think a between could be resolved with an index only access though.
Reply With Quote
  #6 (permalink)  
Old 01-26-04, 11:33
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
A between can use index only access, but in this case there is the min function on the selected column which is not in the index. So index only access is not possible.
__________________
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
  #7 (permalink)  
Old 01-26-04, 13:00
cchattoraj cchattoraj is offline
Registered User
 
Join Date: Mar 2003
Posts: 343
You're right - I meant min and wrote between. Thank you.
Reply With Quote
  #8 (permalink)  
Old 01-26-04, 13:49
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Dollar you should also read the other post on indexes

http://www.dbforums.com/t979949.html

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
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