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
 
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: 54
Location: Madrid

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: 6970
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 How to force a select query to abend neo4u DB2 5 Mon Apr 23, 2018 1:36 pm
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

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