Skip to content

Instantly share code, notes, and snippets.

@ghotz
Created January 26, 2019 10:31
Show Gist options
  • Save ghotz/07350e2202117b5a02fdad9ad97ffe69 to your computer and use it in GitHub Desktop.
Save ghotz/07350e2202117b5a02fdad9ad97ffe69 to your computer and use it in GitHub Desktop.
Analyze single plan usage
SELECT
objtype
, COUNT_BIG(*) AS plans_count
, SUM(CAST(size_in_bytes AS bigint) / 1024. / 1024.) AS plans_MB
, AVG(usecounts) AS plans_count_avg
, SUM(CASE WHEN usecounts = 1 THEN 1 ELSE 0 END) AS plans_single_use_count
, SUM(CASE WHEN usecounts = 1 THEN CAST(size_in_bytes AS bigint) / 1024. / 1024. ELSE 0 END) AS plans_single_use_MB
FROM sys.dm_exec_cached_plans
GROUP BY objtype
ORDER BY plans_single_use_MB DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment