Skip to main content
The SHOW STATISTICS lists used by the . By default, CockroachDB on all indexed columns and up to 100 non-indexed columns, and automatically collects on the columns that prefix each index.

Synopsis

show_stats syntax diagram

Required Privileges

To list table statistics, the user must have any on the table being inspected.

Parameters

ParameterDescription
table\_nameThe name of the table to view statistics for.
opt\_with\_optionsControl the behavior of SHOW STATISTICS with these options.

Options

OptionValueDescription
FORECASTN/ADisplay forecasted statistics along with the existing table statistics.

Output

ColumnDescription
statistics\_nameThe name of the statistics. If \_\_auto\_\_, the statistics were created automatically. If \_\_forecast\_\_, the statistics are forecasted.
column\_namesThe name of the columns on which the statistics were created.
createdThe when the statistics were created.
row\_countThe number of rows for which the statistics were computed.
distinct\_countThe number of distinct values for which the statistics were computed.
null\_countThe number of null values for which the statistics were computed.
avg\_sizeThe average size in bytes of the values of the columns for which the statistics were computed.
histogram\_idThe ID of the used to compute statistics.

Examples

Setup

To follow along, run to start a temporary, in-memory cluster with the sample dataset preloaded:

List table statistics

Display forecasted statistics

The WITH FORECAST option calculates and displays along with the existing table statistics. The following example shows 3 historical statistics collections and the subsequent forecast:

Delete statistics

To delete statistics for all tables in all databases:
To delete a named set of statistics (e.g, one named “users_stats”), run a query like the following:
For more information about the DELETE statement, see .

See also