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 > How to improve performance when using distinct

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-23-03, 08:27
matthewlau matthewlau is offline
Member
 
Join Date: Dec 2001
Posts: 78
How to improve performance when using distinct

Very simple statement:
select distinct locid from location

The table contains a million of rows, and the statement only return 1-3 records (i.e. the table only have 1-3 sets of locid). Index (locid) is built in the table, it takes 3-7 seconds to run this SQL, very slow, I have tried to build clustering index on locid, it helps a little, but still very slow, take 2-5 seconds to run. Is there any way to improve the performance of this SQL?

Thx in advance.
Reply With Quote
  #2 (permalink)  
Old 10-23-03, 09:34
blom0344 blom0344 is offline
Registered User
 
Join Date: Jan 2003
Location: Zutphen,Netherlands
Posts: 256
Are you assuming that the duration of a query should be related to the queries output in terms of rows returned?
2-5 seconds does not seem unreasonable. I have a 14 second wait for a similar query fetching 4 distinct years from a 2.5 million table.

However query optimization is set at 9, which may be okay for complicated queries and bad for simple ones (Optimizer is given more time to choose an access path)
__________________
Ties Blom
Senior Application Developer BI
Getronics Healthcare
DB2,ORACLE,Powercenter,BusObj,Access,
SQL, SQL server
Reply With Quote
  #3 (permalink)  
Old 10-23-03, 11:36
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
In order to satisfy the query, DB2 has to read all the rows of the index. Even though the column length of the index may be small, 4 million is a lot of index rows to read.

Most studies have shown that optimization level 7 is about as high as you want to go except in very rare cases. Optimization level 9 can take a lot longer than level 7.
Reply With Quote
  #4 (permalink)  
Old 10-23-03, 13:59
chuzhoi chuzhoi is offline
Registered User
 
Join Date: Dec 2002
Posts: 134
Re: How to improve performance when using distinct

You have only one option - build a summary table. You will have whole set of new issues like maitaining the table(when to refresh), but it's a different story.
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