Skip to content

Commit 3e8c17c

Browse files
authored
Freshness pass 005 (#33665)
1 parent 080c2ce commit 3e8c17c

File tree

5 files changed

+273
-262
lines changed

5 files changed

+273
-262
lines changed
Lines changed: 104 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: "sys.dm_exec_query_statistics_xml (Transact-SQL)"
3-
description: sys.dm_exec_query_statistics_xml (Transact-SQL)
3+
description: sys.dm_exec_query_statistics_xml returns query execution plan for in-flight requests. Use this DMV to retrieve showplan XML with transient statistics.
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: "02/24/2023"
6+
ms.date: 03/31/2025
77
ms.service: sql
88
ms.subservice: system-objects
99
ms.topic: conceptual
@@ -21,111 +21,112 @@ dev_langs:
2121

2222
[!INCLUDE [sqlserver2016-asdb-asdbmi](../../includes/applies-to-version/sqlserver2016-asdb-asdbmi.md)]
2323

24-
Returns query execution plan for in-flight requests. Use this DMV to retrieve showplan XML with transient statistics.
24+
Returns query execution plan for in-flight requests. Use this DMV to retrieve showplan XML with transient statistics.
2525

2626
## Syntax
2727

28+
```syntaxsql
29+
sys.dm_exec_query_statistics_xml(session_id)
2830
```
29-
sys.dm_exec_query_statistics_xml(session_id)
30-
```
31-
32-
## Arguments
33-
*session_id*
34-
Is the session id executing the batch to be looked up. *session_id* is **smallint**. *session_id* can be obtained from the following dynamic management objects:
35-
36-
- [sys.dm_exec_requests](../../relational-databases/system-dynamic-management-views/sys-dm-exec-requests-transact-sql.md)
37-
38-
- [sys.dm_exec_sessions](../../relational-databases/system-dynamic-management-views/sys-dm-exec-sessions-transact-sql.md)
39-
40-
- [sys.dm_exec_connections](../../relational-databases/system-dynamic-management-views/sys-dm-exec-connections-transact-sql.md)
41-
42-
## Table Returned
43-
44-
|Column Name|Data Type|Description|
45-
|-----------------|---------------|-----------------|
46-
|session_id|**smallint**|ID of the session. Not nullable.|
47-
|request_id|**int**|ID of the request. Not nullable.|
48-
|sql_handle|**varbinary(64)**|Is a token that uniquely identifies the batch or stored procedure that the query is part of. Nullable.|
49-
|plan_handle|**varbinary(64)**|Is a token that uniquely identifies a query execution plan for a batch that is currently executing. Nullable.|
50-
|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.|
31+
32+
## Arguments
33+
34+
#### *session_id*
35+
36+
The session ID executing the batch to be looked up. *session_id* is **smallint**. *session_id* can be obtained from the following dynamic management objects:
37+
38+
- [sys.dm_exec_requests](../../relational-databases/system-dynamic-management-views/sys-dm-exec-requests-transact-sql.md)
39+
- [sys.dm_exec_sessions](../../relational-databases/system-dynamic-management-views/sys-dm-exec-sessions-transact-sql.md)
40+
- [sys.dm_exec_connections](../../relational-databases/system-dynamic-management-views/sys-dm-exec-connections-transact-sql.md)
41+
42+
## Table returned
43+
44+
| Column Name | Data Type | Description |
45+
| --- | --- | --- |
46+
| `session_id` | **smallint** | ID of the session. Not nullable. |
47+
| `request_id` | **int** | ID of the request. Not nullable. |
48+
| `sql_handle` | **varbinary(64)** | A token that uniquely identifies the batch or stored procedure that the query is part of. Nullable. |
49+
| `plan_handle` | **varbinary(64)** | A token that uniquely identifies a query execution plan for a batch that is currently executing. Nullable. |
50+
| `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. |
51+
52+
## Limitations
53+
54+
Owing 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. You can re-enable this value in [!INCLUDE [ssSQL17](../../includes/sssql17-md.md)] CU 31, [!INCLUDE [sql-server-2019](../../includes/sssql19-md.md)] CU 19, and later versions, using [Trace Flag 2446](../../t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql.md#tf2446). This trace flag enables the collection of the runtime parameter value at the cost of introducing extra overhead.
55+
56+
> [!CAUTION]
57+
> 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 introduces extra and possibly significant CPU and memory overhead, as it creates a Showplan XML fragment with runtime parameter information, whether the `sys.dm_exec_query_statistics_xml` DMV is called or not.
58+
59+
In [!INCLUDE [ssSQL22](../../includes/sssql22-md.md)], [!INCLUDE [Azure SQL Database](../../includes/ssazure-sqldb.md)], and [!INCLUDE [Azure SQL Managed Instance](../../includes/ssazuremi-md.md)], you can accomplish the same functionality at the database level using the `FORCE_SHOWPLAN_RUNTIME_PARAMETER_COLLECTION` option in [ALTER DATABASE SCOPED CONFIGURATION (Transact-SQL)](../../t-sql/statements/alter-database-scoped-configuration-transact-sql.md).
5160

5261
## 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-sqldb.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-
64-
This system function is available starting with [!INCLUDE[sssql16-md](../../includes/sssql16-md.md)] SP1. See KB [3190871](https://support.microsoft.com/help/3190871)
65-
66-
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).
67-
68-
Under the following conditions, no Showplan output is returned in the **query_plan** column of the returned table for **sys.dm_exec_query_statistics_xml**:
69-
70-
- If the query plan that corresponds to the specified *session_id* is no longer executing, the **query_plan** column of the returned table is null. For example, this condition may occur if there is a time delay between when the plan handle was captured and when it was used with **sys.dm_exec_query_statistics_xml**.
71-
72-
Due to a limitation in the number of nested levels allowed in the **xml** data type, **sys.dm_exec_query_statistics_xml** cannot return query plans that meet or exceed 128 levels of nested elements. In earlier versions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], this condition prevented the query plan from returning and generates error 6335. In [!INCLUDE[ssVersion2005](../../includes/ssversion2005-md.md)] Service Pack 2 and later versions, the **query_plan** column returns NULL.
73-
74-
## Permissions
75-
On [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], requires `VIEW SERVER STATE` permission on the server.
76-
On [!INCLUDE[ssSDS](../../includes/sssds-md.md)] Premium Tiers, requires the `VIEW DATABASE STATE` permission in the database. On [!INCLUDE[ssSDS](../../includes/sssds-md.md)] Standard and Basic Tiers, requires the **Server admin** or a [Microsoft Entra admin](/azure/azure-sql/database/authentication-aad-overview#administrator-structure) account.
77-
78-
### Permissions for SQL Server 2022 and later
79-
80-
Requires VIEW SERVER PERFORMANCE STATE permission on the server.
81-
82-
## Examples
83-
84-
### A. Looking at live query plan and execution statistics for a running batch
85-
The following example queries **sys.dm_exec_requests** to find the interesting query and copy its `session_id` from the output.
86-
87-
```sql
88-
SELECT * FROM sys.dm_exec_requests;
89-
GO
90-
```
91-
92-
Then, to obtain the live query plan and execution statistics, use the copied `session_id` with system function **sys.dm_exec_query_statistics_xml**.
93-
94-
```sql
95-
--Run this in a different session than the session in which your query is running.
96-
SELECT * FROM sys.dm_exec_query_statistics_xml(< copied session_id >);
97-
GO
98-
```
99-
100-
Or combined for all running requests.
101-
102-
```sql
103-
--Run this in a different session than the session in which your query is running.
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;
62+
63+
This system function is available starting with [!INCLUDE [sssql16-md](../../includes/sssql16-md.md)] with Service Pack 1. For more information, see [KB 3190871](https://support.microsoft.com/help/3190871).
64+
65+
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).
66+
67+
Under the following conditions, no Showplan output is returned in the `query_plan` column of the returned table for `sys.dm_exec_query_statistics_xml`:
68+
69+
- If the query plan that corresponds to the specified *session_id* is no longer executing, the `query_plan` column of the returned table is null. For example, this condition might occur if there's a time delay between when the plan handle was captured and when it was used with `sys.dm_exec_query_statistics_xml`
70+
71+
Due to a limitation in the number of nested levels allowed in the **xml** data type, `sys.dm_exec_query_statistics_xml` can't return query plans that meet or exceed 128 levels of nested elements. In earlier versions of [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)], this condition prevented the query plan from returning and generates error 6335. In [!INCLUDE [ssVersion2005](../../includes/ssversion2005-md.md)] Service Pack 2 and later versions, the `query_plan` column returns `NULL`.
72+
73+
## Permissions
74+
75+
Requires `VIEW SERVER STATE` permission on the server, in [!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and earlier versions.
76+
77+
Requires `VIEW SERVER PERFORMANCE STATE` permission on the server, in [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions.
78+
79+
Requires the `VIEW DATABASE STATE` permission in the database, on [!INCLUDE [ssSDS](../../includes/sssds-md.md)] Premium Tiers.
80+
81+
Requires the **Server admin** or a [Microsoft Entra admin](/azure/azure-sql/database/authentication-aad-overview#administrator-structure) account on [!INCLUDE [ssSDS](../../includes/sssds-md.md)] Standard and Basic Tiers.
82+
83+
## Examples
84+
85+
### A. Look at live query plan and execution statistics for a running batch
86+
87+
The following example queries `sys.dm_exec_requests` to find the interesting query and copy its `session_id` from the output.
88+
89+
```sql
90+
SELECT *
91+
FROM sys.dm_exec_requests;
12592
GO
126-
```
127-
128-
## See Also
129-
[Trace Flags](../../t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql.md)
130-
[Dynamic Management Views and Functions &#40;Transact-SQL&#41;](~/relational-databases/system-dynamic-management-views/system-dynamic-management-views.md)
131-
[Database Related Dynamic Management Views &#40;Transact-SQL&#41;](../../relational-databases/system-dynamic-management-views/database-related-dynamic-management-views-transact-sql.md)
93+
```
94+
95+
Then, to obtain the live query plan and execution statistics, use the copied `session_id` with system function `sys.dm_exec_query_statistics_xml`. Run this query in a different session than the session in which your query is running.
96+
97+
```sql
98+
SELECT * FROM sys.dm_exec_query_statistics_xml(< copied session_id >);
99+
GO
100+
```
101+
102+
Or, combined for all running requests. Run this query in a different session than the session in which your query is running.
103+
104+
```sql
105+
SELECT 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 AS er
123+
CROSS APPLY sys.dm_exec_query_statistics_xml(session_id) AS eqs
124+
WHERE er.session_id <> @@SPID;
125+
GO
126+
```
127+
128+
## Related content
129+
130+
- [DBCC TRACEON - Trace Flags (Transact-SQL)](../../t-sql/database-console-commands/dbcc-traceon-trace-flags-transact-sql.md)
131+
- [System dynamic management views](system-dynamic-management-views.md)
132+
- [Database related dynamic management views (Transact-SQL)](database-related-dynamic-management-views-transact-sql.md)

docs/relational-databases/system-dynamic-management-views/sys-dm-os-host-info-transact-sql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "sys.dm_os_host_info (Transact-SQL)"
33
description: The sys.dm_os_host_info DMV returns one row that displays operating system version information.
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: 11/20/2023
6+
ms.date: 03/31/2025
77
ms.service: sql
88
ms.subservice: system-objects
99
ms.topic: conceptual
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
22
title: "sys.dm_pdw_component_health_alerts (Transact-SQL)"
3-
description: sys.dm_pdw_component_health_alerts (Transact-SQL)
3+
description: sys.dm_pdw_component_health_alerts stores previously issued alerts on appliance components.
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: "03/07/2017"
6+
ms.date: 03/31/2025
77
ms.service: sql
88
ms.subservice: data-warehouse
99
ms.topic: conceptual
@@ -12,22 +12,26 @@ dev_langs:
1212
monikerRange: ">=aps-pdw-2016"
1313
---
1414
# sys.dm_pdw_component_health_alerts (Transact-SQL)
15+
1516
[!INCLUDE [pdw](../../includes/applies-to-version/pdw.md)]
1617

17-
Stores previously issued alerts on appliance components.
18-
19-
|Column Name|Data Type|Description|Range|
20-
|-----------------|---------------|-----------------|-----------|
21-
|pdw_node_id|**int**|Unique identifier of a [!INCLUDE[ssPDW](../../includes/sspdw-md.md)] node.<br /><br /> pdw_node_id, component_id, component_instance_id, alert_id, and alert_instance_id form the key for this view.|NOT NULL|
22-
|component_id|**int**|The ID of the component. See [sys.pdw_health_components &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-pdw-health-components-transact-sql.md).<br /><br /> pdw_node_id, component_id, component_instance_id, alert_id, and alert_instance_id form the key for this view.|NOT NULL|
23-
|component_instance_id|**nvarchar(255)**|pdw_node_id, component_id, component_instance_id, alert_id, and alert_instance_id form the key for this view.|NOT NULL|
24-
|alert_id|**int**|The ID for the alert type. See [sys.pdw_health_alerts &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-pdw-health-alerts-transact-sql.md).<br /><br /> pdw_node_id, component_id, component_instance_id, alert_id, and alert_instance_id form the key for this view.|NOT NULL|
25-
|alert_instance_id|**nvarchar(36)**|Identifies an instance of a given alert.<br /><br /> pdw_node_id, component_id, component_instance_id, alert_id, and alert_instance_id form the key for this view.|NOT NULL|
26-
|previous_value|**nvarchar(255)**|Used when the alert is of type StatusChange. This is the previous component status. Value is NULL for alerts of type Threshold. See [sys.pdw_health_alerts &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-pdw-health-alerts-transact-sql.md) for a list of alert types.|NULL|
27-
|current_value|**nvarchar(255)**|Used when the alert is of type StatusChange. This is the current component status. Value is NULL for alerts of type Threshold. See [sys.pdw_health_alerts &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-pdw-health-alerts-transact-sql.md) for a list of alert types.|NULL|
28-
|create_time|**datetime**|Time and date when the alert was generated.|NOT NULL|
29-
30-
## See Also
31-
[Azure Synapse Analytics and Parallel Data Warehouse Dynamic Management Views &#40;Transact-SQL&#41;](../../relational-databases/system-dynamic-management-views/sql-and-parallel-data-warehouse-dynamic-management-views.md)
32-
33-
18+
Stores previously issued alerts on appliance components.
19+
20+
| Column Name | Data Type | Description |
21+
| --- | --- | --- |
22+
| `pdw_node_id` | **int** | Unique identifier of a [!INCLUDE [ssPDW](../../includes/sspdw-md.md)] node. Not nullable. |
23+
| `component_id` | **int** | The ID of the component. For more information, see [sys.pdw_health_components](../system-catalog-views/sys-pdw-health-components-transact-sql.md). Not nullable. |
24+
| `component_instance_id` | **nvarchar(255)** | `pdw_node_id`, `component_id`, `component_instance_id`, `alert_id`, and `alert_instance_id` form the key for this view. Not nullable. |
25+
| `alert_id` | **int** | The ID for the alert type. For more information, see [sys.pdw_health_alerts](../system-catalog-views/sys-pdw-health-alerts-transact-sql.md). Not nullable. |
26+
| `alert_instance_id` | **nvarchar(36)** | Identifies an instance of a given alert. Not nullable. |
27+
| `previous_value` <sup>2</sup> | **nvarchar(255)** | Used when the alert is of type `StatusChange`. This is the previous component status. Value is `NULL` for alerts of type `Threshold`. Nullable. |
28+
| `current_value` <sup>2</sup> | **nvarchar(255)** | Used when the alert is of type `StatusChange`. This is the current component status. Value is `NULL` for alerts of type `Threshold`. Nullable. |
29+
| `create_time` | **datetime** | Time and date when the alert was generated. Not nullable. |
30+
31+
<sup>1</sup> `pdw_node_id`, `component_id`, `component_instance_id`, `alert_id`, and `alert_instance_id` form the key for this view.
32+
33+
<sup>2</sup> See [sys.pdw_health_alerts](../system-catalog-views/sys-pdw-health-alerts-transact-sql.md) for a list of alert types.
34+
35+
## Related content
36+
37+
- [SQL and Parallel Data Warehouse Dynamic Management Views](sql-and-parallel-data-warehouse-dynamic-management-views.md)

0 commit comments

Comments
 (0)