Saturday, June 19, 2021

Get in-memory OLTP index usage

Understanding how your SQL Server indexes are performing is crucial for database optimization. The following SQL query leverages sys.dm_db_xtp_index_stats to provide valuable insights into your in-memory OLTP (Hekaton) index usage. This dynamic management view gives you statistics like the number of scans, retries, rows touched, and rows returned for each index.

SELECT OBJECT_NAME(i.[object_id]) AS [Object Name],
       i.index_id,
       i.[name] AS [Index Name],
       i.[type_desc],
       xis.scans_started,
       xis.scans_retries,
       xis.rows_touched,
       xis.rows_returned
FROM sys.dm_db_xtp_index_stats AS xis WITH (NOLOCK)
INNER JOIN sys.indexes AS i WITH (NOLOCK) ON i.[object_id] = xis.[object_id]
                                          AND i.index_id = xis.index_id
ORDER BY OBJECT_NAME(i.[object_id])
OPTION (RECOMPILE);

This query helps you identify which indexes are being heavily utilized and which might be underperforming or not being used efficiently. For more detailed information on sys.dm_db_xtp_index_stats, you can refer to the official Microsoft documentation:

sys.dm_db_xtp_index_stats (Transact-SQL) - SQL Server | Microsoft Docs

You might also find these related articles helpful for further exploration of SQL Server memory management and performance:

Popular Posts