Skip to content

PopSQL: limited support.

Migrate now →

Queries by total CPU

Cached plans ranked by worker time across all executions.

SQL Server · SQL
SELECT TOP 20
       LEFT(SUBSTRING(t.text, (s.statement_start_offset / 2) + 1,
            ((CASE s.statement_end_offset WHEN -1 THEN DATALENGTH(t.text) ELSE s.statement_end_offset END - s.statement_start_offset) / 2) + 1), 160) AS statement,
       s.execution_count AS calls,
       s.total_worker_time / 1000 AS total_cpu_ms,
       s.total_worker_time / s.execution_count / 1000 AS avg_cpu_ms,
       s.total_logical_reads AS logical_reads,
       s.last_execution_time
FROM sys.dm_exec_query_stats s
CROSS APPLY sys.dm_exec_sql_text(s.sql_handle) t
ORDER BY s.total_worker_time DESC

This query is part of the "SQL Server health" pack: connect the database in DataRunner and install the whole pack — queries, dashboard and checks — at once.