小编典典

如何在SQL Server 2005/2008中清除查询执行统计信息

sql

基于使用从这篇文章中“最常执行的存储过程-
堆栈溢出”中
获得的极其有用的SQL获取查询执行统计信息:

SELECT TOP 100
   qt.TEXT AS 'SP Name',
   SUBSTRING(qt.text, qs.statement_start_offset/2, CASE WHEN (qs.statement_end_offset = -1) THEN LEN(qt.text) ELSE (qs.statement_end_offset - qs.statement_start_offset)/2 END) AS actual_query,
   qs.execution_count AS 'Execution Count',
   qs.total_worker_time/qs.execution_count AS 'AvgWorkerTime',
   qs.total_worker_time AS 'TotalWorkerTime',
   qs.total_physical_reads AS 'PhysicalReads',
   qs.creation_time 'CreationTime',
   qs.execution_count/DATEDIFF(Second, qs.creation_time, GETDATE()) AS 'Calls/Second'
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
WHERE qt.dbid = (SELECT dbid
                FROM sys.sysdatabases
               WHERE name = 'BSP')
ORDER BY qs.total_worker_time/qs.execution_count DESC

我将如何彻底清除这些执行统计信息并从头开始?

这将特别有用,因为开发错误和测试已导致例程被多次调用,从而使实际使用水平无效。


阅读 322

收藏
2021-04-15

共1个答案

小编典典

DBCC FREEPROCCACHE
DBCC DROPCLEANBUFFERS

2021-04-15