Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created one store procedure which is taking too much time compile but when i ran same query within stored procedure separately it gets executed with in seconds. I am not able to find the reason behind that. Please help me out what will be the problem behind that. It is very helpful for me. Thanks in advance.
Posted
Comments
DamithSL 5-Jun-15 2:50am    
can you explain the testing steps for both in detail?
Tomas Takac 5-Jun-15 3:16am    
Did you check the query plans? Maybe a wrong one is cached for the SP.
OriginalGriff 5-Jun-15 3:58am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
We need to know how you are executing the two queries for comparison, what code if any you are using, how you are timing them. At the moment, you have called the garage, said "my car is slow sometimes" and put the phone down. The garage needs to know if it's when you are going up hill, or it's very cold - or very hot, if you are towing a caravan, etc.

Use the "Improve question" widget to edit your question and provide better information.

I'm assuming you're using SQL Server here.
When you have different execution times in different environments it's usually the plan cache that's the culprit.
For a better understanding I'll refer you to an article[^] by the real SQL Server Guru, Erland Sommarskog.
 
Share this answer
 
Hi,

I have faced this issue many times. If u execute the same query many times then SQL will return the query result from cache. So it will provide fast result.

Please use below lines before executing your query.

SQL
CHECKPOINT;
GO
DBCC DROPCLEANBUFFERS;
GO



That will remove the cache and provide you the fresh result.

I believe your query will take the same time as your stored procedure.

Please let me know if you have any concern or query on this.

Thanks
Advay Pandya
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900