loglog_counter
loglog_counter:为 PostgreSQL 提供 Aggregation 函数 and 数据类型 for distinct estimation based on LogLog。
distinct_estimators · loglog_counter:为 PostgreSQL 提供 Aggregation 函数 and 数据类型 for distinct estimation based on LogLog。
概览
| ID | 扩展 | 软件包 | 版本 | 类别 | 许可证 | 编程语言 |
|---|---|---|---|---|---|---|
| 100037 | loglog_counter | distinct_estimators | 1.2.4 | FUNC | BSD-2-Clause | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
用法
来源:
loglog_counter 将 LogLog 基数估算器实现为 loglog_estimator 类型、状态函数和聚合。它适用于固定内存比精确性更重要的近似去重计数。
核心流程
单参数重载 loglog_distinct(anyelement) 使用 2.5% 的默认误差率。显式重载允许查询选择不同的误差目标。
API
loglog_init(real)创建loglog_estimator,loglog_size(real)返回对应大小。loglog_add_item(loglog_estimator, anyelement)更新状态;loglog_get_estimate(loglog_estimator)读取结果。loglog_reset(loglog_estimator)清空状态,length(loglog_estimator)返回其存储大小。loglog_distinct(anyelement, real)执行可配置聚合;loglog_distinct(anyelement)使用默认值。
运维说明
1.2.4 版控制文件可重定位,未声明前置扩展或预加载要求。上游仓库已经归档并只读。估算器状态可能占用数 KB;频繁更新持久化状态会产生 MVCC 行版本并造成膨胀。应采用可接受的最低精度、批量更新,并在依赖估算值前测量实际误差。