> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lancedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fragment column statistics for pruning

> Store the value range of a column for each fragment so that filtered queries skip the fragments that cannot match.

Enterprise only

Fragment column statistics store the minimum and maximum value of a column for
each fragment. A filtered query uses them to prune fragments: a fragment whose
value range cannot match the filter is skipped without being read.

Pruning pays off most when the values of the column follow the order in which
the data was written, as timestamps usually do. Take a table of 100 million
rows written in time order, stored as 100 fragments of 1 million rows each. A
filter on a narrow time range matches the range of a single fragment, so the
query prunes the other 99 fragments, about 99 million rows, and reads only the
remaining 1 million. That is about 100 times less data to read than a scan of
the whole table.

The statistics reuse the ZoneMap index mechanism, with `rows_per_zone` of at
least `1000000`, `store_null_bitmap = false` and `use_seeds = false`.

## Syntax

```sql theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
CREATE INDEX [<name>] ON <table> USING zonemap (<column>)
WITH (rows_per_zone = <rows>, store_null_bitmap = false [, use_seeds = false]);
```

| Option | Accepted values |
| - | - |
| `rows_per_zone` | An integer of at least `1000000`. Required. |
| `store_null_bitmap` | `false`. Required. |
| `use_seeds` | `false`, or omitted. |

No other values are supported. Without `WITH`, the statement builds an ordinary
ZoneMap index, which is not used to skip fragments.

The column can be a boolean, integer, floating-point, date, timestamp, string
or binary column.

## Create the statistics

The statistics are created with a SQL statement. From Python, send the same
statement through the SDK's SQL API.

> [tab] SQL
>
> ```sql theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
> CREATE INDEX events_updated_at_stats ON events USING zonemap (updated_at)
> WITH (rows_per_zone = 1000000, store_null_bitmap = false);
> ```

> [tab] Python
>
> Set `LANCEDB_DATABASE`, `LANCEDB_API_KEY`, `LANCEDB_REST_ENDPOINT`, and
> `LANCEDB_SQL_ENDPOINT` to the values for your deployment. Endpoints include their
> scheme and port, and the SQL endpoint may differ from the REST endpoint.
>
> ```python theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
> import os
>
> import lancedb
>
> db = lancedb.connect(
>     f"db://{os.environ['LANCEDB_DATABASE']}",
>     api_key=os.environ["LANCEDB_API_KEY"],
>     host_override=os.environ["LANCEDB_REST_ENDPOINT"],
>     sql_host_override=os.environ["LANCEDB_SQL_ENDPOINT"],
> )
>
> db.execute_query("""
>     CREATE INDEX events_updated_at_stats ON events USING zonemap (updated_at)
>     WITH (rows_per_zone = 1000000, store_null_bitmap = false)
> """).read_all()
> ```

The statement submits a build job and returns. Follow the job until it
succeeds:

> [tab] SQL
>
> ```sql theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
> SHOW JOBS FOR TABLE events;
> ```

> [tab] Python
>
> ```python theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
> print(db.execute_query("SHOW JOBS FOR TABLE events").read_all())
> ```

## Query with a filter

No query change is needed. A filter on the column prunes fragments in both SQL
queries and SDK queries.

> [tab] SQL
>
> ```sql theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
> SELECT id, updated_at
> FROM events
> WHERE updated_at >= timestamp '2026-01-05 03:15:00'
>   AND updated_at < timestamp '2026-01-05 03:45:00';
> ```

> [tab] Python
>
> Continue with the `db` connection from the previous step:
>
> ```python theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
> table = db.open_table("events")
>
> rows = (
>     table.search()
>     .where(
>         "updated_at >= timestamp '2026-01-05 03:15:00' "
>         "AND updated_at < timestamp '2026-01-05 03:45:00'"
>     )
>     .select(["id", "updated_at"])
>     .to_arrow()
> )
> ```
>
> The SDK's SQL API runs the SQL query from the other tab and prunes the same
> way:
>
> ```python theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
> rows = db.execute_query("""
>     SELECT id, updated_at
>     FROM events
>     WHERE updated_at >= timestamp '2026-01-05 03:15:00'
>       AND updated_at < timestamp '2026-01-05 03:45:00'
> """).read_all()
> ```

## Check that fragments were pruned

`EXPLAIN ANALYZE` reports how many fragments remained after pruning:

```sql theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
EXPLAIN ANALYZE
SELECT count(*)
FROM events
WHERE updated_at >= timestamp '2026-01-05 03:15:00'
  AND updated_at < timestamp '2026-01-05 03:45:00';
```

The plan contains a `CoarseZoneMapPruneExec` line. `candidates=1/100` means
that 1 of 100 fragments is read and the other 99 are pruned:

```text theme={"theme":{"light":"vitesse-light","dark":"catppuccin-mocha"}}
CoarseZoneMapPruneExec: indexes=[events_updated_at_stats], columns=[updated_at], candidates=1/100, metrics=[candidate_fragments=1, input_fragments=100, pruned_fragments=99, ...]
```

A fragment that has no statistics yet, such as newly written data, is read
instead of pruned, so query results stay correct.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.