superloglog_counter
distinct_estimators · C data type, functions, and aggregates for approximate distinct counting with the SuperLogLog algorithm.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100040 | superloglog_counter | distinct_estimators | 1.2.3 | FUNC | BSD-3-Clause | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
superloglog_counter implements SuperLogLog, a LogLog variant with truncation and restriction rules, as a superloglog_estimator type and aggregate. It is for approximate, memory-bounded distinct counting.
Core Workflow
The one-argument superloglog_distinct(anyelement) overload uses a 2.5% default error rate. Pass an explicit rate to tune memory and accuracy.
API
superloglog_init(real)creates asuperloglog_estimator, andsuperloglog_size(real)reports its size.superloglog_add_item(superloglog_estimator, anyelement)updates a state;superloglog_get_estimate(superloglog_estimator)reads the estimate.superloglog_reset(superloglog_estimator)clears a state, whilelength(superloglog_estimator)reports its storage size.superloglog_distinct(anyelement, real)is configurable;superloglog_distinct(anyelement)uses the default error rate.
Operational Notes
The version 1.2.3 control file is relocatable and declares no prerequisite extension or preload requirement. The upstream repository is archived and read-only. Estimator states may occupy several kilobytes, and repeated table updates can cause MVCC bloat. Choose the lowest acceptable precision, batch state updates, and verify estimates with real data before operational use.