Skip to content

Commit 6e8594b

Browse files
authored
Merge pull request #33810 from thesqlsith/patch-1
Update sys-dm-db-missing-index-group-stats-query-transact-sql.md
2 parents 08a6702 + db850ac commit 6e8594b

File tree

1 file changed

+56
-57
lines changed

1 file changed

+56
-57
lines changed

docs/relational-databases/system-dynamic-management-views/sys-dm-db-missing-index-group-stats-query-transact-sql.md

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "sys.dm_db_missing_index_group_stats_query (Transact-SQL)"
33
description: The sys.dm_db_missing_index_group_stats_query dynamic management view returns information about queries that needed a missing index from groups of missing indexes.
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: "02/24/2023"
6+
ms.date: 04/15/2025
77
ms.service: sql
88
ms.subservice: system-objects
99
ms.topic: "reference"
@@ -17,61 +17,60 @@ helpviewer_keywords:
1717
- "missing indexes feature [SQL Server], sys.dm_db_missing_index_group_stats_query dynamic management view"
1818
dev_langs:
1919
- "TSQL"
20-
monikerRange: "=azuresqldb-current||>=sql-server-ver15||>=sql-server-linux-ver15||=azuresqldb-mi-current"
20+
monikerRange: "=azuresqldb-current || >=sql-server-ver15 || >=sql-server-linux-ver15 || =azuresqldb-mi-current"
2121
---
2222
# sys.dm_db_missing_index_group_stats_query (Transact-SQL)
23+
2324
[!INCLUDE [SQL Server 2019 SQL Database](../../includes/applies-to-version/sqlserver2019-asdb-asdbmi.md)]
2425

