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: 45
Location: Mumbai

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: 6966
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 Join in SQL Query vickey_dw DB2 1 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