Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 1281
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 Query to compare 2 values of 1 column... Poha Eater DB2 13 Fri Mar 09, 2018 10:45 am
No new posts How to replace the below query? pkmurali DB2 12 Tue Feb 27, 2018 9:51 pm
No new posts Need Guidance regarding UPDATE query Poha Eater DB2 3 Mon Feb 12, 2018 11:35 pm
No new posts Query to skip Max time-stamp and fetc... vickey_dw DB2 8 Sun Jan 28, 2018 1:09 am
No new posts reg query on DYNALLOC feature raghuraman123 SYNCSORT 12 Wed Jan 10, 2018 2:42 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us