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 > Is creating indexes on date cols fo MAX /MIN aggregate functions good?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-08-07, 14:58
pagwu pagwu is offline
Registered User
 
Join Date: Mar 2007
Posts: 70
Is creating indexes on date cols fo MAX /MIN aggregate functions good?

Hi all,

I need to create one or two indexes on date columns to support MAX and MIN aggregate functions on a very large table and to make the SQL perform/run faster. I remember a group discussion sometime ago that creating an index on the date column ASCENDING or DESCENDING will be the thing to do. Is that still true?

Does anyone have or know of a good discussion of the pros and cons of doing what I am trying to accomplish?

Any information or examples will be very much appreciated.

Okonita
Reply With Quote
  #2 (permalink)  
Old 11-09-07, 02:28
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
due to enhancements in the usage of an index,
MAX() and MIN() can now take advantage of an index regardless of the ASC or DESC order.

to find the most effective index, the whole query must be considered. Creating an index only on the column used with MIN or MAX might not increase performance
Reply With Quote
  #3 (permalink)  
Old 11-09-07, 03:49
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,
it is suggested to create index with 'allow reverse scan' option.
Sample:
create index index_name on table_name (column1, column2, ... columnN) allow reverse scan

It is important as umayer stated that the whole SQL should be considered. Can you post SQL statement. Please also post user db2 edition and version, fixpack level and operating system you are using.
Hope this helps,
Grofaty
Reply With Quote
  #4 (permalink)  
Old 11-09-07, 12:09
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
DB2 z/OS doesn't have the ALLOW REVERSE SCAN option. But internally, indexes will be created with forward and backward pointers at the leaf level already. (The backward pointers are what ALLOW REVERSE SCAN adds on DB2 LUW.)
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 11-09-07, 13:35
pagwu pagwu is offline
Registered User
 
Join Date: Mar 2007
Posts: 70
Thanks Knut. Just so I understand, are you saying adding date_column_only index for SQL constructs using MAX(date_column) is a good idea, all things considered?

Okonita
Reply With Quote
  #6 (permalink)  
Old 11-09-07, 17:04
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Yes, I'd think so. But you should verify that the index is used by looking at the access plan.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
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