May 2019
Intermediate to advanced
484 pages
11h 23m
English
If SQL Server is experiencing resource contention such as high CPU consumption or heavy I/O, or we simply want to find queries that are resource intensive, we can use sys.dm_exec_query_stats to list the top resource consuming queries that are currently in the cache. There are several different metrics available via sys.dm_exec_query_stats, such as CPU, logical reads, and elapsed time, which we can sort by to obtain a list of queries that consume large amounts of these resources.
The following query will list the top 10 queries by average CPU consumption in the cache:
SELECT st.[text], qp.query_plan, q.*FROM(SELECT TOP 10 [execution_count], [total_worker_time]/[execution_count] AS [Avg_CPU_Time], [total_elapsed_time]/[execution_count] ...
Read now
Unlock full access