Created
February 27, 2014 17:17
-
-
Save cpruitt/9254622 to your computer and use it in GitHub Desktop.
SQL Query Cash Queries - Some Queries to examine the contents of the SQL Server query cache and related system stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Get the text of the top 100 queries in the query cache | |
| -- sorted by obj type (adhoc will be first) and then most memory | |
| SELECT TOP 100 | |
| objtype, | |
| usecounts, | |
| p.size_in_bytes / 1024 'size_in_kb', | |
| LEFT([sql].[text], 200) as [text] | |
| FROM sys.dm_exec_cached_plans p | |
| OUTER APPLY sys.dm_exec_sql_text (p.plan_handle) sql | |
| ORDER BY objtype, size_in_kb DESC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Show stats for the number of cached plans, total memory size | |
| -- and average plan use count by query type | |
| 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 | |
| ORDER BY 'Plan Cache Size (MB)' DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment