Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT DISTINCT
- QCP.objtype
- ,MultipleQ.PlanCount
- ,qStat.query_hash
- ,sText.text AS QueryText
- ,size_in_bytes
- ,qStat.creation_time
- FROM (
- SELECT query_hash,
- COUNT(query_hash) AS PlanCount
- FROM sys.dm_exec_query_stats
- GROUP BY query_hash
- ) AS MultipleQ
- INNER JOIN sys.dm_exec_query_stats qStat ON MultipleQ.query_hash = qStat.query_hash
- INNER JOIN sys.dm_exec_cached_plans QCP
- ON QCP.plan_handle = qStat.plan_handle
- CROSS APPLY sys.dm_exec_sql_text(qStat.sql_handle) AS sText
- CROSS APPLY sys.dm_exec_query_plan(qStat.plan_handle) AS qp
- WHERE PlanCount > 1
- AND QCP.objtype = 'Adhoc'
- ORDER BY MultipleQ.PlanCount DESC
- DBCC FREESYSTEMCACHE ('SQL Plans')
Add Comment
Please, Sign In to add comment