Skip to content

Commit 0463f43

Browse files
Merge pull request #26217 from thesqlsith/patch-3
Update sys-dm-exec-query-statistics-xml-transact-sql.md with behavior change re-introduced in later CU's
2 parents b2ecfd9 + ec1e060 commit 0463f43

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

docs/relational-databases/system-dynamic-management-views/sys-dm-exec-query-statistics-xml-transact-sql.md

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ sys.dm_exec_query_statistics_xml(session_id)
5050
|query_plan|**xml**|Contains the runtime Showplan representation of the query execution plan that is specified with *plan_handle* containing partial statistics. The Showplan is in XML format. One plan is generated for each batch that contains, for example ad hoc [!INCLUDE[tsql](../../includes/tsql-md.md)] statements, stored procedure calls, and user-defined function calls. Nullable.|
5151

5252
## Remarks
53+
> [!IMPORTANT]
54+
> Owning to a possible random access violation (AV) while executing a monitoring stored procedure with the ``sys.dm_exec_query_statistics_xml`` DMV, the Showplan XML attribute \<ParameterList\> value `ParameterRuntimeValue` was removed in [!INCLUDE[ssSQL17](../../includes/sssql17-md.md)] CU 26 and [!INCLUDE[sql-server-2019](../../includes/sssql19-md.md)] CU 12. This value could be useful while troubleshooting long running stored procedures.
55+
>
56+
> Starting with [!INCLUDE[ssSQL17](../../includes/sssql17-md.md)] CU 31 and [!INCLUDE[sql-server-2019](../../includes/sssql19-md.md)] CU 19, the collection of the Showplan XML attribute \<ParameterList\> value `ParameterRuntimeValue` has been re-enabled with the inclusion of trace flag 2446. This trace flag enables the collection of the runtime parameter value at the cost of introducing additional overhead.
57+
58+
> [!WARNING]
59+
>Trace Flag 2446 isn't meant to be enabled continuously in a production environment, but only for time-limited troubleshooting purposes. Using this trace flag will introduce additional and possibly significant CPU and memory overhead as we will create a Showplan XML fragment with runtime parameter information, whether the ``sys.dm_exec_query_statistics_xml`` DMV is called or not.
60+
61+
> [!NOTE]
62+
>Starting with [!INCLUDE[ssSQL22](../../includes/sssql22-md.md)], [!INCLUDE[Azure SQL Database](../../includes/ssazure_md.md)], and [!INCLUDE[Azure SQL Managed Instance](../../includes/ssazuremi_md.md)], to accomplish this at the database level see the FORCE_SHOWPLAN_RUNTIME_PARAMETER_COLLECTION option in [ALTER DATABASE SCOPED CONFIGURATION (Transact-SQL)](../../t-sql/statements/alter-database-scoped-configuration-transact-sql.md).
63+
5364
This system function is available starting with [!INCLUDE[sssql16-md](../../includes/sssql16-md.md)] SP1. See KB [3190871](https://support.microsoft.com/help/3190871)
5465

5566
This system function works under both **standard** and **lightweight** query execution statistics profiling infrastructure. For more information, see [Query Profiling Infrastructure](../../relational-databases/performance/query-profiling-infrastructure.md).
@@ -90,9 +101,28 @@ GO
90101

91102
```sql
92103
--Run this in a different session than the session in which your query is running.
93-
SELECT * FROM sys.dm_exec_requests
94-
CROSS APPLY sys.dm_exec_query_statistics_xml(session_id);
95-
GO
104+
SELECT
105+
eqs.query_plan,
106+
er.session_id,
107+
er.request_id,
108+
er.database_id,
109+
er.start_time,
110+
er.[status],
111+
er.wait_type,
112+
er.wait_resource,
113+
er.last_wait_type,
114+
(er.cpu_time/1000) AS cpu_time_sec,
115+
(er.total_elapsed_time/1000)/60 AS elapsed_time_minutes,
116+
(er.logical_reads*8)/1024 AS logical_reads_KB,
117+
er.granted_query_memory,
118+
er.dop,
119+
er.row_count,
120+
er.query_hash,
121+
er.query_plan_hash
122+
FROM sys.dm_exec_requests er
123+
CROSS APPLY sys.dm_exec_query_statistics_xml(session_id) eqs
124+
WHERE er.session_id <> @@spid;
125+
GO
96126
```
97127

98128
## See Also

0 commit comments

Comments
 (0)