MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

DB2 query optimization

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
srini_igsi
Beginner


Joined: 12 May 2006
Posts: 41
Topics: 16
Location: Mumbai

PostPosted: Mon Mar 16, 2009 1:37 pm    Post subject: DB2 query optimization Reply with quote

The following query extracts all the CORPS for all the releases released till date at CORP level. The db2 host variable DB2-HOST-V-RLSE-DATE is populated with highest/latest release date from some other db2 table so that this wil be used to extract all the corps less than that release date. Just before the MAP is thrown to the user, we alwasys save the release dt, release id and the corp for the 1st and 12th rown on the MAP so that these values will be used for the forward (PF8) operation.


My requirement is that I have to extract all the releases for a specific CORP enterd by the user at the terminal on DESC order by RELEASE DT.
The updated query should also support forward (PF8) operation.

Could somebody please help to update the following query to retrieve the records matching the criteria said above.

Code:
                     
   SELECT CORP                                             
         ,C.RELEASE_ID                                     
         ,C.RELEASE_DATE                                   
         ,C.RT_IND                                         
         ,C.PROD_CODE                                       
         ,VALUE (SUM (SHARES_TOT),     0) AS SHARES_TOT     
         ,VALUE (SUM (SHARES_WTHHLD),  0) AS SHARES_WTHHLD 
      ,SUM (MULTIPLY_ALT (VALUE (VEST_DT_FMV , 0),         
          VALUE (SHARES_TOT ,  0)))                         
                       AS GROSS_TOT                         
         ,VALUE (SUM_TOT_SHRS ,   0) AS COVER_SHARES       
   FROM       SOSRSTK_REL_CNTL   C                         
   INNER JOIN SOSRSTK_REL_ELECT  E                         
   ON ((  C.CORP          > :DB2-HOST-V-CORP-12                 
   AND    C.RELEASE_DATE  = :DB2-HOST-V-RLSE-DATE           
   AND    C.RELEASE_ID    = E.RELEASE_ID )   
OR   ( C.CORP          = :DB2-HOST-V-CORP-12       
AND    C.RELEASE_ID    > :DB2-HOST-V-RLSE-ID-12     
AND    C.RELEASE_DATE  = :DB2-HOST-V-RLSE-DATE     
AND    C.RELEASE_ID    = E.RELEASE_ID ))           
     INNER JOIN SOSRSTK_REL_STATUS S               
ON     S.RELEASE_ID    = C.RELEASE_ID               
AND    S.REL_TYPE IN ('1', '2', '3', '4')           
AND    S.REL_STATUS   IN ('C', 'O', 'P')           
GROUP BY CORP                                       
        ,C.RELEASE_DATE                             
        ,C.RELEASE_ID                               
        ,C.RT_IND                                   
        ,C.PROD_CODE                               
        ,SUM_TOT_SHRS                               
ORDER BY C.CORP         ASC                         
        ,C.RELEASE_DATE ASC                         
        ,C.RELEASE_ID   ASC                         
OPTIMIZE FOR 12 ROWS           


Thanks in advance.
_________________
Thanks,
-Srini
Back to top
View user's profile Send private message
srini_igsi
Beginner


Joined: 12 May 2006
Posts: 41
Topics: 16
Location: Mumbai

PostPosted: Tue Mar 17, 2009 2:56 am    Post subject: Reply with quote

Could somebody help to re-design the query please?
_________________
Thanks,
-Srini
Back to top
View user's profile Send private message
bauer
Intermediate


Joined: 10 Oct 2003
Posts: 317
Topics: 50
Location: Germany

PostPosted: Thu Mar 26, 2009 1:58 am    Post subject: Reply with quote

Did you try to run explain ?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group