count_distinct
count_distinct : An alternative to COUNT(DISTINCT …) aggregate, usable with HashAggregate
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4630 | count_distinct | count_distinct | 3.0.2 |
FUNC | BSD-2-Clause | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
| Relationships | |
|---|---|
| See Also | ddsketch tdigest topn omnisketch datasketches hll intagg intarray |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 3.0.2 |
18 17 16 15 14 | count_distinct |
- |
| RPM | PIGSTY | 3.0.2 |
18 17 16 15 14 | count_distinct_$v |
- |
| DEB | PIGSTY | 3.0.2 |
18 17 16 15 14 | postgresql-$v-count-distinct |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 |
| el8.aarch64 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 |
| el9.x86_64 | PGDG 3.0.2 | PGDG 3.0.2 | PGDG 3.0.2 | PGDG 3.0.2 | PGDG 3.0.2 |
| el9.aarch64 | PGDG 3.0.2 | PGDG 3.0.2 | PGDG 3.0.2 | PGDG 3.0.2 | PGDG 3.0.2 |
| el10.x86_64 | PGDG 3.0.2 | PGDG 3.0.2 | PGDG 3.0.2 | PGDG 3.0.2 | PGDG 3.0.2 |
| el10.aarch64 | PGDG 3.0.2 | PGDG 3.0.2 | PGDG 3.0.2 | PGDG 3.0.2 | PGDG 3.0.2 |
| d12.x86_64 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 |
| d12.aarch64 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 |
| d13.x86_64 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 |
| d13.aarch64 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 |
| u22.x86_64 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 |
| u22.aarch64 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 |
| u24.x86_64 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 |
| u24.aarch64 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 |
| u26.x86_64 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 |
| u26.aarch64 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 | PIGSTY 3.0.2 |
Source
github.com/tvondra/count_distinct
count_distinct-3.0.2.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
Provides an alternative to COUNT(DISTINCT ...) that avoids sorting and supports parallel aggregation.
Functions
| Function | Description |
|---|---|
count_distinct(value anyelement) |
Count distinct values (alternative to COUNT(DISTINCT ...)) |
array_agg_distinct(value anyelement) |
Aggregate distinct values into an array |
count_distinct_elements(value anyarray) |
Count distinct elements within input arrays |
array_agg_distinct_elements(value anyarray) |
Aggregate distinct elements from input arrays |
Examples
Types, Memory and Version
Version 3.0.2 accepts fixed-length values passed by value, such as integers, and arrays of those values; it is not a general replacement for distinct text aggregation. Hashing a larger value first makes collisions possible and changes the result into an estimate. These aggregates keep their state in RAM and cannot reliably enforce work_mem; high cardinality or many concurrent groups can exhaust memory. Compare correctness, plans and memory use with the built-in aggregate on the actual workload rather than assuming a speedup. The control file is relocatable and has no preload requirement; C-extension installation normally needs a superuser.