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
 

 

SQL Query Optimization

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sreekusr
Warnings : 1

New User


Joined: 28 Aug 2006
Posts: 50
Location: London

PostPosted: Wed Jun 03, 2009 7:13 pm    Post subject: SQL Query Optimization
Reply with quote

For our project,we have a cursor defenition as shown below. For opening this cursor the CPU time required is quite high. Can someone suggest and alternative approach to reduce the time taken for the query to execute. We would prefer to get rid of the NOT EXISTS in the query

Code:
SELECT        TEST_ROL_ID                                     
         FROM        VIEW1 A,                                     
                       VIEW2 B                                     
         WHERE       TEST_STRT_TS < :WS-TODAY-TS            AND 
                       TEST_EXPIRY_TS > :WS-TODAY-TS-1        AND 
                     TEST_EXPIRY_TS <= :WS-TODAY-TS         AND 
                        TEST_ALWD_ROL_S_TS < :WS-TODAY-TS      AND 
                        TEST_ALWD_ROL_E_TS > :WS-TODAY-TS      AND 
                        TEST_ROL_ID > :WS-CP-ROL-ID            AND 
                        A.TEST_SEC_SEG_ID = B.TEST_SEC_SEG_ID  AND 
                        B.TEST_USR_TYP_ID = 1                  AND 
                        TEST_VFN_ST = 'A'                      AND 
            NOT EXISTS                                 
                       (SELECT * FROM VIEW3 C                   
                        WHERE C.TEST_ROL_ID = A.TEST_ROL_ID AND
                              C.TEST_SEC_SEG_ID =               
                                       A.TEST_SEC_SEG_ID   AND 
                              C.TEST_VFN_ST = A.TEST_VFN_ST AND
                              C.TEST_STRT_TS <                 
                                       CURRENT TIMESTAMP   AND 
                              C.TEST_EXPIRY_TS >               
                                       CURRENT TIMESTAMP   AND 
                              C.TEST_ALWD_ROL_S_TS <           
                                       CURRENT TIMESTAMP   AND 
                              C.TEST_ALWD_ROL_E_TS >           
                                          CURRENT TIMESTAMP)   
            ORDER BY TEST_ROL_ID ASC;


Thanks,
Sree
Back to top
View user's profile Send private message

Itanium

Active User


Joined: 22 Jan 2006
Posts: 114
Location: India

PostPosted: Wed Jun 03, 2009 7:22 pm    Post subject:
Reply with quote

Best suggestion would be to ask the DBA of your shop.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6967
Location: porcelain throne

PostPosted: Wed Jun 03, 2009 9:29 pm    Post subject:
Reply with quote

just remove the NOT EXISTS from your CURSOR DECLARATION
and after every FETCH,
do a singleton select against VIEW3
(with all the where clauses from the subselect) -
you would have to recode the singleton to use host variables instead of VIEW1 column references.

Also, the WS-TODAY-TS and WS-TODAY-TS-1 -
if they are host variable timestamps, how did you generate them?
If you generated them thru COLUMNAR functions in an earlier SQL,
use the COLUMNAR functions to replace the host variables.
remove as many host variables as you can from your cursor declaration.

and index as much as possible.

then EXPLAIN your SQL.

then talk with your DBA's.
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 -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


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