> ## Documentation Index
> Fetch the complete documentation index at: https://paradedb-ankitml-legacy-docs-remove.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Cardinality

> Compute the number of distinct values in a field

The cardinality aggregation estimates the number of distinct values in a field.

```sql theme={null}
SELECT pdb.agg('{"cardinality": {"field": "rating"}}') FROM mock_items
WHERE id @@@ pdb.all();
```

```ini Expected Response theme={null}
      agg
----------------
 {"value": 5.0}
(1 row)
```

Unlike SQL's `DISTINCT` clause, which returns an exact value but is very computationally expensive, the cardinality aggregation uses the HyperLogLog++ algorithm to
closely approximate the number of distinct values.

See the [Tantivy documentation](https://docs.rs/tantivy/latest/tantivy/aggregation/metric/struct.CardinalityAggregationReq.html) for all available options.
