Friday, July 22, 2011

MS SQL Server - Clear Cache - for Query Timing

[Using MS-SQL Server] When timing a query for the purposes of optimization, the query may well run quicker on re-execution subsequent to the initial execution - due to caching by the db engine.

In order to meaningfully compare execution time across optimization attempts, the cache needs to be cleared, and this can be done by executing


DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE
go


between query timings.

To turn query timing on - SET STATISTICS TIME ON
To turn query timing off - STATISTICS TIME OFF

No comments:

Post a Comment

comment: