Cached query plans and top stored procedures that are recompiled

Published 11 May 07 04:02 AM | SQL Master 

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.

Comments

# SQL Server Performance and Tuning - (SSQA) said on May 14, 2007 2:55 AM:

I don't believe you would need to reset the cache on a production server, it is not a best practice to

# SQL Server Users & tools (SSQA) said on May 15, 2007 8:02 AM:

Well another cache related blog in a row since last few days! I have had weird issues on one of the SQL

# SQL Server Performance and Tuning - (SSQA) said on May 18, 2007 3:54 AM:

For a SQL Server database having an index is always beneficial and from performance point of view too.

# SQL Server Security, Performance & Tuning (SSQA.net) said on September 20, 2007 9:07 AM:

Here comes another Frequently Asked Question (FAQ) on the forums and Frequently Posted Blog (FPB) here

Anonymous comments are disabled

About SQL Master

**__________________________________** 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.

Search

Go

This Blog

«May 2007»
SMTWTFS
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

Syndication