Quantcast
Channel: SQL Archives - SQL Authority with Pinal Dave
Viewing all articles
Browse latest Browse all 594

SQL SERVER – Using dm_db_stats_properties With InMemory OLTP Tables

$
0
0

The whole concept of InMemory OLTP has been around for a while and still there are areas that I try to go back to learn every single time. If you are new to InMemory OLTP, I would highly recommend searching this blog for more content. For a starter, the blow blog is a great start. SQL SERVER – Beginning In-Memory OLTP with Sample Example

In exploring the DMVs which are available in standard tables, I stumbled upon a great addition. I found the db_stats_properties DMV, which was able to give me information about the number of rows that have been modified.

Getting curious, I wanted to know if this worked with InMemory OLTP tables. The amount of changes and modification to a memory-optimized table is now reflected in the Dynamic Management Function “sys.dm_db_stats_properties” which returns a record per stats object on the table. The DMF is now behaving equally for memory-optimized and disk-based table and the column – “modification_counter” reflects the row modification counter that is used for determining whether an auto – update of stats is needed.

Consider the following query to analyze statistics and the modification_counter value:

USE [MyDatabase]
GO
SELECT
    sp.stats_id, name, filter_definition, last_updated, rows, rows_sampled, steps,
unfiltered_rows, modification_counter
FROM sys.stats AS stat
CROSS APPLY sys.dm_db_stats_properties(stat.object_id, stat.stats_id) AS sp
WHERE stat.object_id = object_id('Schemaname.TableName');

One of the things to keep in mind is that the data on the DMF resets on DB restart or failover. A typical output would look like:

SQL SERVER - Using dm_db_stats_properties With InMemory OLTP Tables db_stats_properties-01-800x231

It is worth to know that the modification_counter can be more than the number of rows. The logic is, if the same rows are modified multiple times, then this counter can be higher than the actual number of rows.

Do let me know if you find this interesting. Where would you use this capability? Let me know via comments below.

Reference: Pinal Dave (https://blog.sqlauthority.com)

First appeared on SQL SERVER – Using dm_db_stats_properties With InMemory OLTP Tables


Viewing all articles
Browse latest Browse all 594

Trending Articles