用于确定SQL SERVER dm_exec_procedure_stats优先级的度量标准

时间:2016-12-07 10:13:51

标签: sql-server tsql database-performance

此查询提供了大量有用的信息,但我需要提出一个好的度量标准来确定数据的优先级。任何人都可以为ORDER BY子句提出理想的序列吗?

我猜测计算优先顺序的关键字段是[execution_count],[total_worker_time],[total_physical_reads]和[total_logical_writes]

SELECT 
    DB_NAME(database_id)               databaes_name
    ,p.name                                 proc_name
    ,p.type                                 proc_type
    ,d.object_id
    ,d.type
    ,d.type_desc
    --,d.sql_handle
    --,d.plan_handle
    ,d.cached_time
    ,d.last_execution_time
    ,d.execution_count
    ,d.total_worker_time
    ,d.last_worker_time
    ,d.min_worker_time
    ,d.max_worker_time
    ,d.total_physical_reads
    ,d.last_physical_reads
    ,d.min_physical_reads
    ,d.max_physical_reads
    ,d.total_logical_writes
    ,d.last_logical_writes
    ,d.min_logical_writes
    ,d.max_logical_writes
    ,d.total_logical_reads
    ,d.last_logical_reads
    ,d.min_logical_reads
    ,d.max_logical_reads
    ,d.total_elapsed_time
    ,d.last_elapsed_time
    ,d.min_elapsed_time
    ,d.max_elapsed_time
FROM   
    sys.procedures p
        JOIN sys.dm_exec_procedure_stats d
            ON 
            p.object_id = d.object_id
WHERE  
    d.database_id = Db_id() 

任何人都可以提出额外的DMV,我应该考虑找出我最昂贵的存储程序是什么吗?

1 个答案:

答案 0 :(得分:0)

这篇文章是关于这个主题的精彩读物。 Simple-Talk

但是为了回答你的问题,我建议使用这个:

ORDER BY AVG_LOGICAL_READS DESC

通过执行此操作,您可以查看哪个过程执行了最多逻辑I / O.

您也应该看一下,即使它特定于查询与程序。它有大量与该主题相关的信息。 SQL Authority Most Expensive Queries它包含以下代码段:

SELECT TOP 10 SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(qt.TEXT)
ELSE qs.statement_end_offset
END - qs.statement_start_offset)/2)+1),
qs.execution_count,
qs.total_logical_reads, qs.last_logical_reads,
qs.total_logical_writes, qs.last_logical_writes,
qs.total_worker_time,
qs.last_worker_time,
qs.total_elapsed_time/1000000 total_elapsed_time_in_S,
qs.last_elapsed_time/1000000 last_elapsed_time_in_S,
qs.last_execution_time,
qp.query_plan
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
ORDER BY qs.total_logical_reads DESC -- logical reads
-- ORDER BY qs.total_logical_writes DESC -- logical writes
-- ORDER BY qs.total_worker_time DESC -- CPU time