Tuesday, February 23, 2016

Cache plan


Create Procedure SeeCacheWSize (@str NVARCHAR(4000))
as

select cp.objecttype, cp.cacheobjtype
 cp.size_in_bytes, cp.usecounts, st.text
from sys.dm_exec_cached_plans as cp
  cross apply sys.dm_exec_sql_text
  (cp.plan_handle) as st
where cp.objtype in ('adhoc','prepared')
and st.text like @str
 and (st.text not like '%syscacheobjects%'
   or st.text not like '%select%cp.objecttype%')

usage SeeCacheWSize '%m_safe%' or '%m_unsafe%'

Dynamic Management View/Function
DMV:sys.dm_exec_query_stats 
DMF:sys.dm_exec_sql_text(sql_handle)
DMF:sys.dm_exec_query_plan(plan_handle) 

No comments:

Post a Comment