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


sp VS adhoc query peformance?


sp VS adhoc query peformance?

Author
Message
dufus
dufus
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 149
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.



Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)

Group: General Forum Members
Points: 94159 Visits: 33010
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 Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Matt Miller (4)
Matt Miller (4)
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28064 Visits: 18997
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?
Adam Bean
Adam Bean
SSCertifiable
SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)

Group: General Forum Members
Points: 6234 Visits: 2222
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.
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)

Group: General Forum Members
Points: 94159 Visits: 33010
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 Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
dufus
dufus
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 149
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?



Adam Bean
Adam Bean
SSCertifiable
SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)SSCertifiable (6.2K reputation)

Group: General Forum Members
Points: 6234 Visits: 2222
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.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (212K reputation)SSC Guru (212K reputation)SSC Guru (212K reputation)SSC Guru (212K reputation)SSC Guru (212K reputation)SSC Guru (212K reputation)SSC Guru (212K reputation)SSC Guru (212K reputation)

Group: General Forum Members
Points: 212867 Visits: 46259
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, MVP, M.Sc (Comp Sci)
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


Ian Yates
Ian Yates
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4422 Visits: 445
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?



TheSQLGuru
TheSQLGuru
SSC-Dedicated
SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)

Group: General Forum Members
Points: 30655 Visits: 8668
>>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 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