Skip to content

Instantly share code, notes, and snippets.

@kshimi
Last active March 14, 2019 09:54
Show Gist options
  • Save kshimi/b284134ca1812e13164fecace3cedff9 to your computer and use it in GitHub Desktop.
Save kshimi/b284134ca1812e13164fecace3cedff9 to your computer and use it in GitHub Desktop.
SQLServer Check heavy query
SELECT TOP 100
total_elapsed_time / execution_count / 1000.0 AS [平均実行時間(ミリ秒)]
, total_worker_time / execution_count / 1000.0 AS [平均 CPU 時間(ミリ秒)]
, total_physical_reads / execution_count AS [平均物理I/O 数]
, (total_logical_reads + total_logical_writes)
/ execution_count AS [平均論理I/O 数]
, SUBSTRING(text, (statement_start_offset / 2) + 1,
((CASE statement_end_offset
WHEN -1 THEN DATALENGTH(text)
ELSE statement_end_offset
END - statement_start_offset) / 2) + 1) AS sqltext
,creation_time, last_execution_time, execution_count
FROM
sys.dm_exec_query_stats
CROSS APPLY sys.dm_exec_sql_text(sql_handle)
ORDER BY 2 DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment