简体   繁体   中英

How to clear cache of latest select query that was run? (or prevent a select query from caching)

I am using MS SQL Server 2012. I am trying to see the optimization in the server so I can't just clear everything.

This link didn't work for me. (or this example )

Any suggestions how I can select the query and clear the cache afterwards?
(or prevent it from caching would be better)

EDIT:
Most desired outcome is testing the select query like it's running for the very first time.

You can query sys.dm_exec_connections to get a handle to last executed query for a given connection, and then evict that plan with DBCC FREEPROCCACHE . Make sure you do this on another connection.

Alternatively, use WITH RECOMPILE or OPTION(RECOMPILE) to not cache the plan at all:

http://blogs.msdn.com/b/sqlmeditation/archive/2013/01/01/is-it-really-quot-recompile-quot-or-a-quot-private-temporary-compile-quot.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM