> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 使用 HyperLogLog 算法计算不同参数值的近似个数。

# uniqHLL12

<div id="uniqHLL12">
  ## uniqHLL12
</div>

引入版本：v1.1.0

使用 [HyperLogLog](https://en.wikipedia.org/wiki/HyperLogLog) 算法，计算不同参数值的近似数量。

<Warning>
  不建议使用此函数。在大多数情况下，请使用 [uniq](/zh/reference/functions/aggregate-functions/uniq) 或 [uniqCombined](/zh/reference/functions/aggregate-functions/uniqCombined) 函数。
</Warning>

<Accordion title="实现细节">
  此函数会对聚合中的所有参数计算哈希值，并在计算中使用这些哈希值。
  它使用 HyperLogLog 算法来近似计算不同参数值的数量。

  使用 2^12 个 5 位单元。
  状态大小略高于 2.5 KB。
  对于较小的数据集 (\<10K 个元素) ，结果不太准确 (误差最高约为 10%) 。
  不过，对于高基数数据集 (10K-100M) ，结果相当准确，最大误差约为 1.6%。
  从 100M 开始，估算误差会增大；对于基数极高的数据集 (1B+ 个元素) ，该函数会返回非常不准确的结果。

  可提供确定性的结果 (不依赖查询处理顺序) 。
</Accordion>

**语法**

```sql theme={null}
uniqHLL12(x[, ...])
```

**参数**

* `x` — 该函数接受可变数量的参数。[`Tuple(T)`](/zh/reference/data-types/tuple) 或 [`Array(T)`](/zh/reference/data-types/array) 或 [`Date`](/zh/reference/data-types/date) 或 [`DateTime`](/zh/reference/data-types/datetime) 或 [`String`](/zh/reference/data-types/string) 或 [`(U)Int*`](/zh/reference/data-types/int-uint) 或 [`Float*`](/zh/reference/data-types/float) 或 [`Decimal`](/zh/reference/data-types/decimal)

**返回值**

返回一个 `UInt64` 类型的数值，表示不同参数值的近似数量。[`UInt64`](/zh/reference/data-types/int-uint)

**示例**

**基本用法**

```sql title=Query theme={null}
CREATE TABLE example_hll
(
    id UInt32,
    category String
)
ENGINE = Memory;

INSERT INTO example_hll VALUES
(1, 'A'), (2, 'B'), (3, 'A'), (4, 'C'), (5, 'B'), (6, 'A');

SELECT uniqHLL12(category) AS hll_unique_categories
FROM example_hll;
```

```response title=Response theme={null}
┌─hll_unique_categories─┐
│                     3 │
└───────────────────────┘
```

**另请参见**

* [uniq](/zh/reference/functions/aggregate-functions/uniq)
* [uniqCombined](/zh/reference/functions/aggregate-functions/uniqCombined)
* [uniqExact](/zh/reference/functions/aggregate-functions/uniqExact)
* [uniqTheta](/zh/reference/functions/aggregate-functions/uniqthetasketch)
