Page 1 of 1

Hoe to reduce the Query running time

PostPosted: Fri Jul 01, 2011 7:05 pm
by shyamsaravan
Hi;

I have pasted the codes below is the Stored Procedure and the values feed from the Front-end screen to the DB2 StroedProc and fetching the values from the DB2 tables,.The question is why do this query taking more than 30 minutes to display the result...the datas are also somewhat 50k records

SELECT                   
     DISTINCT             
       sam.Place 
     , sam.NO_mode_name
     , sam.NO_mob_name 
     , sam.NO_disp_name
     , sam.NO_rate_type
     , sam.ran_date
     , sam.NO_pers_CNTL   
FROM                                               
    cus_frt_tab   sam,                           
    Pen_tab       ben                           
WHERE
                                             

    (sam.NO_mob_name   BETWEEN :WS-ALL-mob-LOW   
                            AND  :WS-ALL-mob-HIGH)
AND (sam.NO_mode_name BETWEEN :WS-ALL-mode-LOW   
                            AND  :WS-ALL-mode-HIGH)
AND (sam.NO_disp_name BETWEEN :WS-ALL-disp-LOW   
                            AND  :WS-ALL-disp-HIGH)

AND sam.NO_rate_type      IN ( :LT-DEL ,     
                                  :LT-INS ,       
                                  :LT-UPD  )     

 AND DATE (sam.ran_date)                       
                          BETWEEN :WS-START-DT
                             AND  :WS-END-DT

 AND                                                 
     (                                               
     (:WS-ALL-DISTR  =  :LT-ALL)    OR           
     ( sam.PLACE           IN  (:DISTR01,         
                                :DISTR02,         
                                :DISTR03,         
                                :DISTR04,         
                                :DISTR05)  )                                         
             )                                         

         AND                                           
             (                                         
             (:WS-ALL-CUS   =  :LT-ALL)  OR         
             (BEN.CD_CONSUMER IN    (:CONS01,         
                                      :CONS02,         
                                      :CONS03,         
                                      :CONS04,         
                                      :CONS05)  )             
             )                                                 

         AND  sam.NO_mob_name   =  ben.NO_mob_name     
         AND  sam.NO_mode_name  =  ben.NO_mode_name       
         AND  sam.NO_disp_name  =  ben.NO_disp_name     
         AND  sam.NO_pers_CNTL  =  ben.sam.NO_pers_CNTL   

         ORDER BY                                             
              sam.Place                           
             ,sam.NO_mode_name                             
             ,sam.NO_mob_name                             
             ,sam.NO_disp_name                           
             ,sam.NO_pers_CNTL                              
             ,sam.Phy_TYPE                             
             ,sam.DT_IN      DESC             


Cobol Declaration

05  WS-ALL-mob-LOW          PIC X(09)  VALUE SPACES.
05  WS-ALL-mob-HIGH         PIC X(09)  VALUE SPACES.
05  WS-ALL-mode-LOW          PIC X(07)  VALUE SPACES.
05  WS-ALL-mode-HIGH         PIC X(07)  VALUE SPACES.
05  WS-ALL-disp-LOW          PIC X(08)  VALUE SPACES.
05  WS-ALL-disp-HIGH         PIC X(08)  VALUE SPACES.

 05  LT-DEL               PIC X(06) VALUE "DELETE".
 05  LT-INS               PIC X(06) VALUE "INSERT".
 05  LT-UPD               PIC X(06) VALUE "UPDATE".

 05  LT-ALL                  PIC X(01) VALUE "#".

05  WS-START-DT       PIC X(10)  VALUE SPACES.
05  WS-END-DT         PIC X(10)  VALUE SPACES.

05  WS-ALL-DISTR         PIC X(01)  VALUE SPACES.
05  WS-ALL-CUS         PIC X(01)  VALUE SPACES.

 05  WS-DISTR-LIST.                                 
     10  DISTR01           PIC X(05)  VALUE SPACES.
     10  FILLER               PIC X(01)  VALUE SPACES.
     10  DISTR02           PIC X(05)  VALUE SPACES.
     10  FILLER               PIC X(01)  VALUE SPACES.
     10  DISTR03           PIC X(05)  VALUE SPACES.
     10  FILLER               PIC X(01)  VALUE SPACES.
     10  DISTR04           PIC X(05)  VALUE SPACES.
     10  FILLER               PIC X(01)  VALUE SPACES.
     10  DISTR05           PIC X(05)  VALUE SPACES.

