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 timestamp 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

The following examples use MovR, a fictional vehicle-sharing application, to demonstrate CockroachDB SQL statements. For more information about the MovR example application and dataset, see . To follow along, run to start a temporary, in-memory cluster with the movr dataset preloaded:

List table statistics

Display forecasted statistics

The WITH FORECAST option calculates and displays forecasted statistics along with the existing table statistics. The forecast is a simple regression model that predicts how the statistics have changed since they were last collected. Forecasts that closely match the historical statistics are used by the . CockroachDB generates forecasted statistics when the following conditions are met:
  • There have been at least 3 historical statistics collections.
  • The historical statistics closely fit a linear pattern.
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