SQL Query takes lot of time

Reply

Join Date: Jan 2009
Posts: 21
Reputation: rak4u is an unknown quantity at this point 
Solved Threads: 0
rak4u rak4u is offline Offline
Newbie Poster

SQL Query takes lot of time

 
0
  #1
Jun 29th, 2009
Hi evrybody,

My sql SP takes around two to three minutes which is quite long time to execute
the SP select data from three tables publicity(29000 row) publicitysubject(29000 row) & lookuptable(50 rows)

all three tables have clustered index How can i reduce the time

  1.  
  2. USE [ReadWorthyPublication]
  3. GO
  4. /****** Object: StoredProcedure [dbo].[RW_SP_GET_PUBLICITY_DETAIL] Script Date: 06/29/2009 15:03:28 ******/
  5. SET ANSI_NULLS ON
  6. GO
  7. SET QUOTED_IDENTIFIER ON
  8. GO
  9.  
  10.  
  11.  
  12.  
  13. CREATE PROC [dbo].[RW_SP_GET_PUBLICITY_DETAIL]
  14. (
  15. @vParty_Name VARCHAR(200) = NULL,
  16. @iCategory_ID INT= NULL,
  17. @vCity VARCHAR(100) = NULL,
  18. @iCountry_ID INT = NULL,
  19. @iSubject_ID INT = NULL,
  20. @iPublicity_ID INT = NULL,
  21. @vAddress VARCHAR(200) = NULL,
  22. @bActive BIT = NULL
  23.  
  24. )
  25. AS
  26. BEGIN
  27. BEGIN TRY
  28. SELECT PT.Publicity_ID,
  29. PT.Party_Name,
  30. LT.Lookup_ID [Publicity_Category_ID],
  31. LT.Lookup_Item [Publicity_Category_Type],
  32. CT.Country_ID,
  33. CT.Country_Name,
  34. PT.Address,
  35. PT.City,
  36. PT.Phone,
  37. PT.Fax,
  38. PT.Active,
  39. PT.Web_Address,
  40. PT.Email,
  41. PST.Subject_ID
  42.  
  43. FROM [dbo].[Publicity_Table] PT WITH (NOLOCK)
  44. INNER JOIN [dbo].[Country_Table] CT WITH (NOLOCK)
  45. ON PT.Country_ID = CT.Country_ID
  46. INNER JOIN [dbo].[Lookup_Table] LT WITH (NOLOCK)
  47. ON PT.Category_Type_ID = LT.Lookup_ID
  48. INNER JOIN [dbo].[PublicitySubject_Table] PST WITH (NOLOCK)
  49. ON PT.Publicity_ID = PST.Publicity_ID
  50. WHERE ((@vParty_Name IS NULL) OR (PT.Party_Name LIKE '%'+@vParty_Name+'%'))
  51. AND ((@iCategory_ID IS NULL) OR (PT.Category_Type_ID = @iCategory_ID))
  52. AND ((@vCity IS NULL) OR (PT.City LIKE '%' + @vCity + '%'))
  53. AND ((@iCountry_ID IS NULL) OR (PT.Country_ID = @iCountry_ID))
  54.  
  55. AND ((@iSubject_ID IS NULL) OR (PST.Subject_ID = @iSubject_ID))
  56. AND ((@iPublicity_ID IS NULL) OR (PT.Publicity_ID = @iPublicity_ID))
  57. AND ((@vAddress IS NULL) OR (PT.Address LIKE '%' + @vAddress + '%'))
  58. AND ((@bActive IS NULL) OR (PT.Active = @bActive))
  59. ORDER BY PT.Publicity_ID
  60.  
  61.  
  62. END TRY
  63. BEGIN CATCH
  64. EXEC dbo.RW_SP_GET_LOG_ERROR_INFO 'Expense_Table'
  65. END CATCH
  66. END
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,141
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 555
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: SQL Query takes lot of time

 
0
  #2
Jun 29th, 2009
Just because an index is clustered doesn't necessarily mean it is the best index to use. If you store a large amount of data in the tables, especially if you use varchar(max), text, or image data types, then you should probably create another nonclustered index on the joining identifiers. A clustered index will cover blob data and make the row seeking perform very slowly.

You should run the sprocs as TSQL and have the SQL Server Management Studio output an execution plan. CTLR+M = "Display actual execution plan" then save the execution plan, upload it, and i'll take a look at it.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 21
Reputation: rak4u is an unknown quantity at this point 
Solved Threads: 0
rak4u rak4u is offline Offline
Newbie Poster

Re: SQL Query takes lot of time

 
0
  #3
Jun 30th, 2009
thanks sknake,

I am attaching the execution plan
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 21
Reputation: rak4u is an unknown quantity at this point 
Solved Threads: 0
rak4u rak4u is offline Offline
Newbie Poster

Re: SQL Query takes lot of time

 
0
  #4
Jun 30th, 2009
write some part of execution plan

1)Select cost 0%
2)Merge Join(inner join) cost 0%
3)Nested Loop(inner join) cost 11%
4)Sort 1%
5)Hash Match(inner join) 13%
6)Clustered index publicity cost 67%
7)clustered index publicitysubject 13%
8)clustered index lookup 0%
clustred index country 0%
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,141
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 555
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: SQL Query takes lot of time

 
0
  #5
Jun 30th, 2009
Please ATTACH the execution plan as a file and also post the create table () statements for your tables with the indexes. This doesn't look like a complicated fix but I'm missing information.
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC