Last active
March 20, 2017 13:54
-
-
Save nishi141001/7f3ede6b8083ccb991b27797ae34026e to your computer and use it in GitHub Desktop.
CPU負荷が高いSQLのTOP100
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE master | |
GO | |
SET NOCOUNT ON | |
GO | |
SELECT TOP 100 | |
rank() over(order by total_worker_time desc,sql_handle,statement_start_offset) AS [row_no] | |
, db_name(st.dbid) AS [database_name] | |
, creation_time | |
, last_execution_time | |
, (total_worker_time+0.0)/1000 AS [total_worker_time(ms)] | |
, (total_worker_time+0.0)/(execution_count*1000) AS [AvgCPUTime(ms)] | |
, (total_elapsed_time+0.0)/1000 AS [total_elapsed_time(ms)] | |
, (total_elapsed_time+0.0)/(execution_count*1000) AS [AvgElapsedTime(ms)] | |
, total_logical_reads AS [LogicalReads(page)] | |
, total_logical_writes AS [logicalWrites(page)] | |
, total_logical_reads+total_logical_writes AS [AggIO(page)] | |
, (total_logical_reads+total_logical_writes)/(execution_count + 0.0) AS [AvgIO(page)] | |
, execution_count | |
, total_rows | |
, st.text AS [batch_query_text] | |
, CASE | |
WHEN sql_handle IS NULL | |
THEN ' ' | |
ELSE ( SUBSTRING(st.text,(qs.statement_start_offset+2)/2,(CASE | |
WHEN qs.statement_end_offset = -1 | |
THEN LEN(CONVERT(NVARCHAR(MAX),st.text))*2 | |
ELSE qs.statement_end_offset | |
END | |
- qs.statement_start_offset) /2 ) ) | |
END AS [statement_query_text] | |
, plan_generation_num | |
, qp.query_plan | |
FROM sys.dm_exec_query_stats AS [qs] | |
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS [st] | |
CROSS APPLY sys.dm_exec_query_plan(plan_handle) AS [qp] | |
WHERE total_worker_time > 0 | |
ORDER BY total_worker_time DESC | |
OPTION (RECOMPILE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment