Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

What is SQL Server commands to clear caches before running a performance comparison?

Asked by Carl Paige Jul 19, 2021 1.7K views 1 answer
Share

About this question

When comparing the execution time of two different queries, it's important to clear the cache to make sure that the execution of the first query does not alter the performance of the second. In a Google Search, I could find these commands: DBCC FREESYSTEMCACHE DBCC FREESESSIONCACHE DBCC FREEPROCCACHE In fact, my queries are taking a more realistic time to complete after several executions than before. However, I'm not sure this is the recommended technique. What's the best practice? How sql server clear cache? Remove all elements from the plan cache for the entire instance. DBCC FREEPROCCACHE; Use this to clear the plan cache carefully. Freeing the plan cache causes, for example, a stored procedure to be recompiled instead of reused from the cache. Personally, for a common query the 2nd and subsequent executions matter more. Are you testing disk IO or query performance? Assuming your query runs often and is critical, then you want to measure that under real life conditions. And you don't want to clear prod server caches each time... If you want, you can:


Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.