Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

sp VS adhoc query peformance? Expand / Collapse
Author
Message
Posted Thursday, February 7, 2008 12:28 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, March 6, 2014 8:31 AM
Points: 31, Visits: 91
I have a issue i am struggling with. I have a sp that returns 1700 records in about 1 minute but when i run the same exact sql in an adhoc query it takes on 5 seconds?

I declare a table variable for a summary table, load the table then join the results with 4 other tables. It doesn't seem to be anything out the ordinary but the sp will timeout when running via the applcation.

I seem to be just banging my head against the wall at this point! Any assistance is appreciated.



Post #452898
Posted Thursday, February 7, 2008 1:29 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 5:59 PM
Points: 15,735, Visits: 28,141
Does your table variable have a primary key and is that used to join to the other tables? If not, that's going to be a performance problem right there since table variables don't maintain statistics. You may want to switch to a temporary table instead.

If it's an ad hoc query you may be seeing recompiles. Have you watched the execution through profiler?


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #452930
Posted Thursday, February 7, 2008 1:47 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 3:13 PM
Points: 7,156, Visits: 15,255
It seems rather extreme - but could it be parameter sniffing?

Ken Henderson (you will be missed) described it rather well here:

http://blogs.msdn.com/khen1234/archive/2005/06/02/424228.aspx


----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Post #452937
Posted Thursday, February 7, 2008 2:33 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, June 16, 2014 6:53 AM
Points: 1,145, Visits: 1,932
I wonder if the procedure hasn't recompiled since your last change and is using an old execution plan? Might want to try doing a freeproccache for s&g's ...

Regardless, have you looked at the execution plan with the procedure and compared it to the execution plan when running it via TSQL?


---
SQLSlayer
Making SQL do what we want it to do.

Post #452968
Posted Thursday, February 7, 2008 7:42 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 5:59 PM
Points: 15,735, Visits: 28,141
And, check your connection settings. See if the TSQL connection & the ADO connection are the same.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #453040
Posted Friday, February 8, 2008 9:01 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, March 6, 2014 8:31 AM
Points: 31, Visits: 91
Thanks for all your responses.

This issue appears to be wide spread and happening on several stored procedures. Now even my adhoc queries are taking extremely long time to return results.

Just a little background, we just moved several dB's to production from our test. Both environments are sql server 2005. We did not have any issues in the test environment.

I am far from a DBA, but I have never encountered these performance issues from copying stored procedures from one server to anohter.

Has anyone heard of any issues similar to this?



Post #453306
Posted Friday, February 8, 2008 9:08 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, June 16, 2014 6:53 AM
Points: 1,145, Visits: 1,932
First and foremost, you need to look at your execution plans ... your problem could be one of MANY things at this point.

Run your query in query analyzer/management studio, with execution plan turned on. You'll get a new output tab showing the execution plan. Look for the highest percentages used from step to step to start determining where the most resources are used.


---
SQLSlayer
Making SQL do what we want it to do.

Post #453311
Posted Sunday, February 10, 2008 5:42 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:29 AM
Points: 43,022, Visits: 36,182
Check the sys.dm_exec_requests DMV. What are the long running queries waiting on?

Have you rebuilt indexes recently?

Does recompiling the procedure make any difference? (EXEC sp_recompile 'StoredProcName')



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #453639
Posted Sunday, February 10, 2008 6:22 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, January 30, 2014 10:08 PM
Points: 1,038, Visits: 444
Silly question, but how much more data do you have in production compared to your test environment? Is your test data obviously fake test data such as lots of similar names, etc?


Post #453640
Posted Monday, February 11, 2008 7:33 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 3:07 PM
Points: 4,356, Visits: 6,189
>>Has anyone heard of any issues similar to this?

Yeah, we all have! ) The problem is that the potential causes are quite numerous. Even without knowing your code or data structures or data distributions I could probably rattle off 15 or 20 different possibles. In situations like this there is no substitute for experience - it's gonna be a painful process going back and forth via forum posts. Don't suppose you have a DBA at work you can hit up? 10-20 minutes of their time (if that) online with you data should be all it takes to isolate the cause.


Best,

Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru at GMail
Post #454195
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse