본문 바로가기

SQL/DBA 가이드

TOP 10 queries by IO and CPU


Top Queries by Average CPU Time



SELECT TOP(10)

creation_time

, last_execution_time

, (total_worker_time+0.0)/1000 AS total_worker_time

, (total_worker_time+0.0)/(execution_count*1000) AS [AvgCPUTime]

, execution_count

, st.text

FROM sys.dm_exec_query_stats qs

CROSS APPLY sys.dm_exec_sql_text(sql_handle) st

WHERE total_worker_time > 0

ORDER BY total_worker_time DESC




Top Queries by Average IO Time


 SELECT TOP 10

creation_time

, last_execution_time

, total_logical_reads AS [LogicalReads]

, total_logical_writes AS [LogicalWrites]

, execution_count

, total_logical_reads+total_logical_writes AS [AggIO] 

, (total_logical_reads+total_logical_writes)/(execution_count+0.0) AS [AvgIO]

, st.TEXT

, DB_NAME(st.dbid) AS database_name

, st.objectid AS OBJECT_ID

FROM sys.dm_exec_query_stats qs

CROSS APPLY sys.dm_exec_sql_text(sql_handle) st

WHERE total_logical_reads+total_logical_writes > 0

AND sql_handle IS NOT NULL

ORDER BY [AggIO] DESC



https://blog.sqlauthority.com/2014/07/29/sql-server-ssms-top-queries-by-cpu-and-io/