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 

performance tuning for sql query

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


Joined: 12 May 2006
Posts: 10
Topics: 6
Location: india

PostPosted: Mon Aug 27, 2007 1:40 pm    Post subject: performance tuning for sql query Reply with quote

hi

i have one Sql query i need to improve the performance of the query
Code:

SELECT I_REQ_SRV, I_TYP_REQ_SRV, T_CTE_TRG, T008 .         
         I_RSN, T004 . I_STA, I_PRI, I_TO_ASN, I_LCK, T004 .                   
         I_DOM_UDT_RCD, T004 . I_UDT_RCD, T004 . T_UDT_RCD,                     
         I_DOM_UDT_LST_IFO, I_UDT_LST_IFO, T_UDT_LST_IFO, T004 .               
         T_CRT_RCD FROM VCCM904A_STA_DSC T904, VCCM004A_SRV_REQ T004,           
         VCCM008A_RSN_ASN T008, VCCM909A_RSN T909 WHERE T004 . I_STA =         
         T904 . I_STA                                                           
         AND T904 . N_STA IN ( 'Open', 'Pending' )                             
         AND I_TO_ASN = : H : H                                                 
         AND ( : H : H IS NULL                                                 
         OR T_CTE_TRG < : H : H )                                               
         AND C_ASN = 1                                                         
         AND T008 . C_TYP_OWR = 'SERVICEREQUEST'                               
         AND T004 . I_REQ_SRV = T008 . I_OWR                                   
         AND T008 . I_RSN = T909 . I_RSN                                       
         AND T909 . I_CAT_RSN = 1                     


how i can improve the performance of the query

your thoughts on this are appreciated
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon Aug 27, 2007 1:50 pm    Post subject: Reply with quote

rameshb,

We need more information on the indexes to be able to help you. Also post your sql so that it is readable and easily understandable

ex : like
Code:

SELECT I_REQ_SRV
      ,I_TYP_REQ_SRV
      ,T_CTE_TRG
      ,T008.I_RSN
      ,T004.I_STA
      ,I_PRI
      ,I_TO_ASN
      ,I_LCK
      ,T004.I_DOM_UDT_RCD
      ,T004.I_UDT_RCD
      ,T004.T_UDT_RCD
      ,I_DOM_UDT_LST_IFO
      ,I_UDT_LST_IFO
      ,T_UDT_LST_IFO
      ,T004.T_CRT_RCD
 FROM VCCM904A_STA_DSC T904
     ,VCCM004A_SRV_REQ T004
     ,VCCM008A_RSN_ASN T008
     ,VCCM909A_RSN     T909
WHERE T004.I_STA     =    T904 . I_STA
  AND T904.N_STA IN  ( 'Open', 'Pending' )
  AND I_TO_ASN       = :H : H
  AND (:H :H IS NULL OR T_CTE_TRG < : H : H )
  AND C_ASN          = 1
  AND T008.C_TYP_OWR = 'SERVICEREQUEST'
  AND T004.I_REQ_SRV = T008.I_OWR
  AND T008.I_RSN     = T909.I_RSN
  AND T909.I_CAT_RSN = 1


Quote:
AND (:H :H IS NULL OR T_CTE_TRG < : H : H )


what exactly you want to check with that statement?

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


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Aug 27, 2007 1:57 pm    Post subject: Reply with quote

To add to Kolusu's list of 'what in the world is this?', what do you mean by
Quote:
AND I_TO_ASN = :H : H


You can NOT set a host variable to NULL as in
Quote:
AND (:H :H IS NULL OR T_CTE_TRG < : H : H )
and attempt to use it in a predicate.
Binary zeroes in a host variable are not the same as a DB2 NULL.
nor does the usage of a host variable NULL indicator set to -1 = a DB2 NULL.

The NULL predicate is only valid against a COLUMN.

Have you run EXPLAIN?

Have you tried to execute this? or pre-compile or bind it?

What version of DB2 are you using? and on what platform?

anyway, those are my thoughts.

edited several times by dbz in an attempt to make it a positive post
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
rameshb
Beginner


Joined: 12 May 2006
Posts: 10
Topics: 6
Location: india

PostPosted: Mon Aug 27, 2007 2:48 pm    Post subject: Reply with quote

i am sorry the query looks like this
Code:

