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 

Clocking when doing a Fetch

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


Joined: 29 Nov 2005
Posts: 26
Topics: 9

PostPosted: Fri Mar 10, 2006 11:25 am    Post subject: Clocking when doing a Fetch Reply with quote

Hi

I have the following cursor
Code:

DECLARE TRAN1-CSR CURSOR FOR               
 SELECT                                   
        A.RQST_ID                         
       ,A.RQST_CRT_USER_ID                 
       ,A.RQST_CRT_DT                     
       ,A.BENE_CAN_NUM                     
       ,A.BIC_CD                           
       ,A.MCO_CTRT_NUM                     
       ,A.GHP_TRAN_CD                     
       ,'000'                             
       ,A.RQST_TYPE_CD                     
   FROM MCS_REQUEST A                     
   JOIN MCS_RQST_STATUS B                 
     ON A.RQST_STUS_CD = B.RQST_STUS_CD   
JOIN (                                     
      SELECT E.MCO_CTRT_NUM               
     FROM MCS_MCO_CONTRACT  E             
     WHERE E.RGN_NUM IN (                 
        SELECT F.RGN_NUM                   
           FROM MCS_DATA_ACS_RULE F,                     
                MCS_USER_DATA_ACS G                       
          WHERE F.DATA_ACS_RULE_ID  =G.DATA_ACS_RULE_ID   
            AND G.MMCS_USER_ID = :WS-DATA-FLTR-ID         
            AND F.MCO_CTRT_NUM  IS NULL)                 
UNION                                                     
 SELECT E.MCO_CTRT_NUM                                   
   FROM MCS_MCO_CONTRACT  E                               
  WHERE E.MCO_CTRT_NUM IN (                               
      SELECT F.MCO_CTRT_NUM                               
        FROM MCS_DATA_ACS_RULE F,                         
             MCS_USER_DATA_ACS G                         
       WHERE F.DATA_ACS_RULE_ID  = G.DATA_ACS_RULE_ID     
         AND G.MMCS_USER_ID = :WS-DATA-FLTR-ID           
         AND F.RGN_NUM IS NULL )                         
         ) AS Z                                           
     ON A.MCO_CTRT_NUM = Z.MCO_CTRT_NUM                   
  WHERE A.RQST_STUS_CD = :WS-TRANS-STUS                   
    AND A.RQST_TYPE_CD = :WS-TRANS-TYPE                   
    AND A.GHP_TRAN_CD  = :WS-GHP-TRAN-CD                 
    AND A.RQST_TYPE_CD NOT IN (6, 4, 15, 16, 17,   
                                 18, 23, 25)       
    AND A.RQST_DEL_CD  = 'N'                       
     AND A.RQST_CRT_DT BETWEEN                 
               :WS-FROM-DATE AND :WS-THRU-DATE 
     AND (A.RQST_XPRN_DT >= CURRENT DATE       
      OR  A.RQST_XPRN_DT IS NULL )             
     FETCH FIRST 1001 ROWS ONLY                   
  WITH UR                                     



This is executed in a COBOL program via a DB2 Stored procedure.

When trying to OPEN the cursor it clocks. For testing it I changed the FETCH FIRST 1001 ROWS ONLY  to FETCH FIRST 10 ROWS ONLY.
After this change the OPEN worked fine but now it is clocking in the Fetch statement. The Fetch statement is as said below.

   FETCH TRAN1-CSR                                     
    INTO :RQST-ID                             
        ,:RQST-CRT-USER-ID                   
        ,:RQST-CRT-DT:CRT-DT-IND             
        ,:BENE-CAN-NUM                       
        ,:BIC-CD                             
        ,:MCO-CTRT-NUM:CTRT-NUM-IND           
        ,:GHP-TRAN-CD                         
        ,:TRAN-RPLY-CD:RPLY-CD-IND           
        ,:RQST-TYPE-CD                       

All the above host variables except the Indicators are DCLGEN variables.

Please help me out
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Fri Mar 10, 2006 11:36 am    Post subject: Reply with quote

Pknair,

