I need to get several queries to run in ~1-2 seconds. I've been working on optimizing them, but it takes ~20 seconds the first time any of them are called and ~1 on all subsequent calls. This is making it impossible to tell if any changes I make are speeding up the query, because it always runs in ~1 second afterwards. I'm not incredibly familiar with SQL, but from what i've been able to learn it seems like something is caching. I'm trying to figure out how to prevent this, but nothing seems to work. From what i've found off Google, people have been suggesting
DBCC FREEPROCCACHE
or
OPTION(recompile)
Neither of these seem to work though. Each query is still running in ~1 second when they took ~20 the first time. I just want to make sure the changes i'm making are causing improvements, and not that the improvements are coming from caching. Is there some other trick to do this?
DBCC FREEPROCCACHE is for the plan cache (query compilation) which is likeky to be a small gain in your query, not the page buffer data cache which is a big improvement on IO. To be consistent, you need to clear the buffer cache, after having done a checkpoint in your database, with
CHECKPOINT
DBCC DROPCLEANBUFFERS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With