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 > query performance

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-14-08, 11:55
dareman123 dareman123 is offline
Registered User
 
Join Date: Dec 2007
Posts: 30
query performance

i have the following query running which was running a bit slow.(it was not written by me)can any one suggest me how i could improve the performance.its not doing any table scans except inthe first CTE.even though there is a index on the join column its doing table scan as there are no predicates except the flag.how can i rewrite this query with out CTE's.
db2 V8.2fp5 solaris environment
with online AS.
(SELECT exc.snb,
exc.dets,
EC.ccx,
EC.cls_NAME_TX,
EC.SHORT_DESCRIPTION_TX,
exc.SCORE_NB,
exc.sts_cd
FROM db2udb.online_XUSER_cls exc,
db2udb.online_cls EC
WHERE exc.cls_UUID_TX = E.PK_cls_UUID_TX
AND exc.cls = 'N'),
DATES AS
(SELECT snb,
ccx,
COUNT ( ccx ) AS TIMES_TAKEN,
MIN ( dets ) AS MinDATE,
MAX ( dets ) AS MaxDATE
FROM online
WHERE sts_cd <> 'E'
GROUP BY snb,
ccx)
SELECT EM.EMPLOYEE_WORK_LOCATION,EM.snb,EM.EMPLOYEE_NB,EM .FIRST_NM,
EM.LAST_NM,ET.dets,EM.sts_cd AS DEFAULT_sts_cd,ONL.ccx,
ONL.cls_NAME_TX,ONL.SHORT_DESCRIPTION_TX,ONL.SCORE _NB,
ONL.sts_cd,DT.TIMES_TAKEN,DT.MinDATE,DT.MaxDATE
FROM EMPLOYEES EM
LEFT JOIN online ONL ON ONL.snb = EM.snb AND ONL.ccx = ES.ccx
LEFT JOIN DATES DT ON DT.snb = EM.snb AND DT.ccx = ONL.ccx
ORDER BY ONL.sts_cd,
EM.FIRST_NM
any help is appreciated thanks
Reply With Quote
  #2 (permalink)  
Old 03-14-08, 12:45
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Before you try to rewrite it, you need to figure out why it is doing a table scan. How many rows are in db2udb.online_XUSER_cls? How many of those have cls = 'N'? Is there an index on cls?

Andy
Reply With Quote
  #3 (permalink)  
Old 03-14-08, 14:06
dareman123 dareman123 is offline
Registered User
 
Join Date: Dec 2007
Posts: 30
the table is 1.5 million and cls is also almost the same and there is no
index on cls since its a flag i thoght there would not be much use.
Reply With Quote
  #4 (permalink)  
Old 03-14-08, 14:10
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You are better off not doing anything. Since you say that cls = 'N' is almost the entire table, than doing a table scan is not a bad plan to retrieve 98% of the table.

Andy
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