SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Why the difference in query execution times?


Why the difference in query execution times?

Author
Message
p_shaw
p_shaw
Grasshopper
Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)Grasshopper (20 reputation)

Group: General Forum Members
Points: 20 Visits: 37
I have this query:

UPDATE invoice
SET actual_membernumber = members.mbrnbr,
vin = members.vin
FROM Network_Transaction invoice (nolock)
CROSS APPLY
(
SELECT clientindex, lname, fname, mbrnbr, vin FROM vw_ActiveMembers members (nolock)
WHERE members.clientindex = invoice.client_id
) AS members
INNER JOIN erm_claimsdata c (nolock) ON c.clientid = members.clientindex
WHERE invoice.transaction_type = 'I'
AND (@filename is null OR invoice.filename = @filename)
AND (@client_id is NULL OR client_id = @client_id)
AND invoice.deletedflag = 0
AND invoice.exportedflag = 0
AND invoice.last_eight_vin is not null
AND invoice.actual_membernumber is null
AND members.vin LIKE '%' + invoice.last_eight_vin

if I run it in SSMS it takes about 8 minutes, but when the same query is executed in a stored proc it takes 5 hours...sometimes longer before I kill the session. What could possibly cause this? This is on SQL Server 2005. Thanks
Sean Lange
Sean Lange
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64782 Visits: 17979
This is very likely to be parameter sniffing.

http://sqlinthewild.co.za/index.php/2007/11/27/parameter-sniffing/

Your query itself also appears to have some of the performance issues discussed in the "catch-all" queries article.

http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/

Last but not least, be VERY careful with those NOLOCK hints. They are very dangerous. As this looks like some sort of claims system you need to fully understand what that hint does and the nasty things it brings to the table.

http://sqlblog.com/blogs/andrew_kelly/archive/2009/04/10/how-dirty-are-your-reads.aspx

http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
TheSQLGuru
TheSQLGuru
SSC-Dedicated
SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)SSC-Dedicated (33K reputation)

Group: General Forum Members
Points: 33335 Visits: 8681
The dreaded IS NULL OR construct is the root issue here. Fix it per Sean's link. Those simply MUST NOT BE ALLOWED ON YOUR SYSTEM - EVER! :-)

Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search