The sys.dm_exec_query_statistics_xml DMF

SQL Server 2016 SP1 introduced a new DMF named sys.dm_exec_query_statistics_xml, which leverages LWP by default, but it also works if Standard Profiling is enabled. This DMF outputs the query execution plan as a snapshot of the current in-flight request. As such, this query execution plan will have transient runtime statistics captured at the moment the DMF was invoked.

The ability to programmatically access the query execution plan for any running request is a leap forward for scenarios in which we must troubleshoot a long-running query. In this case, we can use this DMF, or LQS, which we discussed in the first section of this chapter.

Let's look at a practical example of using this new DMF. The following ...

Get Learn T-SQL Querying now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.