如果下面使用dm_exec_procedure_stats的查询的[Total Duration(s)]列给出了查询返回结果所需的平均时间,那么任何人都可以进行混淆吗?我担心这只是这些查询重新调整结果所花时间的一个因素,因为它们看起来很低。
感谢每个花时间看的人。
任何帮助或建议将不胜感激
SELECT SUBSTRING(qt.TEXT, CHARINDEX('USP_', qt.TEXT, 1), CHARINDEX(']', qt.TEXT, CHARINDEX('USP_', qt.TEXT, 1)) - CHARINDEX('USP_', qt.TEXT, 1)) AS Procedure_Name,
qt.TEXT,
CAST(total_elapsed_time / 1000000.0 AS DECIMAL(28, 2)) AS [Total Duration (s)],
CASE
WHEN execution_count = 0 THEN 0
ELSE CAST(total_worker_time * 100.0 / total_elapsed_time AS DECIMAL(28, 2))
END AS [% CPU],
CASE
WHEN execution_count = 0 THEN 0
ELSE CAST(( total_elapsed_time - total_worker_time ) * 100.0 / total_elapsed_time AS DECIMAL(28, 2))
END AS [% Waiting],
execution_count,
CASE
WHEN execution_count = 0 THEN 0
ELSE CAST(total_elapsed_time / 1000000.0 / execution_count AS DECIMAL(28, 2))
END AS [Average Duration (s)],
sql_handle,
plan_handle,
object_id,
total_elapsed_time,
total_worker_time,
execution_count,
total_physical_reads,
total_logical_reads,
total_logical_writes
FROM sys.dm_exec_procedure_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
WHERE qt.text LIKE '%USP%'
ORDER BY 1
答案 0 :(得分:1)
要获得平均时间,您需要除以TOTAL
/ COUNT
然后除以1000000.0以获得秒数。
这是代码:
,CONVERT(DECIMAL(26,10),(qs.total_elapsed_time / qs.execution_count)) / 1000000.0 AS [avg_elapsed_time_inSec]