我们在应用程序中创建了许多效率低下的存储过程,我们总是将其推迟以提高其效率,直到我们对数据库性能遇到严重的问题为止。
现在,我正在考虑通过最常执行的存储过程一一修复它。
找出哪个存储过程最执行的最佳方法是什么?
是否有一个脚本可以显示哪个存储过程执行得最多?
使用:
SELECT TOP 10 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 = '[your database name]') ORDER BY qs.total_physical_reads DESC