You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/relational-databases/system-dynamic-management-views/sys-dm-db-missing-index-group-stats-query-transact-sql.md
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.
[!INCLUDE [SQL Server 2019 SQL Database](../../includes/applies-to-version/sqlserver2019-asdb-asdbmi.md)]
24
25
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.
|**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.
53
55
54
56
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.
58
57
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.
63
67
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
65
69
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.
0 commit comments