For Day 29 of this series, we start out with Query #65<\/strong>, which is XTP Index Usage. This query retrieves information from the sys.dm_db_xtp_index_stats<\/a> dynamic management view and the sys.indexes<\/a> object catalog view about the overall in-memory OLTP index usage in the current database, ordered by object name. Query #65 is shown in Figure 1.<\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/div>\n<\/div>\n Figure 1: Query #65 XTP Index Usage<\/strong><\/p>\n If you are using in-memory OLTP<\/a> (aka Hekaton), then this query will show how your in-memory OLTP indexes are being used. Perhaps because this is an Enterprise-only feature and perhaps because it has some limitations in SQL Server 2014, I have not seen this feature being used that much out in the field yet. I think the adoption rate will improve with SQL Server 2016.<\/p>\n <\/p>\n Query #66<\/strong> is Lock Waits. This query retrieves information from the sys.dm_db_index_operational_stats<\/a> dynamic management function, the sys.objects<\/a> object catalog view, and the sys.indexes<\/a> object catalog view about the cumulative lock waits in the current database. Query #66 is shown in Figure 2.<\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/div>\n<\/div>\n Figure 2: Query #66 Lock Waits<\/strong><\/p>\n If you are seeing symptoms of locking\/blocking\/deadlocks (such as high average task counts or actual deadlock errors), then this query can show which tables and indexes are seeing the most lock waits, which can often help you troubleshoot and resolve your blocking issues.<\/p>\n These three Pluralsight Courses go into even more detail about how to run these queries and interpret the results. <\/p>\n SQL Server 2014 DMV Diagnostic Queries \u2013 Part 1<\/a><\/p>\n<\/blockquote>\n SQL Server 2014 DMV Diagnostic Queries \u2013 Part 2<\/a><\/p>\n<\/blockquote>\n 1:<\/span> -- Get in-memory OLTP index usage (Query 65) (XTP Index Usage)<\/span><\/pre>\n 2:<\/span> SELECT<\/span> OBJECT_NAME(i.[object_id]) AS<\/span> [Object<\/span> Name], i.index_id, i.name, i.type_desc,<\/pre>\n 3:<\/span> xis.scans_started, xis.scans_retries, xis.rows_touched, xis.rows_returned <\/pre>\n 4:<\/span> FROM<\/span> sys.dm_db_xtp_index_stats AS<\/span> xis WITH<\/span> (NOLOCK)<\/pre>\n 5:<\/span> INNER<\/span> JOIN<\/span> sys.indexes AS<\/span> i WITH<\/span> (NOLOCK)<\/pre>\n 6:<\/span> ON<\/span> i.[object_id] = xis.[object_id] <\/pre>\n 7:<\/span> AND<\/span> i.index_id = xis.index_id <\/pre>\n 8:<\/span> ORDER<\/span> BY<\/span> OBJECT_NAME(i.[object_id]) OPTION<\/span> (RECOMPILE);<\/pre>\n 9:<\/span> <\/pre>\n 10:<\/span> -- This gives you some index usage statistics for in-memory OLTP<\/span><\/pre>\n 11:<\/span> -- Returns<\/span> no<\/span> data<\/span> if<\/span> you are<\/span> not<\/span> using<\/span> in<\/span>-memory OLTP<\/pre>\n 1:<\/span> -- Get lock waits for current database (Query 66) (Lock Waits)<\/span><\/pre>\n 2:<\/span> SELECT<\/span> o.name AS<\/span> [table_name], i.name AS<\/span> [index_name], ios.index_id, ios.partition_number,<\/pre>\n 3:<\/span> SUM<\/span>(ios.row_lock_wait_count) AS<\/span> [total_row_lock_waits], <\/pre>\n 4:<\/span> SUM<\/span>(ios.row_lock_wait_in_ms) AS<\/span> [total_row_lock_wait_in_ms],<\/pre>\n 5:<\/span> SUM<\/span>(ios.page_lock_wait_count) AS<\/span> [total_page_lock_waits],<\/pre>\n 6:<\/span> SUM<\/span>(ios.page_lock_wait_in_ms) AS<\/span> [total_page_lock_wait_in_ms],<\/pre>\n 7:<\/span> SUM<\/span>(ios.page_lock_wait_in_ms)+ SUM<\/span>(row_lock_wait_in_ms) AS<\/span> [total_lock_wait_in_ms]<\/pre>\n 8:<\/span> FROM<\/span> sys.dm_db_index_operational_stats(DB_ID(), NULL<\/span>, NULL<\/span>, NULL<\/span>) AS<\/span> ios<\/pre>\n 9:<\/span> INNER<\/span> JOIN<\/span> sys.objects AS<\/span> o WITH<\/span> (NOLOCK)<\/pre>\n 10:<\/span> ON<\/span> ios.[object_id] = o.[object_id]<\/pre>\n 11:<\/span> INNER<\/span> JOIN<\/span> sys.indexes AS<\/span> i WITH<\/span> (NOLOCK)<\/pre>\n 12:<\/span> ON<\/span> ios.[object_id] = i.[object_id] <\/pre>\n 13:<\/span> AND<\/span> ios.index_id = i.index_id<\/pre>\n 14:<\/span> WHERE<\/span> o.[object_id] > 100<\/pre>\n 15:<\/span> GROUP<\/span> BY<\/span> o.name, i.name, ios.index_id, ios.partition_number<\/pre>\n 16:<\/span> HAVING<\/span> SUM<\/span>(ios.page_lock_wait_in_ms)+ SUM<\/span>(row_lock_wait_in_ms) > 0<\/pre>\n 17:<\/span> ORDER<\/span> BY<\/span> total_lock_wait_in_ms DESC<\/span> OPTION<\/span> (RECOMPILE);<\/pre>\n 18:<\/span> <\/pre>\n 19:<\/span> -- This query is<\/span> helpful for<\/span> troubleshooting blocking and<\/span> deadlocking issues<\/pre>\n\n
\n
\n