Query on Multi row fetch CPU time performance improvements

Ask question on - DataBase Concepts, IBM Mainframe DB2, DB2/UDB, DB2 Tools, SQL , DB2 programming with languages like COBOL, PL1.

Moderators: Kalicharan, Moderator Group

Post Reply
MFdevlpr
Member
Posts: 2
Joined: Tue Nov 11, 2014 2:12 pm
Location: Bangalore

Query on Multi row fetch CPU time performance improvements

Post by MFdevlpr » Tue Nov 11, 2014 2:42 pm

Hi,

I had done a bit of research on Multi-row fetching in COBOL-DB2 application programs for CPU time utilization/performance improvement and tried to implement the same in my system.

There is a COBOL-DB2 batch program which reads from DB2 tables and writes into a flat file as an extract of data.
The driving cursor has UNION ALL and its a join of 3 tables. I have verified the joins and the indexes defined, all look good.

In the peak time (something like during Christmas runs) the expectation is load would be more and the job might take too long to execute.

So, I tried Multi-row fetching (with row-set 100 once, with row-set 1000 once) to reduce the CPU time.

Below is the SQL query in cursor definition:

Code: Select all

      SELECT A.Col1                     
            ,A.Col2                          
            ,A.Col3                          
            ,A.Col4                        
            ,B.Col5                     
            ,B.Col6                 
      FROM                                    
      (                                       
       SELECT C.Col1                    
             ,C.Col2                         
             ,C.Col3                         
             ,C.Col4                       
             ,MAX(C.SEQ_NO)   MAXSEQ          
       FROM                                   
      (                                       
       SELECT A.Col1                  
             ,A.Col2                       
             ,A.Col3                       
             ,A.Col4                     
             ,B.SEQ_NO                                  
        FROM  TableA A                                
             ,TableB B                                
             ,TableC C                                
        WHERE C.Col1 BETWEEN :WH-CR-PART-NO-FROM  
                         AND :WH-CR-PART-NO-TO    
          AND  C.Col1      =  A.Col1      
          AND  C.Col2      =  A.Col2           
          AND  A.Col3     >=  C.Col3           
  AND A.Col3 <= SUBSTR&#40;STRIP&#40;C.Col3&#41; || "9999",1,5&#41; 
          AND  A.Col7 <= &#58;WW-PROCESS-DATE     
          AND &#40;A.Col8 >= &#58;WW-PROCESS-DATE     
           OR  A.Col8 IS NULL&#41;                
          AND  C.Col4         =  0                   
          AND  C.SEQ_NO          =  B.SEQ_NO          
          AND  B.Col9 <= &#58;WW-WF-FORMAT-DATE   
          AND  B.ColA >= &#58;WW-WF-FORMAT-DATE   
      UNION ALL                                           
       SELECT A.Col1                             
             ,A.Col2                                  
             ,A.Col3                                  
             ,A.Col4                                
             ,B.SEQ_NO                                 
        FROM  TableA A                               
             ,TableB B                               
             ,TableC C                               
       WHERE  C.Col1 BETWEEN &#58;WH-CR-PART-NO-FROM 
                         AND &#58;WH-CR-PART-NO-TO   
         AND  C.Col1      =   A.Col1     
         AND  C.Col2      =   A.Col2          
         AND  A.Col7 <=  &#58;WW-PROCESS-DATE    
         AND &#40;A.Col8 >=  &#58;WW-PROCESS-DATE    
              OR  A.Col8 IS NULL&#41;            
         AND  C.Col4         =   A.Col4        
         AND  C.SEQ_NO       =   B.SEQ_NO         
         AND  B.Col9 <=  &#58;WW-WF-FORMAT-DATE  
         AND  B.ColA >=  &#58;WW-WF-FORMAT-DATE 
        &#41; C                                              
              GROUP BY C.Col1                      
                      ,C.Col2                           
                      ,C.Col3                           
                      ,C.Col4 &#41; A                     
           ,TableB B                                   
            WHERE B.SEQ_NO = A.MAXSEQ                    
            ORDER BY Col1                          
                    ,Col2                               
                    ,Col4                             
        FOR FETCH ONLY                                   
      WITH UR                                            

I don't see any optimization after the multi-row fetch technique.

Code CPU # of Records Processed
Old 6.61 12068688
New 6.07 12068688

Its a mere 8% improvement on CPU time. As per some books, I read that it would be at least 60% of CPU time improvement.

I am afraid if I have missed anything in the process.
Can someone help me understand what could be the reason for not having much optimization for multi-row fetch technique.

Any help would be much appreciated.

Thanks in advance.
Vinay R

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Mon Nov 17, 2014 7:32 pm

maybe because the multirow fetch only has affect on the result table,
which (by looking at the sql) is the resouce user and not the fetch.

i think that you will also find that the documentation concerning multirow fetch does little discussion of complex queries (in the sense of JOIN, UNION, subselects and host varibale usage).

have you tried running this trough an unload utility instead of a COBOL DB2 program and then parse the flat file with the host variables?

My experience with unload utilities is that the dump is so quick, that I can use a second step (COBOL or SORT) to parse the flat file and generate the desired output.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

MFdevlpr
Member
Posts: 2
Joined: Tue Nov 11, 2014 2:12 pm
Location: Bangalore

Post by MFdevlpr » Wed Nov 19, 2014 9:52 am

Hi Dick,

Thanks a lot for your reply.

As this query was a bit complex, I was trying out to improve performance without going to Sort.

The JCL with unload was already built and it was giving a better CPU performance.

To retain the readability and in the perspective of future maintenance, I had attempted to improve performance with multi-row fetch.

Seems like it won't help as much as the Unload dump and sorting does.

Thanks again for your time.

With regards,
Vinay R :lol:

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others