Skip to content

Instantly share code, notes, and snippets.

@jdaigle
Created April 21, 2013 02:19
Show Gist options
  • Save jdaigle/5428198 to your computer and use it in GitHub Desktop.
Save jdaigle/5428198 to your computer and use it in GitHub Desktop.
query for single use ad hoc queries in the plan cache
SELECT [text], cp.size_in_bytes, plan_handle
FROM sys.dm_exec_cached_plans AS cp
CROSS APPLY sys.dm_exec_sql_text(plan_handle)
WHERE
cp.cacheobjtype = N'Compiled Plan'
AND cp.objtype = N'Adhoc'
AND cp.usecounts = 1
ORDER BY cp.size_in_bytes DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment