RSS

Querying Plan Cache

22 Aug

SELECT [cp].[refcounts] ,
[cp].[usecounts] ,
[cp].[objtype] ,
[st].[dbid] ,
[st].[objectid] ,
[st].[text] ,
[qp].[query_plan],
cp.plan_handle
FROM sys.dm_exec_cached_plans cp
CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) st
CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) qp;

where the value in cp.plan_handle can be used to single out a particular plan and use that value to clear cache for just 1 proc..

example dbcc freeproccache(plan_handle)

— From Sql Server Execution Plans by Grant Fritchley, page 52

 
 

Leave a comment