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