Advertisement
etsuskier

Index Memory Usage

May 1st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.21 KB | None | 0 0
  1.  
  2. USE master
  3.  
  4. SELECT tables.name,
  5.        indexes.name,
  6.        COUNT(*) AS cached_pages_count,
  7.        COUNT(*) / 128 AS cached_mb
  8.   FROM sys.dm_os_buffer_descriptors
  9.  INNER JOIN (
  10.        SELECT partitions.object_id,
  11.               partitions.index_id,
  12.               allocation_units.allocation_unit_id
  13.          FROM sys.allocation_units
  14.         INNER JOIN sys.partitions ON allocation_units.container_id = partitions.hobt_id
  15.           AND (allocation_units.type = 1
  16.            OR allocation_units.type = 3)
  17.         UNION ALL
  18.        SELECT partitions.object_id,
  19.               partitions.index_id,
  20.               allocation_units.allocation_unit_id
  21.          FROM sys.allocation_units
  22.         INNER JOIN sys.partitions ON allocation_units.container_id = partitions.partition_id
  23.           AND allocation_units.type = 2
  24.        ) AS obj ON dm_os_buffer_descriptors.allocation_unit_id = obj.allocation_unit_id
  25.  INNER JOIN sys.indexes ON obj.object_id = indexes.object_id
  26.    AND obj.index_id = indexes.index_id
  27.  INNER JOIN sys.tables ON indexes.object_id = tables.object_id
  28. WHERE dm_os_buffer_descriptors.database_id = DB_ID()  
  29. GROUP BY tables.name,
  30.       indexes.name
  31. ORDER BY cached_pages_count DESC
  32. OPTION (RECOMPILE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement