在SQL Server中,是否存在在批处理上下文之外可用的查询成本度量



SQL Server会告诉您查询相对于批处理中其他查询的成本百分比,但这并不能告诉我多少。有没有一种查询成本的衡量标准可以让我在批处理的上下文之外比较应用程序中的所有查询?我可以将感兴趣的查询与引用查询放在一个批中,但这似乎是不必要的笨拙?

我可能不理解这个问题,但我经常使用这样的查询来查看针对DB(或您的示例中的"应用程序"(运行的所有查询:

Select 
st.[text] AS [Query Text],          
wt.last_execution_time AS [Last Execution Time],
wt.execution_count AS [Execution Count],
wt.total_worker_time/1000000 AS [Total CPU Time(second)],
wt.total_worker_time/wt.execution_count/1000 AS [Average CPU Time(milisecond)],
qp.query_plan,
DB_NAME(st.dbid) AS [Database Name]
from 
(select top 50 
qs.last_execution_time,
qs.execution_count,
qs.plan_handle, 
qs.total_worker_time
from sys.dm_exec_query_stats qs
order by qs.total_worker_time desc) wt
cross apply sys.dm_exec_sql_text(plan_handle) st
cross apply sys.dm_exec_query_plan(plan_handle) qp
order by wt.total_worker_time desc

我误解你的问题了吗?我本不想把它作为"答案"发布,但我的问题太长了,无法发表评论。:-(

最新更新