Skip to content

Instantly share code, notes, and snippets.

@richardbasile
Created February 16, 2018 14:49
Show Gist options
  • Save richardbasile/c24101a9c53e5b2fe7771b6816223525 to your computer and use it in GitHub Desktop.
Save richardbasile/c24101a9c53e5b2fe7771b6816223525 to your computer and use it in GitHub Desktop.
SQL Server - Multiple Plans
SELECT TOP 100
query_hash AS [Query Hash]
, COUNT(query_hash) AS [Plan Count]
, (
SELECT TOP 1 text
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
WHERE pc.query_hash = qs.query_hash
) AS [Query Text]
FROM sys.dm_exec_query_stats pc
GROUP BY query_hash
HAVING COUNT(1) > 1
ORDER BY [Plan Count] DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment