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

# vsql_hll extension for MySQL

> The vsql_hll community extension adds HyperLogLog sketches to MySQL, for fast estimates of how many different values a column holds.

`vsql_hll` estimates how many different values a column holds, such as how
many different users visited a site, using a small fixed-size summary called
a sketch. Reach for it when an exact `COUNT(DISTINCT ...)` is too slow, or when
you want to store daily counts and combine them into weekly ones without going
back to the raw rows.

| | |
| - | - |
| **Maintainer** | [Kavish](https://github.com/kash2104) |
| **Source and documentation** | [kash2104/vsql-hll](https://github.com/kash2104/vsql-hll) |
| **License** | GPL-2.0 |

> [!NOTE]
>
> A third party writes and maintains this extension. VillageSQL does not build,
> test, or ship it, and the description below follows the maintainer's own
> documentation. Read that documentation before you rely on it.

## Install

Build it from the repository against a VillageSQL build tree (`VillageSQL_BUILD_DIR`), copy the `.veb` file into the server's `veb_dir`, then install it:

```sql theme={null}
INSTALL EXTENSION vsql_hll;
```

## What it adds

An `hll` column type stores a sketch, so you can save one and combine it later.

| Function | Returns | What it does |
| - | - | - |
| `hll_hash_bigint(number)` | number | Hashes a whole number so it can be added to a sketch |
| `hll_hash_text(text)` | number | Hashes a text value |
| `hll_hash_boolean(value)` | number | Hashes a true or false value |
| `hll_hash_bytea_hex(hex_text)` | number | Hashes binary data written as hex text |
| `hll_empty()` | `hll` | Returns a new, empty sketch |
| `hll_add(sketch, hash)` | `hll` | Adds one hashed value to a sketch |
| `hll_union(sketch_a, sketch_b)` | `hll` | Combines two sketches, counting a value that is in both once |
| `hll_cardinality(sketch)` | number | Returns the estimated number of different values |
| `hll_agg(hash)` | `hll` | Aggregate: builds one sketch from the hashed values in a group of rows |
| `hll_union_agg(sketch)` | `hll` | Aggregate: combines the sketches in a group of rows |

Hash every value before you add it to a sketch, and always hash the same kind
of value with the same function.

## See also

* [Available extensions](https://villagesql.com/docs/en/extensions/catalog) — the full catalog
* [kash2104/vsql-hll](https://github.com/kash2104/vsql-hll) — source, examples, accuracy notes, and the known limitations


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