When I am testing a query I will typically drop the following lines in front of whatever i am testing to make sure I'm starting from the same baseline every time i run a query.
CHECKPOINT
GO
DBCC FREEPROCCACHE
GO
DBCC DROPCLEANBUFFERS
GO
EXEC sp_MyProc 12345
On the Stored proc i was running today i noticed that when I ran it with these lines it took aproximately 18 minutes everytime. When I left these lines off it only took 3. Seeing the drastic difference caused by having a cleared cache vs a primed cache i decided to add the following to see if I could manually prime the cache before running my proc and see what that did to performance.
CHECKPOINT
GO
DBCC FREEPROCCACHE
GO
DBCC DROPCLEANBUFFERS
GO
SELECT top 1 '1' from Table1
EXEC sp_MyProc 12345
As you may have guessed sp_MyProc
uses Table1
quite a bit. I was surprised to find that doing this took my run time down to about 6 minutes consistently. Although it does improve the performance it looks a little hackish, and I'm curious if there is something built into SQL Server that will accomplish this.
- Is doing this to improve the performance of your queries unheard of?
- Am i even right to assume that the improvement in time that I saw was a result of a "Primed" cache?
If my understanding of Caching is a bit off please feel free to share any links or info you think might be helpful.
UPDATE: Well I'm embarrassed to say that I tried to reproduce this behavior today, but was unable to. I spoke with some people at my work and it looks like some of the stuff they were doing on the DB yesterday may have made it appear as if my select before the proc was improving performance when in fact it wasn't. I'd still be interested to hear if anyone knows if "priming" the cache is possible through.