SELECT I_REQ_SRV                               
       ,I_TYP_REQ_SRV                           
       ,T_CTE_TRG                               
       ,T008.I_RSN                               
       ,T004.I_STA                               
       ,I_PRI                                   
       ,I_TO_ASN                                 
       ,I_LCK                                   
       ,T004.I_DOM_UDT_RCD                       
       ,T004.I_UDT_RCD                           
       ,T004.T_UDT_RCD                           
       ,I_DOM_UDT_LST_IFO                       
       ,I_UDT_LST_IFO                           
       ,T_UDT_LST_IFO                           
       ,T004.T_CRT_RCD                           
       ,T008.I_RSN_SUB                           
             ,T008.X_DSC_RSN                           
 FROM   VCCM904A_STA_DSC T904                     
       ,VCCM004A_SRV_REQ T004                     
       ,VCCM008A_RSN_ASN T008                     
       ,VCCM909A_RSN     T909                     
 WHERE   T004.I_STA = T904.I_STA                 
 AND     T904.N_STA IN ('Open','Pending')         
 AND     I_TO_ASN = V_I_TO_ASN                   
 AND    (V_T_CUTOFF_DATE IS NULL                 
 OR      T_CTE_TRG < V_T_CUTOFF_DATE)             
 AND     C_ASN = 1                               
 AND     T008.C_TYP_OWR = 'SERVICEREQUEST'       
 AND     T004.I_REQ_SRV = T008.I_OWR             
 AND     T008.I_RSN     = T909.I_RSN             
 AND     T909.I_CAT_RSN = 1                       
 ;
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon Aug 27, 2007 2:56 pm    Post subject: Reply with quote

Rameshb,

bonk bonk bonk try answering the other questions posted by me and dbz
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Aug 27, 2007 3:10 pm    Post subject: Reply with quote

rameshb,

OK, it is a four table join. You need an EXPLAIN.
The construct of the 4 tables and relationships between the 4 tables is only something that you know. You are the only one that knows what indexes exist.

Indexes, size of tables, the join types - only an EXPLAIN can tell you that.
Is Visual Explain available on your DB2 release? (which version of db2 are you on?).

There are all kinds of things that can be done, maybe. It depends.
Is this SQL imbedded in an application or is it a Stored Procedure?
Is this for online or batch?
How often is it executed?
How long is it taking now? (yeah, I know, too long....)
How big is the box - what type - what OS - what else is running in the DB2 space?

try to answer a few of these questions. Important questions to answer are:
Online or batch
Imbedded or Stored Procedure
Frequency
Info on your box (computer).
VSN of DB2!!!!!!!!!!

I am not avoiding your question. I (nor anyone else) have any idea where to start with suggestions.

Need more info!!!
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
rameshb
Beginner


Joined: 12 May 2006
Posts: 10
Topics: 6
Location: india

PostPosted: Mon Aug 27, 2007 4:29 pm    Post subject: Reply with quote

Hi kolusu,


V_I_TO_ASN ,

V_T_CUTOFF_DATE


input variables to the Stored procedure


we are trying to insert using this sql into temporary table

there are no indexes on any of the the tables


any more info needed please let me know
Back to top
View user's profile Send private message
Luc Orient
Beginner


Joined: 30 Apr 2006
Posts: 15
Topics: 4
Location: Paris - France

PostPosted: Mon Aug 27, 2007 4:34 pm    Post subject: Reply with quote

In general in a join of 2 or more tables, the columns that are to be joined must be indexed ...

Of course, it's a general idea ...

As mentionned, it would be better to have the result of an EXPLAIN of your query (the PLAN_TABLE if you prefer ...)
Back to top
View user's profile Send private message
Luc Orient
Beginner


Joined: 30 Apr 2006
Posts: 15
Topics: 4
Location: Paris - France

PostPosted: Mon Aug 27, 2007 4:44 pm    Post subject: Reply with quote

rameshb wrote:
... there are no indexes on any of the the tables ...

It's very strange ... even for PRIMARY_KEYS ?

Is it possible to create index on your tables ?
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Aug 27, 2007 11:57 pm    Post subject: Reply with quote

rameshb,

Though the following may sound like nagging, lack of information prohibits any type of productive suggestions. Like coding in COBOL, a good habit is to 'Fully qualify all references'. The four way implicit JOIN could possibly be optimized with different JOIN syntax or sub-selects. But, we have no idea which table contains these columns:

I_REQ_SRV
I_TYP_REQ_SRV
T_CTE_TRG
I_PRI
I_TO_ASN
I_LCK
I_DOM_UDT_LST_IFO
I_UDT_LST_IFO
T_UDT_LST_IFO

and in the where clause, the following is impossible to attempt to optimize:
C_ASN
I_TO_ASN
V_I_TO_ASN

So, full column qualification along with answers to the following will help us in providing some productive suggestions:

1. Are all four of these tables temporary?
2. what is the expected row count of each table?
3. What SQL was used to populate the temporary table(s)?
4. Are all predicate columns of the same datatype?

I realize that this seems like a great volume of info to provide, but there is more. You mentioned inserting?

Also, a general flow of the Stored Procedure would help. Does not make sense to optimize only part of the SP.

What language is the SP? is this SPL?

Good morning, by the way.
_________________
Dick Brenholtz
American living in Varel, Germany
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