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 > Why combined index improves performance of SUM ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-18-12, 08:26
captnkirk captnkirk is offline
Registered User
 
Join Date: Jan 2012
Posts: 1
Question Why combined index improves performance of SUM ?

Hi,

I have a question concerning combined index and SUM. The following query needs about 20 minutes:

SELECT vendorid, count(*), SUM(value) from TABLE1 WHERE vendorid=1112233 group by vendorid;

I have an index for the column vendorid. If I skip the SUM part then the query is finished below one second. The amount of entries to sum up is about 300.000.

db2advis told me to make a combined index of (vendorid ASC, value DESC). Now the query is very fast. But I do not understand why the combined index makes the SUM operation faster?
Reply With Quote
  #2 (permalink)  
Old 01-18-12, 08:51
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
Because with the combined index DB2 can satisfy the entire query by only accessing the index and not even having to go to the table to get the results. You should probably determine how often this query runs and whether it is worth adding the value column to the index, especially since it might make other SQL run slightly slower. DB2 advisor can produce misleading results unless you provide it the entire SQL workload against the table.
__________________
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-18-12, 20:15
fengsun2 fengsun2 is offline
Registered User
 
Join Date: Nov 2011
Posts: 124
Can you publish the access plan here ?

1、without combined indexes and without sum,
2、without combined indexes and with sum
3、with combined indexes

thx
Reply With Quote
Reply

Tags
index, sum

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