Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Pls suggest to optimize below query.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
apandey

New User


Joined: 31 Aug 2009
Posts: 73
Location: Mumbai

PostPosted: Fri May 06, 2011 3:34 pm    Post subject: Pls suggest to optimize below query.
Reply with quote

Hi All,

Below query is taking lots of time because of which the job is abending, giving time out reason. Pls Note: INDEX are already built on where clause predicates.

---------------------------------------------------------
EXEC SQL
DECLARE PVPWCUR CURSOR FOR
SELECT F1.I_MOD_YR
,F1.C_FAM
,F1.C_GRP
,Q1.I_VSC
,Q1.Q_PART_REQD
,Q1.Q_PART_FPV_ANNL
,X1.X_DESC
FROM
(SELECT DISTINCT(E1.I_PART)
,E1.I_MOD_YR
,E1.C_FAM
,E1.C_GRP
FROM E.EBUCREL E1
WHERE E1.C_STAGE_DVLP = '3'
AND E1.D_EFF_OUT = '9999-12-31'
AND E1.C_UM <> 'RF'
AND E1.I_MOD_YR = :EPVSDTL.I-MOD-YR
AND E1.C_FAM >= :WS-FAM-LOW
AND E1.C_FAM <= :WS-FAM-HIGH
AND E1.I_PART >= :WS-PART-LOW
AND E1.I_PART <= :WS-PART-HIGH
AND E1.C_GRP >= :WS-BCG-LOW
AND E1.C_GRP <= :WS-BCG-HIGH
) AS F1,

(
SELECT P1.I_MOD_YR
,P1.C_FAM
,P1.I_PART
,P1.I_VSC
,P1.Q_PART_REQD
,SUM(P1.Q_PART_FPV_ANNL) AS Q_PART_FPV_ANNL
FROM E.EPVSDTL P1
WHERE P1.I_PRTITN = :EPVSDTL.I-PRTITN
AND P1.I_MOD_YR = :EPVSDTL.I-MOD-YR
AND P1.C_FAM >= :WS-FAM-LOW
AND P1.C_FAM <= :WS-FAM-HIGH
AND P1.I_PART >= :WS-PART-LOW
AND P1.I_PART <= :WS-PART-HIGH
AND P1.I_VSC >= :MD-VSC-MIN
AND P1.I_VSC <= :MD-VSC-MAX
AND P1.C_LINE >= :MD-LINE-MIN
AND P1.C_LINE <= :MD-LINE-MAX
AND P1.C_MKT >= :MD-MKT-MIN
AND P1.C_MKT <= :MD-MKT-MAX
AND P1.I_PLT >= :MD-PLT-MIN
AND P1.I_PLT <= :MD-PLT-MAX
AND P1.C_SERIES >= :MD-SRS-MIN
AND P1.C_SERIES <= :MD-SRS-MAX
AND P1.C_BDY_STYLE >= :MD-BDYSTL-MIN
AND P1.C_BDY_STYLE <= :MD-BDYSTL-MAX

GROUP BY P1.I_MOD_YR
,P1.C_FAM
,P1.I_PART
,P1.I_VSC
,P1.Q_PART_REQD
) AS Q1, E.EBLDGRP X1
WHERE F1.I_PART = Q1.I_PART
AND F1.I_MOD_YR = Q1.I_MOD_YR
AND F1.C_FAM = Q1.C_FAM
AND X1.C_GRP = F1.C_GRP
ORDER BY F1.I_MOD_YR
,F1.C_FAM
,F1.C_GRP
,F1.I_PART
END-EXEC.
--------------------------------------------------------------------------
Back to top
View user's profile Send private message

GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1278
Location: Belgium

PostPosted: Fri May 06, 2011 9:04 pm    Post subject:
Reply with quote

Do you really think this is enough info?
which indexes ? one with all the columns, or one for each column ? in which order are the columns in the index ?
Which of the 8 predicates is most likely to be filled in and which is most selective/restrictive ?
You should at least use between instead of >= and <=
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Join in SQL Query vickey_dw DB2 2 Tue Jan 17, 2017 12:15 am
This topic is locked: you cannot edit posts or make replies. MQ setup query mohitsaini Java & MQSeries 4 Sun Jan 08, 2017 1:53 am
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us