Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let SQL Server know not to use Cache in Queries?

Just a general question:

Is there a query/command I can pass to SQL Server not to use cache when executing a particularly query?

I am looking for a query/command that I can set rather than a configuration setting. Is there no need to do this?

like image 276
Abs Avatar asked Dec 06 '09 23:12

Abs


People also ask

How do I remove query cache?

If you want to disable the query cache code, set query_cache_size=0. By disabling the query cache code there is no noticeable overhead. (query cache can be excluded from code with help of configure option --without-query-cache)

Does SQL Server cache queries?

The system automatically maintains a cache of prepared SQL statements (“queries”). This permits the re-execution of an SQL query without repeating the overhead of optimizing the query and developing a Query Plan. A cached query is created when certain SQL statements are prepared.

Should you cache database queries?

Cached queries provide the following benefits: Subsequent execution of frequently used queries is faster. More importantly, this performance boost is available automatically without having to code cumbersome stored procedures. Most relational database products recommend using only stored procedures for database access.

How do you clear the buffer pool in SQL Server?

By cleaning the buffer pool before each test run SQL Server will have to re-read the data it needs from disk. To clean the buffer pool you execute the command: DBCC DROPCLEANBUFFERS. Next you should remove your execution plans from the procedure cache.


1 Answers

DBCC FREEPROCCACHE 

Will remove all cached procedures execution plans. This would cause all subsequent procedure calls to be recompiled.

Adding WITH RECOMPILE to a procedure definition would cause the procedure to be recompiled every time it was called.

I do not believe that (in SQL 2005 or earlier) there is any way to clear the procedrue cache of a single procedures execution plan, and I'd doubt you could do it in 2008 either.

like image 165
Philip Kelley Avatar answered Sep 28 '22 14:09

Philip Kelley