Thursday 5 March 2015

Top 5 most expensive queries - DMOs


SELECT TOP(5)

(total_logical_reads + total_logical_writes) AS total_logical_IO,

execution_count,

(total_logical_reads/execution_count) AS avg_logical_reads,

(total_logical_writes/execution_count) AS avg_logical_writes,

(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 (total_logical_reads + total_logical_writes) DESC;

//returns five most expensive queries that used the logical disk IO with their query text extracted the batch text

No comments:

Post a Comment