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
description: DBCC SHOW_STATISTICS displays current query optimization statistics for a table or indexed view.
4
4
author: rwestMSFT
5
5
ms.author: randolphwest
6
-
ms.date: 08/29/2023
6
+
ms.date: 07/10/2025
7
7
ms.service: sql
8
8
ms.subservice: t-sql
9
9
ms.topic: reference
@@ -91,7 +91,7 @@ Name of the table that contains the statistics to display. The table can't be an
91
91
Name of the index, statistics, or column for which to display statistics information. *target* is enclosed in brackets, single quotes, double quotes, or no quotes.
92
92
93
93
- If *target* is a name of an existing index or statistics on a table or indexed view, the statistics information about this target is returned.
94
-
- If *target* is the name of an existing column, and an automatically created statistics object on this column exists, information about that auto-created statistic is returned.
94
+
- If *target* is the name of an existing column, and an automatically created statistics object on this column exists, information about that autocreated statistic is returned.
95
95
96
96
If an automatically created statistic doesn't exist for a column target, error message 2767 is returned.
97
97
@@ -116,38 +116,38 @@ The following table describes the columns returned in the result set when STAT_H
116
116
| Column name | Description |
117
117
| --- | --- |
118
118
| Name | Name of the statistics object. |
119
-
| Updated | Date and time the statistics were last updated. The [STATS_DATE](../../t-sql/functions/stats-date-transact-sql.md) function is an alternate way to retrieve this information. For more information, see the [Remarks](#remarks) section in this page. |
119
+
| Updated | Date and time the statistics were last updated. The [STATS_DATE](../functions/stats-date-transact-sql.md) function is an alternate way to retrieve this information. For more information, see the [Remarks](#remarks) section in this page. |
120
120
| Rows | Total number of rows in the table or indexed view when the statistics were last updated. If the statistics are filtered or correspond to a filtered index, the number of rows might be less than the number of rows in the table. For more information, see [Statistics](../../relational-databases/statistics/statistics.md). |
121
121
| Rows Sampled | Total number of rows sampled for statistics calculations. If Rows Sampled < Rows, the displayed histogram and density results are estimates based on the sampled rows. |
122
122
| Steps | Number of steps in the histogram. Each step spans a range of column values followed by an upper bound column value. The histogram steps are defined on the first key column in the statistics. The maximum number of steps is 200. |
123
123
| Density | Calculated as 1 / *distinct values* for all values in the first key column of the statistics object, excluding the histogram boundary values. This Density value isn't used by the Query Optimizer and is displayed for backward compatibility with versions before [!INCLUDE [sql2008-md](../../includes/sql2008-md.md)]. |
124
124
| Average Key Length | Average number of bytes per value for all of the key columns in the statistics object. |
125
125
| String Index | Yes indicates the statistics object contains string summary statistics to improve the cardinality estimates for query predicates that use the LIKE operator; for example, `WHERE ProductName LIKE '%Bike'`. String summary statistics are stored separately from the histogram and are created on the first key column of the statistics object when it's of type **char**, **varchar**, **nchar**, **nvarchar**, **varchar(max)**, **nvarchar(max)**, **text**, or **ntext.**. |
126
-
| Filter Expression | Predicate for the subset of table rows included in the statistics object. `NULL` = non-filtered statistics. For more information about filtered predicates, see [Create Filtered Indexes](../../relational-databases/indexes/create-filtered-indexes.md). For more information about filtered statistics, see [Statistics](../../relational-databases/statistics/statistics.md). |
126
+
| Filter Expression | Predicate for the subset of table rows included in the statistics object. `NULL` = non-filtered statistics. For more information about filtered predicates, see [Create filtered indexes](../../relational-databases/indexes/create-filtered-indexes.md). For more information about filtered statistics, see [Statistics](../../relational-databases/statistics/statistics.md). |
127
127
| Unfiltered Rows | Total number of rows in the table before applying the filter expression. If Filter Expression is `NULL`, `Unfiltered Rows` is equal to `Rows`. |
128
128
| Persisted Sample Percent | Persisted sample percentage used for statistic updates that don't explicitly specify a sampling percentage. If value is zero, then no persisted sample percentage is set for this statistic.<br /><br />**Applies to:**[!INCLUDE [sssql16-md](../../includes/sssql16-md.md)] Service Pack 1 CU 4 |
129
129
130
-
The following table describes the columns returned in the result set when DENSITY_VECTOR is specified.
130
+
The following table describes the columns returned in the result set when `DENSITY_VECTOR` is specified.
131
131
132
132
| Column name | Description |
133
133
| --- | --- |
134
134
| All Density | Density is 1 / *distinct values*. Results display density for each prefix of columns in the statistics object, one row per density. A distinct value is a distinct list of the column values per row and per columns prefix. For example, if the statistics object contains key columns (A, B, C), the results report the density of the distinct lists of values in each of these column prefixes: (A), (A,B), and (A, B, C). Using the prefix (A, B, C), each of these lists is a distinct value list: (3, 5, 6), (4, 4, 6), (4, 5, 6), (4, 5, 7). Using the prefix (A, B) the same column values have these distinct value lists: (3, 5), (4, 4), and (4, 5) |
135
135
| Average Length | Average length, in bytes, to store a list of the column values for the column prefix. For example, if the values in the list (3, 5, 6) each require 4 bytes the length is 12 bytes. |
136
136
| Columns | Names of columns in the prefix for which All density and Average length are displayed. |
137
137
138
-
The following table describes the columns returned in the result set when the HISTOGRAM option is specified.
138
+
The following table describes the columns returned in the result set when the `HISTOGRAM` option is specified.
139
139
140
140
| Column name | Description |
141
141
| --- | --- |
142
-
| RANGE_HI_KEY | Upper bound column value for a histogram step. The column value is also called a key value. |
143
-
| RANGE_ROWS | Estimated number of rows whose column value falls within a histogram step, excluding the upper bound. |
144
-
| EQ_ROWS | Estimated number of rows whose column value equals the upper bound of the histogram step. |
145
-
| DISTINCT_RANGE_ROWS | Estimated number of rows with a distinct column value within a histogram step, excluding the upper bound. |
146
-
| AVG_RANGE_ROWS | Average number of rows with duplicate column values within a histogram step, excluding the upper bound. When DISTINCT_RANGE_ROWS is greater than 0, AVG_RANGE_ROWS is calculated by dividing RANGE_ROWS by DISTINCT_RANGE_ROWS. When DISTINCT_RANGE_ROWS is 0, AVG_RANGE_ROWS returns 1 for the histogram step. |
142
+
|`RANGE_HI_KEY`| Upper bound column value for a histogram step. The column value is also called a key value. |
143
+
|`RANGE_ROWS`| Estimated number of rows whose column value falls within a histogram step, excluding the upper bound. |
144
+
|`EQ_ROWS`| Estimated number of rows whose column value equals the upper bound of the histogram step. |
145
+
|`DISTINCT_RANGE_ROWS`| Estimated number of rows with a distinct column value within a histogram step, excluding the upper bound. |
146
+
|`AVG_RANGE_ROWS`| Average number of rows with duplicate column values within a histogram step, excluding the upper bound. When `DISTINCT_RANGE_ROWS` is greater than 0, `AVG_RANGE_ROWS` is calculated by dividing `RANGE_ROWS` by `DISTINCT_RANGE_ROWS`. When `DISTINCT_RANGE_ROWS` is 0, `AVG_RANGE_ROWS` returns 1 for the histogram step. |
147
147
148
148
## Remarks
149
149
150
-
Statistics update date is stored in the [statistics blob object](../../relational-databases/statistics/statistics.md#DefinitionQOStatistics) together with the [histogram](#histogram) and [density vector](#density), not in the metadata. When no data is read to generate statistics data, the statistics blob isn't created, the date isn't available, and the *updated* column is `NULL`. This is the case for filtered statistics for which the predicate doesn't return any rows, or for new empty tables.
150
+
Statistics update date is stored in the [statistics blob object](../../relational-databases/statistics/statistics.md#DefinitionQOStatistics) together with the [histogram](#histogram) and [density vector](#density), not in the metadata. When no data is read to generate statistics data, the statistics blob isn't created, the date isn't available, and the `updated` column is `NULL`. This is the case for filtered statistics for which the predicate doesn't return any rows, or for new empty tables.
151
151
152
152
## Histogram
153
153
@@ -167,7 +167,9 @@ For each histogram step:
167
167
168
168
The query optimizer defines the histogram steps according to their statistical significance. It uses a maximum difference algorithm to minimize the number of steps in the histogram while maximizing the difference between the boundary values. The maximum number of steps is 200. The number of histogram steps can be fewer than the number of distinct values, even for columns with fewer than 200 boundary points. For example, a column with 100 distinct values can have a histogram with fewer than 100 boundary points.
169
169
170
-
## <aid="density"></a> Density vector
170
+
<aid="density"></a>
171
+
172
+
## Density vector
171
173
172
174
The query optimizer uses densities to enhance cardinality estimates for queries that return multiple columns from the same table or indexed view. The density vector contains one density for each prefix of columns in the statistics object. For example, if a statistics object has the key columns `CustomerId`, `ItemId` and `Price`, density is calculated on each of the following column prefixes.
173
175
@@ -185,29 +187,30 @@ The query optimizer uses densities to enhance cardinality estimates for queries
185
187
186
188
In order to view the statistics object, the user must have the `SELECT` permission on the table.
187
189
188
-
The following requirements exist for SELECT permissions to be sufficient to run the command:
190
+
The following requirements exist for `SELECT` permissions to be sufficient to run the command:
189
191
190
-
- Users must have permissions on all columns in the statistics object
191
-
- Users must have permission on all columns in a filter condition (if one exists)
192
+
- Users must have permissions on all columns in the statistics object.
193
+
- Users must have permission on all columns in a filter condition (if one exists).
192
194
- The table can't have a row-level security policy.
193
195
- If any of the columns within a statistics object is masked with Dynamic Data Masking rules, in addition to the `SELECT` permission, the user must have the `UNMASK` permission, or be a member of the **db_ddladmin** role.
194
196
195
-
In versions before [!INCLUDE [ssSQL11](../../includes/sssql11-md.md)] Service Pack 1, the user must own the table or the user must be a member of the **sysadmin** fixed server role, the **db_owner** fixed database role, or the **db_ddladmin** fixed database role.
197
+
In versions before [!INCLUDE [ssSQL11](../../includes/sssql11-md.md)] Service Pack 1, the user must own the table or the user must be a member of the **sysadmin** fixed server role, the **db_owner** fixed database role, or the **db_ddladmin** fixed database role. To change the behavior back to the pre [!INCLUDE [ssSQL11](../../includes/sssql11-md.md)] Service Pack 1 behavior, use Trace Flag 9485.
198
+
199
+
## Permissions for [!INCLUDE [fabric](../../includes/fabric.md)] Data Warehouse and [!INCLUDE [fabric-se](../../includes/fabric-se.md)]
196
200
197
-
> [!NOTE]
198
-
> To change the behavior back to the pre [!INCLUDE [ssSQL11](../../includes/sssql11-md.md)] Service Pack 1 behavior, use Trace Flag 9485.
201
+
In order to view the statistics object in Fabric Data Warehouse or the SQL analytics endpoint, the user must have the `SELECT` permission on the table, or a member of the Viewer Fabric workspace role or higher role membership.
199
202
200
203
## Permissions for [!INCLUDE [ssazuresynapse-md](../../includes/ssazuresynapse-md.md)] and [!INCLUDE [ssPDW](../../includes/sspdw-md.md)]
201
204
202
205
`DBCC SHOW_STATISTICS` requires `SELECT` permission on the table or membership in the **sysadmin** fixed server role, the **db_owner** fixed database role, or the **db_ddladmin** fixed database role.
203
206
204
207
## Limitations and Restrictions for [!INCLUDE [ssazuresynapse-md](../../includes/ssazuresynapse-md.md)] and [!INCLUDE [ssPDW](../../includes/sspdw-md.md)]
205
208
206
-
`DBCC SHOW_STATISTICS` shows statistics stored in the `Shell` database at the Control node level. It doesn't show statistics that are auto-created by [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] on the Compute nodes.
209
+
`DBCC SHOW_STATISTICS` shows statistics stored in the `Shell` database at the Control node level. It doesn't show statistics that are autocreated by [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] on the Compute nodes.
207
210
208
211
`DBCC SHOW_STATISTICS` isn't supported on external tables.
209
212
210
-
In [!INCLUDE [fabric](../../includes/fabric.md)], `DBCC SHOW_STATISTICS` only shows results for histogram statistics, not ACE-* statistics.
213
+
In [!INCLUDE [fabric](../../includes/fabric.md)], `DBCC SHOW_STATISTICS` only shows results for histogram statistics, not `ACE-*` statistics.
211
214
212
215
## Examples: SQL Server and Azure SQL Database
213
216
@@ -247,22 +250,19 @@ GO
247
250
248
251
The results show the header, the density vector, and part of the histogram.
0 commit comments