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 

Help in fine tunning a SQL query using Joins and Like

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


Joined: 05 Jan 2006
Posts: 43
Topics: 14

PostPosted: Tue Nov 14, 2006 1:09 pm    Post subject: Help in fine tunning a SQL query using Joins and Like Reply with quote

Hi,

we have query some thing like below
Code:

Select D.PERM_ADDR_STATE_CD                           
      ,CUS.BIRTH_DT                                   
      ,CUS.TAX_ID                                     
      ,D.PERM_ADDR_ZIP_CD                             
      ,D.PERM_ADDR_CITY_NM                           
      ,CUST_FULL_NM                                   
 FROM  MUS.TUZ42 AS C INNER JOIN
       MUS.TUZ49 AS D ON       
       C.CUST_ID = D.CUST_ID JOIN             
       MUS.TUZ43 AS CUS ON         
       C.CUST_ID    = CUS.CUST_ID AND           
       CUS.RCPT_DT  = C.RCPT_DT               
 WHERE C.RCPT_DT    = :RCPT-DT                   
   AND CUST_FULL_NM LIKE :CUST-FULL-NM
   AND C.AMPF_STA_CD = '1'       




We need to fetch all the record from the database where ever the customer name is like the required feild.
The customer name is 27 charecters in the databas and the CUST-FULL-NM is 10 charecter length.
we are adding the rest of the length in the CUST-FULL-NM as '%"

The data Present in this table is around 5 million recors. The query runs of around 20 hours due to the LIKE In the query

Please help me if you have any better solution than like in the query

Thanks
Manoj Voona
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Nov 14, 2006 1:36 pm    Post subject: Reply with quote

manojvoona,

2 Joins and a Like parameter will dent your performance. You need to re-design your logic.

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


Joined: 05 Jan 2006
Posts: 43
Topics: 14

PostPosted: Tue Nov 14, 2006 2:02 pm    Post subject: Reply with quote

Thanks a lot Kolusu.

We really appreciate if you could let us know how we can redesign it.

-Manoj voona
Back to top
View user's profile Send private message Send e-mail
dbzTHEdinosauer
Supermod


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

PostPosted: Tue Nov 14, 2006 2:55 pm    Post subject: Reply with quote

how about removing all that join logic and defining a simple cursor (with the like) and then do singleton selects for the other two tables based on data returned by the fetch.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
manojvoona
Beginner


Joined: 05 Jan 2006
Posts: 43
Topics: 14

PostPosted: Tue Nov 14, 2006 4:39 pm    Post subject: Reply with quote

Thanks a lot.

Does the total execution time for breaked up query may take same time as of the above query? this is because the record count is same and the database tables are same.

Please do mind if the its foolish questions, I am new to DB2.

Thanks
Back to top
View user's profile Send private message Send e-mail
dbzTHEdinosauer
Supermod


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

PostPosted: Tue Nov 14, 2006 4:51 pm    Post subject: Reply with quote

my experience with huge (million or more) joins is that the simple cursor and singleton selects are faster, mainly because not so much DB2 resource (space) is used up building interm tables, sorting and then createing a result table.
_________________
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