25-
Returns information about queries that needed a missing index from groups of missing indexes, excluding spatial indexes. More than one query may be returned per missing index group. One missing index group may have several queries that needed the same index.
26-
27-
In [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)], dynamic management views cannot expose information that would impact database containment or expose information about other databases the user has access to. To avoid exposing this information, every row that contains data that doesn't belong to the connected tenant is filtered out.
28-
29-
|Column name|Data type|Description|
30-
|-----------------|---------------|-----------------|
31-
|**group_handle**|**int**|Identifies a group of missing indexes. This identifier is unique across the server.<br /><br /> The other columns provide information about all queries for which the index in the group is considered missing.<br /><br /> An index group contains only one index.<BR><BR>Can be joined to `index_group_handle` in [sys.dm_db_missing_index_groups](../../relational-databases/system-dynamic-management-views/sys-dm-db-missing-index-groups-transact-sql.md).|
32-
|**query_hash**|**binary(8)**|Binary hash value calculated on the query and used to identify queries with similar logic. You can use the query hash to determine the aggregate resource usage for queries that differ only by literal values.|
33-
|**query_plan_hash**|**binary(8)**|Binary hash value calculated on the query execution plan and used to identify similar query execution plans. You can use query plan hash to find the cumulative cost of queries with similar execution plans.<br /><br /> Will always be 0x000 when a natively compiled stored procedure queries a memory-optimized table.|
34-
|**last_sql_handle**|**varbinary(64)**|Is a token that uniquely identifies the batch or stored procedure of the last compiled statement that needed this index.<BR><BR>The `last_sql_handle` can be used to retrieve the SQL text of the query by calling the dynamic management function [sys.dm_exec_sql_text](../../relational-databases/system-dynamic-management-views/sys-dm-exec-sql-text-transact-sql.md).|
35-
|**last_statement_start_offset**|**int**|Indicates, in bytes, beginning with 0, the starting position of the query that the row describes within the text of its batch or persisted object for the last compiled statement that needed this index in its SQL batch.|
36-
|**last_statement_end_offset**|**int**|Indicates, in bytes, beginning with 0, the ending position of the query that the row describes within the text of its batch or persisted object for the last compiled statement that needed this index in its SQL batch.|
37-
|**last_statement_sql_handle**|**varbinary(64)**|Is a token that uniquely identifies the batch or stored procedure of the last compiled statement that needed this index. Used by Query Store. Unlike `last_sql_handle`, `sys.query_store_query_text` references the `statement_sql_handle` used by the Query Store catalog view [sys.query_store_query_text](../system-catalog-views/sys-query-store-query-text-transact-sql.md).<BR><BR>If Query Store was not enabled when the query was compiled, returns 0.|
38-
|**user_seeks**|**bigint**|Number of seeks caused by user queries that the recommended index in the group could have been used for.|
39-
|**user_scans**|**bigint**|Number of scans caused by user queries that the recommended index in the group could have been used for.|
40-
|**last_user_seek**|**datetime**|Date and time of last seek caused by user queries that the recommended index in the group could have been used for.|
41-
|**last_user_scan**|**datetime**|Date and time of last scan caused by user queries that the recommended index in the group could have been used for.|
42-
|**avg_total_user_cost**|**float**|Average cost of the user queries that could be reduced by the index in the group.|
43-
|**avg_user_impact**|**float**|Average percentage benefit that user queries could experience if this missing index group was implemented. The value means that the query cost would on average drop by this percentage if this missing index group was implemented.|
44-
|**system_seeks**|**bigint**|Number of seeks caused by system queries, such as auto stats queries, that the recommended index in the group could have been used for. For more information, see [Auto Stats Event Class](../../relational-databases/event-classes/auto-stats-event-class.md).|
45-
|**system_scans**|**bigint**|Number of scans caused by system queries that the recommended index in the group could have been used for.|
46-
|**last_system_seek**|**datetime**|Date and time of last system seek caused by system queries that the recommended index in the group could have been used for.|
47-
|**last_system_scan**|**datetime**|Date and time of last system scan caused by system queries that the recommended index in the group could have been used for.|
48-
|**avg_total_system_cost**|**float**|Average cost of the system queries that could be reduced by the index in the group.|
49-
|**avg_system_impact**|**float**|Average percentage benefit that system queries could experience if this missing index group was implemented. The value means that the query cost would on average drop by this percentage if this missing index group was implemented.|
50-
51-
## Remarks
52-
Information returned by `sys.dm_db_missing_index_group_stats_query` is updated by every query execution, not by every query compilation or recompilation. Usage statistics are not persisted and are kept only until the database engine is restarted.
26+
Returns information about queries that needed a missing index from groups of missing indexes, excluding spatial indexes. More than one query might be returned per missing index group. One missing index group might have several queries that needed the same index.
27+
28+
In [!INCLUDE [ssazure-sqldb](../../includes/ssazure-sqldb.md)], dynamic management views can't expose information that would affect database containment, or expose information about other databases the user has access to. To avoid exposing this information, every row that contains data that doesn't belong to the connected tenant is filtered out.
29+
30+
| Column name | Data type | Description |
31+
| --- | --- | --- |
32+
| `group_handle` | **int** | Identifies a group of missing indexes. This identifier is unique across the server.<br /><br />The other columns provide information about all queries for which the index in the group is considered missing.<br /><br />An index group contains only one index.<br /><br />Can be joined to `index_group_handle` in [sys.dm_db_missing_index_groups](sys-dm-db-missing-index-groups-transact-sql.md). |
33+
| `query_hash` | **binary(8)** | Binary hash value calculated on the query and used to identify queries with similar logic. You can use the query hash to determine the aggregate resource usage for queries that differ only by literal values. |
34+
| `query_plan_hash` | **binary(8)** | Binary hash value calculated on the query execution plan and used to identify similar query execution plans. You can use query plan hash to find the cumulative cost of queries with similar execution plans.<br /><br />Always `0x000` when a natively compiled stored procedure queries a memory-optimized table. |
35+
| `last_sql_handle` | **varbinary(64)** | A token that uniquely identifies the batch or stored procedure of the last compiled statement that needed this index.<br /><br />The `last_sql_handle` can be used to retrieve the SQL text of the query by calling the dynamic management function [sys.dm_exec_sql_text](sys-dm-exec-sql-text-transact-sql.md). |
36+
| `last_statement_start_offset` | **int** | Indicates, in bytes, beginning with 0, the starting position of the query that the row describes within the text of its batch or persisted object for the last compiled statement that needed this index in its SQL batch. |
37+
| `last_statement_end_offset` | **int** | Indicates, in bytes, beginning with `0`, the ending position of the query that the row describes within the text of its batch or persisted object, for the last compiled statement that needed this index in its SQL batch. |
38+
| `last_statement_sql_handle` | **varbinary(64)** | A token that uniquely identifies the batch or stored procedure of the last compiled statement that needed this index. Used by Query Store. Unlike `last_sql_handle`, `sys.query_store_query_text` references the `statement_sql_handle` used by the Query Store catalog view [sys.query_store_query_text](../system-catalog-views/sys-query-store-query-text-transact-sql.md).<br /><br />Returns `0` if Query Store wasn't enabled when the query was compiled. |
39+
| `user_seeks` | **bigint** | Number of seeks caused by user queries that the recommended index in the group could have been used for. |
40+
| `user_scans` | **bigint** | Number of scans caused by user queries that the recommended index in the group could have been used for. |
41+
| `last_user_seek` | **datetime** | Date and time of last seek caused by user queries that the recommended index in the group could have been used for. |
42+
| `last_user_scan` | **datetime** | Date and time of last scan caused by user queries that the recommended index in the group could have been used for. |
43+
| `avg_total_user_cost` | **float** | Average cost of the user queries that could be reduced by the index in the group. |
44+
| `avg_user_impact` | **float** | Average percentage benefit that user queries could experience if this missing index group was implemented. The value means that the query cost would on average drop by this percentage if this missing index group was implemented. |
45+
| `system_seeks` | **bigint** | Number of seeks caused by system queries, such as auto stats queries, that the recommended index in the group could have been used for. For more information, see [Auto Stats Event Class](../event-classes/auto-stats-event-class.md). |
46+
| `system_scans` | **bigint** | Number of scans caused by system queries that the recommended index in the group could have been used for. |
47+
| `last_system_seek` | **datetime** | Date and time of last system seek caused by system queries that the recommended index in the group could have been used for. |
48+
| `last_system_scan` | **datetime** | Date and time of last system scan caused by system queries that the recommended index in the group could have been used for. |
49+
| `avg_total_system_cost` | **float** | Average cost of the system queries that could be reduced by the index in the group. |
50+
| `avg_system_impact` | **float** | Average percentage benefit that system queries could experience if this missing index group was implemented. The value means that the query cost would on average drop by this percentage if this missing index group was implemented. |
51+
52+
## Remarks
53+
54+
Information returned by `sys.dm_db_missing_index_group_stats_query` is updated by every query execution, not by every query compilation or recompilation. Usage statistics aren't persisted and are kept only until the database engine is restarted.
5355

