Cached query plans and top stored procedures that are recompiled
We all know that the cached query plans are good to go to attain the performance and no doubt that inefficient query plan will cause more distress to performance with an increased spike in CPU consumption. At the same occurrence of recompilation of a stored procedure is not a good show either. So how you can measure the extent to which the compile time is contributing to the high CPU use.
Again the DMV sys.dm_exec_query_optimizer_info comes handy here to get such information by returning the aggregate performance statistics from the cached quer plans, bear in mind the optimum result is presented only when query execution is completed.
So in order to findout how many times the stored procedures are
compiled, you can take help of following query:
select top 10
sql_text.text,
sql_handle,
plan_generation_num,
execution_count,
dbid,
objectid
from
sys.dm_exec_query_stats a
cross apply sys.dm_exec_sql_text(sql_handle) as sql_text
where
plan_generation_num >1
order by plan_generation_num desc
(Code extracted from Sunil Agarwal & Boris Baryshnikov reference).
From the above DMV results you can get the stored procedure information that
has been compiled that many times based on the plan_generation_num
value and also for the further information on this issue
refer to Batch-Compilation article.
**__________________________________**
SQL Server MVP, Sr. DBA & industry expert.
-
Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it. It is also a power and you will gain by sharing it.