probabilistic_counter
distinct_estimators · A C data type and aggregates for approximate distinct counting using the Flajolet-Martin probabilistic counting algorithm.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100039 | probabilistic_counter | distinct_estimators | 1.3.3 | FUNC | BSD-2-Clause | C |
PostgreSQL · 10, 11, 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
probabilistic_counter implements the Flajolet-Martin probabilistic counter as a probabilistic_estimator state type and aggregate. It trades exactness for a compact, configurable distinct-count estimate.
Core Workflow
The explicit arguments are the state byte count and number of salts. The one-argument probabilistic_distinct(anyelement) overload uses 4 bytes and 32 salts.
API
probabilistic_init(int, int)creates aprobabilistic_estimator;probabilistic_size(int, int)reports its size.probabilistic_add_item(probabilistic_estimator, anyelement)updates a state, andprobabilistic_get_estimate(probabilistic_estimator)returns the estimate.probabilistic_reset(probabilistic_estimator)clears a state, whilelength(probabilistic_estimator)reports its storage size.probabilistic_distinct(anyelement, int, int)is the configurable aggregate;probabilistic_distinct(anyelement)uses the defaults.
Operational Notes
The version 1.3.3 control file is relocatable and declares no prerequisite extension or preload requirement. The upstream repository is archived and read-only. Larger states can improve behavior at the cost of memory; stored states can also contribute to MVCC bloat when updated frequently. Test the estimator on representative distributions and retain exact counting for correctness-sensitive work.