05  WS-CONS-CODES.                                 
    10  CONS01              PIC X(04)  VALUE SPACES.
    10  FILLER               PIC X(01)  VALUE SPACES.
    10  CONS02              PIC X(04)  VALUE SPACES.
    10  FILLER               PIC X(01)  VALUE SPACES.
    10  CONS03              PIC X(04)  VALUE SPACES.
    10  FILLER               PIC X(01)  VALUE SPACES.
    10  CONS04              PIC X(04)  VALUE SPACES.
    10  FILLER               PIC X(01)  VALUE SPACES.
    10  CONS05              PIC X(04)  VALUE SPACES.


iN PROCEDURE DIVISION
;
;
MOVE  LINK-DISTR-TEXT TO  WS-DISTR-LIST
                                WS-ALL-DISTR
                                               
MOVE  LINK-CONS-LIST        TO  WS-ALL-CONS   
                                WS-CONS-CODES 
                                               
IF  WS-ALL-CONS  =  LT-ALL                   
    MOVE  SPACES  TO  WS-CONS-CODES           
ELSE                                           
    UNSTRING                                   
        LINK-CONS-LIST                         
                DELIMITED BY  ','                 
        INTO                                   
          CONS01,                             
          CONS02,                             
          CONS03,                             
          CONS04,
          CONS05
      END-UNSTRING
 END-IF     


Please help me what are possibilites to reduce the Query running time....and let me know that, is delaying the running time if we used the BETWEEN and OR in the Query

Re: Hoe to reduce the Query running time

PostPosted: Fri Jul 01, 2011 7:32 pm
by GuyC
info we need require:

the minimum :
* available indexes ? primary keys ?

extra :
* explain info ?
* column cardinalities

Re: Hoe to reduce the Query running time

PostPosted: Fri Jul 01, 2011 8:22 pm
by BillyBoyo
I've made a little change to part of your code. I don't know if this is part of your problem, but if you can have a variable number of items in the LINK-CONS-LIST then you might be using values from the previous execution of the UNSTRING when there are fewer items this time.

                   
* Initialise all conscodes to space to ensure that any prior values are not used by accident, or for the LT-ALL request, where they should all be space.

MOVE  SPACES  TO  WS-CONS-CODES           
     
IF  WS-ALL-CONS  NOT EQUAL TO  LT-ALL                                     
    UNSTRING                                   
        LINK-CONS-LIST                         
                DELIMITED BY  ','                 
        INTO                                   
          CONS01,                             
          CONS02,                             
          CONS03,                             
          CONS04,
          CONS05
      END-UNSTRING
END-IF

Re: Hoe to reduce the Query running time

PostPosted: Fri Jul 08, 2011 5:26 pm
by shyamsaravan
Thanks for the reply;

The above changes does not reflect big difference in the query running time.We used 'place' as a primary key..
Can you please suggest another way.?
If the LINK-DISTR-TEXT value is # means it will show all the records which are related to the given LINK-CONS-LIST.
If the LINK-CONS-LIST value is # means it will show all the records which are related to the given LINK-DISTR-TEXT.

Re: Hoe to reduce the Query running time

PostPosted: Fri Jul 08, 2011 10:53 pm
by BillyBoyo
info we need require:

the minimum :
* available indexes ? primary keys ?

extra :
* explain info ?
* column cardinalities


GuyC asked you for the above information. Mine was just a suggestion to get the Cobol code correct. If you do five, then four, you'll have one left over from the five, with your original code.

Re: Hoe to reduce the Query running time

PostPosted: Mon Jul 25, 2011 3:36 pm
by shyamsaravan
How to view the Table has Primary keys and indexes in QMF?

Re: Hoe to reduce the Query running time

PostPosted: Mon Jul 25, 2011 11:33 pm
by dick scherrer
Hello,

Suggest you talk with your dba or some co-worker.

You can get what you want with simple queries using spufi and have no need for qmf to just see the key/index definitions.

You might also look at the CREATE statements for these. . . .

Re: Hoe to reduce the Query running time

PostPosted: Tue Oct 11, 2011 1:01 am
by rahuldba
Ask ur DBA to do an explain of the query in the region.Before running explain make sure that runstats are done for the following tables.when the explain is done DBA can come up with suggestions like creating indexes or changing the query..or other reasons.Since ur joining tables so data in talbles as well as indexes be there for joining columns.basically we need explain output to determine what to do next.Aslo all indexes created on tables would be needed.