---
title: SHOW STATISTICS
description: Learn how to use SHOW STATISTICS ... AS JSON to return optimizer table and column statistics in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-show-statistics
---

# SHOW STATISTICS

**Applies to:** ![check marked yes](https://docs.databricks.com/gcp/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/gcp/en/images/icons/check.png) Databricks Runtime 18 LTS and above

> [!NOTE]
>
> Databricks Runtime 18 is newer than Databricks Runtime 18.0, 18.1, and 18.2. Features that would previously have shipped as a later numbered version now ship as dated updates to Databricks Runtime 18 instead. For details, see [About unified release notes](https://docs.databricks.com/gcp/en/release-notes/runtime/18.md#unified-format).

Returns optimizer statistics for a table as a JSON document, including table-level statistics and optionally per-column statistics.

Databricks recommends `SHOW STATISTICS` for reading optimizer statistics programmatically. It returns only statistics, without the schema, storage, properties, partitions, and other metadata included in [DESCRIBE TABLE EXTENDED ... AS JSON](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-describe-table.md). Use [ANALYZE TABLE ... COMPUTE STATISTICS](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-statistics.md) (or [predictive optimization](https://docs.databricks.com/gcp/en/optimizations/predictive-optimization.md)) to collect the statistics that this command reports.

## Required permissions

To run `SHOW STATISTICS` on a Unity Catalog table, you need:

* `USE CATALOG` on the parent catalog.
* `USE SCHEMA` on the parent schema.
* `SELECT` on the table, or ownership of the table.

## Syntax

```
SHOW STATISTICS [ { FROM | IN } ] table_name
    [ FOR COLUMNS column_name [, ...] | FOR ALL COLUMNS ]
    AS JSON
```

The `FROM` and `IN` keywords are optional and interchangeable.

## Parameters

* **[table\_name](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-names.md#table-name)**

  Identifies the table to report statistics for. The name must not include a [temporal specification or options specification](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-names.md#table-name).

  If the table cannot be found, Databricks raises a [TABLE\_OR\_VIEW\_NOT\_FOUND](https://docs.databricks.com/gcp/en/error-messages/table-or-view-not-found-error-class.md) error.

  Views (temporary or persistent) are not supported. Invoking `SHOW STATISTICS` on a view raises [EXPECT\_TABLE\_NOT\_VIEW.NO\_ALTERNATIVE](https://docs.databricks.com/gcp/en/error-messages/expect-table-not-view-error-class.md). Use `DESCRIBE EXTENDED` for view metadata.

* **FOR COLUMNS [column\_name](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-names.md#column-name) \[, ...]**

  Adds an entry to `statistics.column_statistics` for each named column.

  If any named column does not exist on the table, the command raises [COLUMN\_NOT\_FOUND](https://docs.databricks.com/gcp/en/error-messages/error-classes.md#column_not_found).

* **FOR ALL COLUMNS**

  Adds an entry to `statistics.column_statistics` for every atomic-typed top-level column of the table.

  Columns whose data type is [STRUCT](https://docs.databricks.com/gcp/en/sql/language-manual/data-types/struct-type.md), [ARRAY](https://docs.databricks.com/gcp/en/sql/language-manual/data-types/array-type.md), or [MAP](https://docs.databricks.com/gcp/en/sql/language-manual/data-types/map-type.md) are excluded, because the optimizer does not collect statistics on complex types. Nested fields are not enumerated.

* **AS JSON**

  Required. The result is returned as a single JSON-formatted `STRING`.

## JSON-formatted output

The returned JSON document uses the following schema:

```
{
  "table_name": "<table_name>",
  "catalog_name": "<catalog_name>",
  "namespace": ["<schema_name>"],
  "schema_name": "<schema_name>",
  "statistics": {
    "size_in_bytes": <bytes>,
    "num_rows": <count>,
    "collection_source": "<collection_source>",
    "created_at": "<created_at_timestamp>",
    "column_statistics": {
      "<column_name>": {
        "min": "<min_value>",
        "max": "<max_value>",
        "distinct_count": <count>,
        "num_nulls": <count>,
        "avg_len": <bytes>,
        "max_len": <bytes>,
        "has_histogram": <boolean>,
        "has_mcv": <boolean>,
        "has_kll_sketch": <boolean>
      }
    }
  }
}
```

* **statistics.size\_in\_bytes**

  Total size of the table data in bytes, as known to the optimizer. Omitted when no table-level statistics exist.

* **statistics.num\_rows**

  Row count, as known to the optimizer. `null` if not collected.

* **statistics.collection\_source**

  How the table-level statistics were produced. One of:

  * **Manual Analyze** — collected by `ANALYZE TABLE ... COMPUTE STATISTICS`.
  * **Auto Stats** — collected automatically during a write.
  * **Predictive Analyze** — collected by [predictive optimization](https://docs.databricks.com/gcp/en/optimizations/predictive-optimization.md).
  * **Unknown** — collected by an unrecognized source.
  * `null` — no table-level statistics are available.

* **statistics.created\_at**

  When the table-level statistics were collected, as an ISO 8601 UTC timestamp (for example, `2026-05-29T08:14:24.845Z`). `null` if not collected.

* **statistics.column\_statistics**

  Included only when `FOR COLUMNS` or `FOR ALL COLUMNS` is specified. Maps each requested column to its per-column statistics.

  The following fields are always present, with `null` when not collected:

  * **min**, **max** — minimum and maximum values, rendered as JSON strings.
  * **distinct\_count** — number of distinct values (`NDV`).
  * **num\_nulls** — number of `NULL` values.
  * **avg\_len**, **max\_len** — average and maximum value length in bytes.
  * **has\_histogram** — `true` if an equi-height histogram is available for the column.

  The following fields appear only when the corresponding sketch collection is enabled, and are omitted otherwise:

  * **has\_mcv** — `true` if a most-common-values list is available for the column.
  * **has\_kll\_sketch** — `true` if a KLL sketch is available for the column.

## Examples

```sql
-- Set up a table and collect column statistics.
> CREATE TABLE customer(cust_id INT, name STRING, state STRING) USING parquet;
> INSERT INTO customer VALUES (100, 'Mike', 'AR'), (200, 'Jane', 'CA');
> ANALYZE TABLE customer COMPUTE STATISTICS FOR ALL COLUMNS;

-- Table-level statistics only.
> SHOW STATISTICS FROM customer AS JSON;
 {"table_name":"customer","catalog_name":"spark_catalog",
  "namespace":["default"],"schema_name":"default",
  "statistics":{"size_in_bytes":864,"num_rows":2,
                "collection_source":"Manual Analyze",
                "created_at":"2026-05-29T08:14:24.845Z"}}

-- Per-column statistics for a list of columns.
> SHOW STATISTICS FROM customer FOR COLUMNS cust_id, name AS JSON;
 {"table_name":"customer","catalog_name":"spark_catalog",
  "namespace":["default"],"schema_name":"default",
  "statistics":{"size_in_bytes":864,"num_rows":2,
                "collection_source":"Manual Analyze",
                "created_at":"2026-05-29T08:14:24.845Z",
                "column_statistics":{
                  "cust_id":{"min":"100","max":"200","distinct_count":2,"num_nulls":0,
                             "avg_len":4,"max_len":4,"has_histogram":false,"has_mcv":false},
                  "name":   {"min":"Jane","max":"Mike","distinct_count":2,"num_nulls":0,
                             "avg_len":4,"max_len":4,"has_histogram":false,"has_mcv":false}}}}

-- All atomic top-level columns. STRUCT, ARRAY, and MAP columns are skipped.
> SHOW STATISTICS FROM customer FOR ALL COLUMNS AS JSON;
```

## Related articles

* [ANALYZE TABLE … COMPUTE STATISTICS](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-analyze-compute-statistics.md)
* [DESCRIBE TABLE](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-describe-table.md)
* [SHOW COLUMNS](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-aux-show-columns.md)
* [Predictive optimization for Unity Catalog managed tables](https://docs.databricks.com/gcp/en/optimizations/predictive-optimization.md)