5456
Database administrators should periodically make backup copies of the missing index information if they want to keep the usage statistics after server recycling. Use the `sqlserver_start_time` column in [sys.dm_os_sys_info](sys-dm-os-sys-info-transact-sql.md) to find the last database engine startup time. You can also [persist missing indexes with Query Store](../indexes/tune-nonclustered-missing-index-suggestions.md#persist-missing-indexes-with-query-store).
55-
56-
>[!NOTE]
57-
>The result set for this DMV is limited to 600 rows. Each row contains one missing index. If you have more than 600 missing indexes, you should address the existing missing indexes so you can then view the newer ones.
5857

59-
## Permissions
60-
To query this dynamic management view, users must be granted the VIEW SERVER STATE permission or any permission that implies the VIEW SERVER STATE permission.
61-
62-
### Permissions for SQL Server 2022 and later
58+
## Permissions
59+
60+
To query this dynamic management view, users must be granted the `VIEW SERVER STATE` permission or any permission that implies the `VIEW SERVER STATE` permission, for [!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and previous versions.
61+
62+
Requires VIEW SERVER PERFORMANCE STATE permission on the server, for [!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions.
63+
64+
## Examples
65+
66+
The following examples illustrate how to use the `sys.dm_db_missing_index_group_stats_query` dynamic management view.
6367

64-
Requires VIEW SERVER PERFORMANCE STATE permission on the server.
68+
### A. Find the latest query text for the top 10 highest anticipated improvements for user queries
6569

66-
## Examples
67-
The following examples illustrate how to use the `sys.dm_db_missing_index_group_stats_query` dynamic management view.
68-
69-
70-
### A. Find the latest query text for the top 10 highest anticipated improvements for user queries
71-
The following query returns the last recorded query text for the 10 missing indexes that would produce the highest anticipated cumulative improvement, in descending order.
70+
The following query returns the last recorded query text for the 10 missing indexes that would produce the highest anticipated cumulative improvement, in descending order.
7271

7372
```sql
74-
SELECT TOP 10
73+
SELECT TOP 10
7574
SUBSTRING
7675
(
7776
sql_text.text,
@@ -86,19 +85,19 @@ SELECT TOP 10
8685
misq.*
8786
FROM sys.dm_db_missing_index_group_stats_query AS misq
8887
CROSS APPLY sys.dm_exec_sql_text(misq.last_sql_handle) AS sql_text
89-
ORDER BY misq.avg_total_user_cost * misq.avg_user_impact * (misq.user_seeks + misq.user_scans) DESC;
88+
ORDER BY misq.avg_total_user_cost
89+
* misq.avg_user_impact
90+
* (misq.user_seeks + misq.user_scans) DESC;
9091
```
91-
92-
## Next steps
9392

94-
Learn more about the missing index feature and related concepts in the following articles:
93+
## Related content
9594

9695
- [Tune nonclustered indexes with missing index suggestions](../indexes/tune-nonclustered-missing-index-suggestions.md)
97-
- [sys.dm_db_missing_index_columns &#40;Transact-SQL&#41;](../../relational-databases/system-dynamic-management-views/sys-dm-db-missing-index-columns-transact-sql.md)
98-
- [sys.dm_db_missing_index_details &#40;Transact-SQL&#41;](../../relational-databases/system-dynamic-management-views/sys-dm-db-missing-index-details-transact-sql.md)
99-
- [sys.dm_db_missing_index_groups &#40;Transact-SQL&#41;](../../relational-databases/system-dynamic-management-views/sys-dm-db-missing-index-groups-transact-sql.md)
100-
- [sys.dm_db_missing_index_group_stats &#40;Transact-SQL&#41;](../../relational-databases/system-dynamic-management-views/sys-dm-db-missing-index-group-stats-transact-sql.md)
101-
- [sys.dm_exec_sql_text &#40;Transact-SQL&#41;](../../relational-databases/system-dynamic-management-views/sys-dm-exec-sql-text-transact-sql.md)
102-
- [CREATE INDEX &#40;Transact-SQL&#41;](../../t-sql/statements/create-index-transact-sql.md)
103-
- [sys.dm_os_sys_info &#40;Transact-SQL&#41;](sys-dm-os-sys-info-transact-sql.md)
104-
- [Query Store](../performance/monitoring-performance-by-using-the-query-store.md)
96+
- [sys.dm_db_missing_index_columns (Transact-SQL)](sys-dm-db-missing-index-columns-transact-sql.md)
97+
- [sys.dm_db_missing_index_details (Transact-SQL)](sys-dm-db-missing-index-details-transact-sql.md)
98+
- [sys.dm_db_missing_index_groups (Transact-SQL)](sys-dm-db-missing-index-groups-transact-sql.md)
99+
- [sys.dm_db_missing_index_group_stats (Transact-SQL)](sys-dm-db-missing-index-group-stats-transact-sql.md)
100+
- [sys.dm_exec_sql_text (Transact-SQL)](sys-dm-exec-sql-text-transact-sql.md)
101+
- [CREATE INDEX (Transact-SQL)](../../t-sql/statements/create-index-transact-sql.md)
102+
- [sys.dm_os_sys_info (Transact-SQL)](sys-dm-os-sys-info-transact-sql.md)
103+
- [Monitor performance by using the Query Store](../performance/monitoring-performance-by-using-the-query-store.md)

0 commit comments

Comments
 (0)