we really cannot help not knowing how the indexes are defined on each table. btw did you realize how many tables are involved in the join ? Even if one table hits a tablespace scan you will have problems. My advice is to talk to your DBA.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
SureshKumar
Intermediate


Joined: 23 Jan 2003
Posts: 211
Topics: 21

PostPosted: Fri Mar 10, 2006 11:38 am    Post subject: Reply with quote

pknair,
If "FETCH FIRST 10 ROWS ONLY" is in effect and the OPEN is complete, then FETCH should not take time. What else is going on in the program logic, what is going on in the SP with the result - ie, is it a RESULT SET or not, or maybe the caller of the SP is not obtaining the results. Check the program logic, something must be holding it. Thanks
Back to top
View user's profile Send private message
Pknair
Beginner


Joined: 29 Nov 2005
Posts: 26
Topics: 9

PostPosted: Fri Mar 10, 2006 11:41 am    Post subject: Reply with quote

Hi Kolusu

Thank you for a quick reply

You are right about that.

My understanding is that once the Open Cursor statement is successful then the Query is materialised and the result set is created. A fetch only goes against that result set. In the second senario when I included the FETCH FIRST 10 ROWS ONLY statement the OPEN CURSOR worked fine but it started clocking on the fetch. That was why I was confused.

I verified the explain and it does not show any tablespace scans.
Back to top
View user's profile Send private message
Pknair
Beginner


Joined: 29 Nov 2005
Posts: 26
Topics: 9

PostPosted: Fri Mar 10, 2006 11:46 am    Post subject: Reply with quote

Hi Suresh

In between the OPEN and the FETCH there is only one statement which is an SQLCODE verification for the OPEN statement which is

IF SQLCODE NOT = ZEROES
PERFORM XXX-PARA
END-IF

It clocks at the very first FETCH

Thanks
Back to top
View user's profile Send private message
SureshKumar
Intermediate


Joined: 23 Jan 2003
Posts: 211
Topics: 21

PostPosted: Fri Mar 10, 2006 2:06 pm    Post subject: Reply with quote

Pknair,
The issue is more in line with Kolusu's explanation. Its good to have the SQL tested thru QMF/SPUFI with fetch 1 or 2 rows to take an initial shot with the SQL. Thanks
Back to top
View user's profile Send private message
Pknair
Beginner


Joined: 29 Nov 2005
Posts: 26
Topics: 9

PostPosted: Mon Mar 13, 2006 4:48 pm    Post subject: Reply with quote

Hi Kolusu/Suresh

My uderstanding is that an OPEN cursor statement will materialise the CURSOR sql statements(This is when the indexes are used), does it not mean that a Fetch should only read these records from the buffer.

In this case the OPEN is successfull but it clocks in Fetch. Which means that the records have already been retrieved from the respective tables but the reading of the records from the materialised cursor is clocking.

Please help...
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Mar 13, 2006 7:07 pm    Post subject: Reply with quote

Pknair,

Our onsite DBA will be better person to answer your question as he has all the information needed. Did you try to contact him?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
issac1029
Intermediate


Joined: 10 Dec 2005
Posts: 159
Topics: 75

PostPosted: Tue Mar 14, 2006 7:45 am    Post subject: Reply with quote

What will be happen if you want to fetch 10 rows,but there are only 9 row in condition?
Back to top
View user's profile Send private message Send e-mail MSN Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Tue Mar 14, 2006 8:46 am    Post subject: Reply with quote

Quote:

What will be happen if you want to fetch 10 rows,but there are only 9 row in condition?


It will just fetch the available 9 rows.

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Pknair
Beginner


Joined: 29 Nov 2005
Posts: 26
Topics: 9

PostPosted: Mon Apr 03, 2006 2:44 pm    Post subject: Reply with quote

I did a little bit of research and got the following. The SQL's in the CURSOR are not fully materialised when an OPEN CURSOR statement is executed. It is only done on or before the first FETCH statement.

So even if it traverses the OPEN statement quickly it could get hung up on the first FETCH statement.

Thank you everyone for your answers. It was educative
Pknair
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