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 Optimization

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-11-10, 03:44
Ranbir Kaur Ranbir Kaur is offline
Registered User
 
Join Date: Aug 2010
Posts: 4
Query Optimization

SELECT
T1.CT_ID,
T1.LT_UPD,
T1.CREATED,
T1.LT_UPD_BY,
T1.CREATED_BY,
T1.M_NUM,
T1.ROW_ID,
T1.CURCY_CD,
T1.X_ATTRIB_15
FROM
SIE.C_CLAIM_M_M T1
INNER JOIN SIE.S_IN_CLAIM_M T2 ON T1.PAR_ROW_ID = T2.ROW_ID
WHERE
((T1.TYPE = 'Transaction Reserve') AND
(T2.ATTRIB_03 = 'CLAIM')) AND
(T1.CLAIM_ID = '1-CG9X0S')
ORDER BY
T1.CLAIM_ID, T1.X_ATTRIB_18
Reply With Quote
  #2 (permalink)  
Old 08-11-10, 04:23
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
Is it not homework?

Some ideas to rewrite the query are as followings....
Although they may influence performance or not, they may improve readability and maintenability.

1) "INNER JOIN SIE.S_IN_CLAIM_M T2" can be replaced by EXISTS, if T2.ROW_ID is unique.
Because, no column of T2 was included in the select list.

2) T1.CLAIM_ID is not neccesary in ORDER BY clause.
Because T1.CLAIM_ID = '1-CG9X0S' was specified in WHERE clause.

3) I couldn't find any reason to use unnecessary parentheses in WHERE conditions.
They harm readability, and may be cause of syntax error at the time of maintenance.
Reply With Quote
  #3 (permalink)  
Old 08-11-10, 04:49
Ranbir Kaur Ranbir Kaur is offline
Registered User
 
Join Date: Aug 2010
Posts: 4
It was working earlier and stuck in between....can any one suggest the best way to optimize this sql query.
Reply With Quote
  #4 (permalink)  
Old 08-11-10, 05:43
Ranbir Kaur Ranbir Kaur is offline
Registered User
 
Join Date: Aug 2010
Posts: 4
This query was working for the last 2 months. can any one suggest what would be the best way to do the performance tuning for the above listed query. the way to optimize the problem.
Reply With Quote
  #5 (permalink)  
Old 08-11-10, 08:05
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
I, believe, Tonkuma has already answered you on quite a few points that would help speed this query up. If you take his suggestions on the order by and exists subselect, you should see improvement. The other advice for readability and maintenance is, also, spot on.
Dave
Reply With Quote
  #6 (permalink)  
Old 08-11-10, 08:10
Ranbir Kaur Ranbir Kaur is offline
Registered User
 
Join Date: Aug 2010
Posts: 4
Its system generated query as I told earlier for the last 2 months it was working properly and giving prompt results but this time i am facing the problem of long-running query. kindly suggest ....both tables are properly indexed.
Reply With Quote
  #7 (permalink)  
Old 08-11-10, 10:45
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
- reorg and runstats tables used in the query;
- do not assume that your "system" created a perfect query. listen to suggestion given here;
- do not assume that existing indexes are actually used just because you think they are used.
index usage should bechecked by proper db2 tools.
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
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