Determine if adhoc queries are taking up most of the Plan Cache

Below query helps in identifying what type of objects are taking up most of the plan cache.


SELECT objtype AS ‘Cached Object Type’, count(*) AS ‘Number of Plans’,
sum(cast(size_in_bytes AS BIGINT))/1024/1024 AS ‘Plan Cache Size (MB)’,
avg(usecounts) AS ‘Avg Use Count’ FROM sys.dm_exec_cached_plans
GROUP BY objtype

If adhoc queries take up most of the plan cache, it indicates that queries should be parameterized and enclosed within stored procedures for efficient use of plan cache.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s