您的位置:首页 > 产品设计 > UI/UE

get the top-10 queries that are taking the most CPU per execution

2010-06-09 15:34 323 查看
1.

SELECT TOP 10
total_worker_time/execution_count AS avg_cpu_cost, plan_handle,
execution_count,
(SELECT SUBSTRING(text, statement_start_offset/2 + 1,
(CASE WHEN statement_end_offset = -1
THEN LEN(CONVERT(nvarchar(max), text)) * 2
ELSE statement_end_offset
END - statement_start_offset)/2)
FROM sys.dm_exec_sql_text(sql_handle)) AS query_text
FROM sys.dm_exec_query_stats
ORDER BY [avg_cpu_cost] DESC

If you use the above DMV, you may miss finding the most frequently executed queries in your workload if the CPU cost of those queries is much less than say top-10 queries. To find the most frequently executed queries in your workload, you can execute the following DMV query, a slight variant of the previous DMV query:

2.

 SELECT TOP 10 total_worker_time, plan_handle,execution_count,
(SELECT SUBSTRING(text, statement_start_offset/2 + 1,
(CASE WHEN statement_end_offset = -1
THEN LEN(CONVERT(nvarchar(max),text)) * 2
ELSE statement_end_offset
END - statement_start_offset)/2)
FROM sys.dm_exec_sql_text(sql_handle)) AS query_text
FROM sys.dm_exec_query_stats
ORDER BY execution_count DESC
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  query sql less
相关文章推荐