The queries using the most CPU, reads and time since their plans were cached. Change the ORDER BY to sort by reads or duration. For history across restarts use Query Store (Performance 02). Read-only, changes nothing. Tested on SQL Server 2017 and 2025.
-- 01_Top_Queries.sql - the queries using the most CPU, reads and time since their plans were cached. Read-only.
-- Change the ORDER BY to sort by reads or duration. For history across restarts use Query Store (02).
SET NOCOUNT ON;
SELECT TOP (25) DB_NAME(t.dbid) AS [database], OBJECT_NAME(t.objectid, t.dbid) AS [object],
qs.execution_count, qs.total_worker_time / 1000 AS total_cpu_ms, qs.total_worker_time / qs.execution_count / 1000 AS avg_cpu_ms,
qs.total_logical_reads / qs.execution_count AS avg_reads, qs.total_elapsed_time / qs.execution_count / 1000 AS avg_ms,
qs.last_execution_time, qs.creation_time AS cached_since,
SUBSTRING(t.text, qs.statement_start_offset / 2 + 1,
(CASE WHEN qs.statement_end_offset = -1 THEN DATALENGTH(t.text) ELSE qs.statement_end_offset END - qs.statement_start_offset) / 2 + 1) AS statement,
qp.query_plan
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS t
OUTER APPLY sys.dm_exec_query_plan(qs.plan_handle) AS qp
ORDER BY qs.total_worker_time DESC; -- or: qs.total_logical_reads DESC / qs.total_elapsed_time DESC