Friday, February 20, 2009
Statements having High CPU usage on execution count
-- High CPU queries -- on execution count
SELECT TOP 50
total_worker_time/execution_count AS avg_cpu_cost,
execution_count,db_name(depamain.dbid) as dbname,object_name(depamain.objectid,depamain.dbid) as objname,
(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
OUTER APPLY
( select dbid,objectid from
(
select attribute,cast(value as int) as attvalue
from sys.dm_exec_plan_attributes(plan_handle)
where attribute in ('dbid','objectid')
) as depa
PIVOT
(
MAX(depa.attvalue) FOR depa.attribute IN ("dbid", "objectid")
) AS depapvt
) as depamain
ORDER BY execution_count DESC;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment