|
| 1 | +/* |
| 2 | +<documentation> |
| 3 | + <summary>List Cached Data Per Object in Memory</summary> |
| 4 | + <returns>1 data set: list Cached Data Per Object in Memory.</returns> |
| 5 | + <issues>No</issues> |
| 6 | + <author>Pinal Dave</author> |
| 7 | + <created>2021-03-31</created> |
| 8 | + <modified>2021-03-31 by Konstantin Taranov</modified> |
| 9 | + <version>1.0</version> |
| 10 | + <sourceLink>https://github.com/ktaranov/sqlserver-kit/blob/master/Scripts/Cached_Data_Per_Object_in_Memory.sql</sourceLink> |
| 11 | + <originalLink>https://blog.sqlauthority.com/2021/03/31/sql-server-cached-data-per-object-in-memory/</originalLink> |
| 12 | +</documentation> |
| 13 | +*/ |
| 14 | + |
| 15 | +SELECT COUNT (1) * 8 / 1024 AS MBUsed, |
| 16 | + OBJECT_SCHEMA_NAME(object_id) SchemaName, |
| 17 | + name AS TableName, index_id |
| 18 | +FROM sys.dm_os_buffer_descriptors AS bd |
| 19 | + INNER JOIN |
| 20 | + ( |
| 21 | + SELECT object_name(object_id) AS name |
| 22 | + ,index_id ,allocation_unit_id, object_id |
| 23 | + FROM sys.allocation_units AS au |
| 24 | + INNER JOIN sys.partitions AS p |
| 25 | + ON au.container_id = p.hobt_id |
| 26 | + AND (au.type = 1 OR au.type = 3) |
| 27 | + UNION ALL |
| 28 | + SELECT object_name(object_id) AS name |
| 29 | + ,index_id, allocation_unit_id, object_id |
| 30 | + FROM sys.allocation_units AS au |
| 31 | + INNER JOIN sys.partitions AS p |
| 32 | + ON au.container_id = p.partition_id |
| 33 | + AND au.type = 2 |
| 34 | + ) AS obj |
| 35 | + ON bd.allocation_unit_id = obj.allocation_unit_id |
| 36 | +WHERE database_id = DB_ID() |
| 37 | +GROUP BY OBJECT_SCHEMA_NAME(object_id), name, index_id |
| 38 | +ORDER BY COUNT (*) * 8 / 1024 DESC; |
| 39 | +GO |
0 commit comments