Guest User

Untitled

a guest
Jan 21st, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. SELECT DISTINCT
  2. QCP.objtype
  3. ,MultipleQ.PlanCount
  4. ,qStat.query_hash
  5. ,sText.text AS QueryText
  6. ,size_in_bytes
  7. ,qStat.creation_time
  8. FROM (
  9. SELECT query_hash,
  10. COUNT(query_hash) AS PlanCount
  11. FROM sys.dm_exec_query_stats
  12. GROUP BY query_hash
  13. ) AS MultipleQ
  14. INNER JOIN sys.dm_exec_query_stats qStat ON MultipleQ.query_hash = qStat.query_hash
  15. INNER JOIN sys.dm_exec_cached_plans QCP
  16. ON QCP.plan_handle = qStat.plan_handle
  17. CROSS APPLY sys.dm_exec_sql_text(qStat.sql_handle) AS sText
  18. CROSS APPLY sys.dm_exec_query_plan(qStat.plan_handle) AS qp
  19. WHERE PlanCount > 1
  20. AND QCP.objtype = 'Adhoc'
  21. ORDER BY MultipleQ.PlanCount DESC
  22.  
  23. DBCC FREESYSTEMCACHE ('SQL Plans')
Add Comment
Please, Sign In to add comment