IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Query Tuning - Help Needed


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
chinnielr

New User


Joined: 11 Jul 2005
Posts: 87

PostPosted: Mon May 31, 2010 10:05 am
Reply with quote

I tried the changed query given by ashimer.

Please find below no of records in 3 tables

No of records in ASUK – 6236353
No of records in TBLM – 61351411
No of records in ACH - 28445032

Please find below the index details.

Code:
INDEXNAME   UNIQUERULE   COLCOUNT   CLUSTERING   CLUSTERED   PGSIZE   SPACE   CLUSTERRATIO   
   UKI1UMV1         P      5           Y               Y       4096    1844640      97
   UKI1UMV2         D      5           N               N       4096    990000       92
   UKI1CON1         P      2           N               N       4096       0         0
   UKI1CON2         D      6           Y               Y       4096       0         0
   UKI1CON3         D      7           N               N       4096       0         0
   UKI1CON4         U      4           N               N       4096       0         0
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Mon May 31, 2010 3:56 pm
Reply with quote

You are dealing with tables with data in millions ... there will be performance issues ... asked for definitions of index which are used as per your explain ... try the below query too .. use the conditions on each table based on the index defined on them .. if not remove the conditions where you can improve performance.

Code:


SELECT COLS FROM
(SELECT COLS FROM ASUK
WHERE COMPANY  = 'AB'
AND CODE IN ('RRR','TRE','PRP','CON',     
                        'RRT','RRU','RRV','RRW')) AS U
,

(SELECT COLS FROM ACH
WHERE COMPANY  = 'AB'
AND CODE IN ('RRR','TRE','PRP','CON',     
                        'RRT','RRU','RRV','RRW')
AND DDATE           >= :S_DATE ) AS C

,(SELECT COLS FROM TBLM WHERE CODE
IN ('RRR','TRE','PRP','CON',     
                        'RRT','RRU','RRV','RRW')) AS M

WHERE
                                                     
M.CODE          =   U.CODE         
AND   M.UH_NBR  =   U.UH_NBR
AND   C.UH_NBR  =   U.UH_NBR


Select only those columns which are required, the idea is to reduce the number of rows required for the final join.
Back to top
View user's profile Send private message
chinnielr

New User


Joined: 11 Jul 2005
Posts: 87

PostPosted: Tue Jun 01, 2010 10:30 am
Reply with quote

Hi

Please find below the additional details of PLAN_TABLE report and index details as you requested.

Code:
QUERYNO   QBLOCKNO   PLANNO   METHOD   TNAME     
1           1           1       0     ASUK         
1           1           2       1     TBLM         
1           1           3       2     ACH         
1           1           4       3      ----             
ACCESSTYPE MATCHCOLS   INDEXONLY   SORTC_UNIQ
N           2           Y                N
I           3           N                N
I           2           Y                N
-           0           N                Y
 
SORTC_ORDERBY   TSLOCKMODE   PREFETCH   MIXOPSEQ
N                IS           --            0           
N                IS           --            0       
N                IS           --            0
Y                --           --            0

CORRELATION_NAME    PAGE_RANGE   QBLOCK_TYPE                  ACCESSNAME               
U                    Y            SELECT                       TTYNFBC3         
C                    -            SELECT                       TTYNCO4
M                    -            SELECT                       TTYNUHA1         
-                    -            SELECT                       -------


Code:
INDEXNAME   UNIQUERULE   COLCOUNT   CLUSTERING   CLUSTERED   PGSIZE   SPACE   CLUSTERRATIO        FIRSTKEYCARD              FULLKEYCARD 
   TTYNUHA1       P      5           Y               Y       4096    1844640      97              2217                  36525187
   TTYNCO4        U      4           N               N       4096       0         0                -1                      -1
   TTYNFBC3       U      6           N               N       4096      216000      94              43               


Please let me know if the information is suffice.


Code:
SELECT DISTINCT(CL_NBR) ,                   
                CL_ACC_NBR,                 
                UH_NBR,                 
                COMPANY,                 
                CON_NBR,                   
                CODE,                         
                DDATE,                         
                DTIME,                         
                NET_CONS,                 
                SL_RPC,                   
                SUB_TYPE,                     
                STATUS,                   
                AT_CODE,                         
                UNITS,                   
                RATE
FROM
(SELECT U.CL_NBR ,                   
                U.CL_ACC_NBR,                 
                U.UH_NBR,                 
                U.COMPANY

FROM ASUK
WHERE COMPANY  = 'AB'
AND CODE IN ('RRR','TRE','PRP','CON',     
                        'RRT','RRU','RRV','RRW')) AS U
,

(SELECT    CON_NBR,                   
                CODE,                         
                DDATE,                         
                DTIME,                         
                NET_CONS,                 
                SL_RPC,                   
                SUB_TYPE,                     
                STATUS,                   
                AT_CODE,                         
                UNITS,                   
                RATE     

FROM ACH
WHERE COMPANY  = 'AB'
AND CODE IN ('RRR','TRE','PRP','CON',     
                        'RRT','RRU','RRV','RRW')
AND DDATE           >= :S_DATE ) AS C

,(SELECT 1 FROM TBLM WHERE CODE
IN ('RRR','TRE','PRP','CON',     
                        'RRT','RRU','RRV','RRW')) AS M

WHERE
                                                     
M.CODE          =   U.CODE         
AND   M.UH_NBR  =   U.UH_NBR
AND   C.UH_NBR  =   U.UH_NBR


Can you please let me know whether the above query is qhat you are referring to? Also we do not select any columns from TBLM table so I have selected 1 is it fine?

Regards,
Chinni.
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Jun 01, 2010 5:09 pm
Reply with quote

Did you atleast try the query you have posted above ? If you are selecting 1 how do you plan to join M with U ?
No more spoon feeding; try try and try until you find a good improved SQL.
If you face any difficulties ppl are here to help ; you should be doing your part too.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Mainframe Programmer with CICS Skill... Mainframe Jobs 0
Search our Forums:

Back to Top