Skip to content

hll

hll : type for storing hyperloglog data

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
2700
hll
hll
2.21
FEAT
Apache-2.0
C++
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--s-d--
No
Yes
No
Yes
no
no
Relationships
See Also
topn
count_distinct
omnisketch
bloom
roaringbitmap
ddsketch
tdigest
citus

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXT
PGDG
2.21
18
17
16
15
14
hll-
RPM
PGDG
2.21
18
17
16
15
14
hll_$v-
DEB
PGDG
2.20
18
17
16
15
14
postgresql-$v-hll-
Linux / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
el8.aarch64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
el9.x86_64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
el9.aarch64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
el10.x86_64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
el10.aarch64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
d12.x86_64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
d12.aarch64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
d13.x86_64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
d13.aarch64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
u22.x86_64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
u22.aarch64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
u24.x86_64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
u24.aarch64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
u26.x86_64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
u26.aarch64
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PGDG 2.21
PackageVersionOSORGSIZEFile URL
hll_182.21el8.x86_64pgdg43.4 KiBhll_18-2.21-1PGDG.rhel8.10.x86_64.rpm
hll_182.20el8.x86_64pgdg43.0 KiBhll_18-2.20-1PGDG.rhel8.10.x86_64.rpm
hll_182.19el8.x86_64pgdg42.4 KiBhll_18-2.19-1PGDG.rhel8.x86_64.rpm
hll_182.21el8.aarch64pgdg43.2 KiBhll_18-2.21-1PGDG.rhel8.10.aarch64.rpm
hll_182.20el8.aarch64pgdg42.7 KiBhll_18-2.20-1PGDG.rhel8.10.aarch64.rpm
hll_182.19el8.aarch64pgdg42.1 KiBhll_18-2.19-1PGDG.rhel8.aarch64.rpm
hll_182.21el9.x86_64pgdg43.1 KiBhll_18-2.21-1PGDG.rhel9.8.x86_64.rpm
hll_182.21el9.x86_64pgdg43.1 KiBhll_18-2.21-1PGDG.rhel9.7.x86_64.rpm
hll_182.21el9.x86_64pgdg43.2 KiBhll_18-2.21-1PGDG.rhel9.6.x86_64.rpm
hll_182.20el9.x86_64pgdg42.6 KiBhll_18-2.20-1PGDG.rhel9.8.x86_64.rpm
hll_182.20el9.x86_64pgdg42.6 KiBhll_18-2.20-1PGDG.rhel9.7.x86_64.rpm
hll_182.20el9.x86_64pgdg42.7 KiBhll_18-2.20-1PGDG.rhel9.6.x86_64.rpm
hll_182.19el9.x86_64pgdg42.0 KiBhll_18-2.19-1PGDG.rhel9.8.x86_64.rpm
hll_182.19el9.x86_64pgdg42.1 KiBhll_18-2.19-1PGDG.rhel9.x86_64.rpm
hll_182.21el9.aarch64pgdg43.0 KiBhll_18-2.21-1PGDG.rhel9.8.aarch64.rpm
hll_182.21el9.aarch64pgdg43.0 KiBhll_18-2.21-1PGDG.rhel9.7.aarch64.rpm
hll_182.21el9.aarch64pgdg43.1 KiBhll_18-2.21-1PGDG.rhel9.6.aarch64.rpm
hll_182.20el9.aarch64pgdg42.5 KiBhll_18-2.20-1PGDG.rhel9.8.aarch64.rpm
hll_182.20el9.aarch64pgdg42.5 KiBhll_18-2.20-1PGDG.rhel9.7.aarch64.rpm
hll_182.20el9.aarch64pgdg42.6 KiBhll_18-2.20-1PGDG.rhel9.6.aarch64.rpm
hll_182.19el9.aarch64pgdg41.9 KiBhll_18-2.19-1PGDG.rhel9.8.aarch64.rpm
hll_182.19el9.aarch64pgdg41.9 KiBhll_18-2.19-1PGDG.rhel9.aarch64.rpm
hll_182.21el10.x86_64pgdg43.2 KiBhll_18-2.21-1PGDG.rhel10.2.x86_64.rpm
hll_182.21el10.x86_64pgdg43.2 KiBhll_18-2.21-1PGDG.rhel10.1.x86_64.rpm
hll_182.21el10.x86_64pgdg43.5 KiBhll_18-2.21-1PGDG.rhel10.0.x86_64.rpm
hll_182.20el10.x86_64pgdg42.7 KiBhll_18-2.20-1PGDG.rhel10.2.x86_64.rpm
hll_182.20el10.x86_64pgdg42.7 KiBhll_18-2.20-1PGDG.rhel10.1.x86_64.rpm
hll_182.20el10.x86_64pgdg43.1 KiBhll_18-2.20-1PGDG.rhel10.0.x86_64.rpm
hll_182.19el10.x86_64pgdg42.1 KiBhll_18-2.19-1PGDG.rhel10.2.x86_64.rpm
hll_182.19el10.x86_64pgdg42.5 KiBhll_18-2.19-1PGDG.rhel10.x86_64.rpm
hll_182.21el10.aarch64pgdg42.5 KiBhll_18-2.21-1PGDG.rhel10.2.aarch64.rpm
hll_182.21el10.aarch64pgdg42.5 KiBhll_18-2.21-1PGDG.rhel10.1.aarch64.rpm
hll_182.21el10.aarch64pgdg42.5 KiBhll_18-2.21-1PGDG.rhel10.0.aarch64.rpm
hll_182.20el10.aarch64pgdg42.0 KiBhll_18-2.20-1PGDG.rhel10.2.aarch64.rpm
hll_182.20el10.aarch64pgdg42.0 KiBhll_18-2.20-1PGDG.rhel10.1.aarch64.rpm
hll_182.20el10.aarch64pgdg42.0 KiBhll_18-2.20-1PGDG.rhel10.0.aarch64.rpm
hll_182.19el10.aarch64pgdg41.6 KiBhll_18-2.19-1PGDG.rhel10.2.aarch64.rpm
hll_182.19el10.aarch64pgdg41.9 KiBhll_18-2.19-1PGDG.rhel10.aarch64.rpm
postgresql-18-hll2.21d12.x86_64pgdg78.4 KiBpostgresql-18-hll_2.21-1.pgdg12+1_amd64.deb
postgresql-18-hll2.20d12.x86_64pgdg77.6 KiBpostgresql-18-hll_2.20-1.pgdg12+1_amd64.deb
postgresql-18-hll2.19d12.x86_64pgdg76.6 KiBpostgresql-18-hll_2.19-2.pgdg12+2_amd64.deb
postgresql-18-hll2.21d12.aarch64pgdg77.3 KiBpostgresql-18-hll_2.21-1.pgdg12+1_arm64.deb
postgresql-18-hll2.20d12.aarch64pgdg76.4 KiBpostgresql-18-hll_2.20-1.pgdg12+1_arm64.deb
postgresql-18-hll2.19d12.aarch64pgdg75.6 KiBpostgresql-18-hll_2.19-2.pgdg12+2_arm64.deb
postgresql-18-hll2.21d13.x86_64pgdg78.3 KiBpostgresql-18-hll_2.21-1.pgdg13+1_amd64.deb
postgresql-18-hll2.20d13.x86_64pgdg77.4 KiBpostgresql-18-hll_2.20-1.pgdg13+1_amd64.deb
postgresql-18-hll2.19d13.x86_64pgdg76.5 KiBpostgresql-18-hll_2.19-2.pgdg13+2_amd64.deb
postgresql-18-hll2.21d13.aarch64pgdg77.3 KiBpostgresql-18-hll_2.21-1.pgdg13+1_arm64.deb
postgresql-18-hll2.20d13.aarch64pgdg76.5 KiBpostgresql-18-hll_2.20-1.pgdg13+1_arm64.deb
postgresql-18-hll2.19d13.aarch64pgdg75.8 KiBpostgresql-18-hll_2.19-2.pgdg13+2_arm64.deb
postgresql-18-hll2.21u22.x86_64pgdg78.2 KiBpostgresql-18-hll_2.21-1.pgdg22.04+1_amd64.deb
postgresql-18-hll2.20u22.x86_64pgdg77.2 KiBpostgresql-18-hll_2.20-1.pgdg22.04+1_amd64.deb
postgresql-18-hll2.19u22.x86_64pgdg76.4 KiBpostgresql-18-hll_2.19-2.pgdg22.04+2_amd64.deb
postgresql-18-hll2.21u22.aarch64pgdg77.0 KiBpostgresql-18-hll_2.21-1.pgdg22.04+1_arm64.deb
postgresql-18-hll2.20u22.aarch64pgdg76.0 KiBpostgresql-18-hll_2.20-1.pgdg22.04+1_arm64.deb
postgresql-18-hll2.19u22.aarch64pgdg75.3 KiBpostgresql-18-hll_2.19-2.pgdg22.04+2_arm64.deb
postgresql-18-hll2.21u24.x86_64pgdg76.8 KiBpostgresql-18-hll_2.21-1.pgdg24.04+1_amd64.deb
postgresql-18-hll2.20u24.x86_64pgdg76.0 KiBpostgresql-18-hll_2.20-1.pgdg24.04+1_amd64.deb
postgresql-18-hll2.19u24.x86_64pgdg75.0 KiBpostgresql-18-hll_2.19-2.pgdg24.04+2_amd64.deb
postgresql-18-hll2.21u24.aarch64pgdg75.6 KiBpostgresql-18-hll_2.21-1.pgdg24.04+1_arm64.deb
postgresql-18-hll2.20u24.aarch64pgdg74.8 KiBpostgresql-18-hll_2.20-1.pgdg24.04+1_arm64.deb
postgresql-18-hll2.19u24.aarch64pgdg74.0 KiBpostgresql-18-hll_2.19-2.pgdg24.04+2_arm64.deb
postgresql-18-hll2.21u26.x86_64pgdg76.2 KiBpostgresql-18-hll_2.21-1.pgdg26.04+1_amd64.deb
postgresql-18-hll2.20u26.x86_64pgdg75.3 KiBpostgresql-18-hll_2.20-1.pgdg26.04+1_amd64.deb
postgresql-18-hll2.19u26.x86_64pgdg75.1 KiBpostgresql-18-hll_2.19-2.pgdg26.04+1_amd64.deb
postgresql-18-hll2.21u26.aarch64pgdg75.1 KiBpostgresql-18-hll_2.21-1.pgdg26.04+1_arm64.deb
postgresql-18-hll2.20u26.aarch64pgdg74.3 KiBpostgresql-18-hll_2.20-1.pgdg26.04+1_arm64.deb
postgresql-18-hll2.19u26.aarch64pgdg74.2 KiBpostgresql-18-hll_2.19-2.pgdg26.04+1_arm64.deb

Source

Install

Make sure PGDG repo available:

pig repo add pgdg -u    # add pgdg repo and update cache

Install this extension with pig:

pig install hll;		# install via package name, for the active PG version

pig install hll -v 18;   # install for PG 18
pig install hll -v 17;   # install for PG 17
pig install hll -v 16;   # install for PG 16
pig install hll -v 15;   # install for PG 15
pig install hll -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION hll;

Usage

hll: type for storing hyperloglog data

The hll extension provides a HyperLogLog data type for probabilistic distinct-value counting. It enables efficient approximate COUNT(DISTINCT) operations with configurable accuracy, and supports set union operations that allow pre-aggregated data to be combined without loss of precision.

Data Types

  • hll – HyperLogLog accumulator with parameters: hll(log2m, regwidth, expthresh, sparseon)
  • hll_hashval – Hashed value type for insertion into HLL structures

Core Functions

FunctionDescription
hll_empty()Create an empty HLL
hll_add(hll, hll_hashval)Add a hashed value to an HLL
hll_cardinality(hll)Estimate distinct count
hll_union(hll, hll)Combine two HLLs
hll_add_agg(hll_hashval)Aggregate hashed values into a single HLL
hll_union_agg(hll)Merge multiple HLLs into one
hll_print(hll)Display HLL parameters and contents

Hash Functions

FunctionInput Type
hll_hash_boolean(boolean [, seed])boolean
hll_hash_smallint(smallint [, seed])smallint
hll_hash_integer(integer [, seed])integer
hll_hash_bigint(bigint [, seed])bigint
hll_hash_bytea(bytea [, seed])bytea
hll_hash_text(text [, seed])text
hll_hash_any(any [, seed])any (dynamic dispatch, slower)

Operators

OperatorFunctionExample
||hll_add / hll_unionusers || hll_hash_integer(123)
#hll_cardinality#users

Example: Daily Unique User Tracking

-- Store daily unique user counts
CREATE TABLE daily_uniques (
    date  date UNIQUE,
    users hll
);

-- Aggregate daily data
INSERT INTO daily_uniques(date, users)
    SELECT date, hll_add_agg(hll_hash_integer(user_id))
    FROM facts GROUP BY 1;

-- Weekly uniques (unions are lossless)
SELECT hll_cardinality(hll_union_agg(users))
FROM daily_uniques
WHERE date >= '2012-01-02' AND date <= '2012-01-08';

-- Monthly breakdown
SELECT EXTRACT(MONTH FROM date) AS month,
       #hll_union_agg(users) AS approx_uniques
FROM daily_uniques
WHERE date >= '2012-01-01' AND date < '2013-01-01'
GROUP BY 1;

-- 7-day sliding window
SELECT date, #hll_union_agg(users) OVER seven_days
FROM daily_uniques
WINDOW seven_days AS (ORDER BY date ASC ROWS 6 PRECEDING);

Configuration Parameters

  • log2m (4–31): Number of registers as log-base-2. Controls accuracy with relative error of +/-1.04/sqrt(2^log2m). Default: 11.
  • regwidth (1–8): Bits per register. Tuned alongside log2m for maximum cardinality estimation. Default: 5.
  • expthresh (-1 to 18): Controls EXPLICIT-to-SPARSE promotion. -1 for auto mode, 0 to skip EXPLICIT. Default: -1.
  • sparseon (0 or 1): Enables/disables SPARSE representation. Default: 1.

All inputs to a given HLL must use the same hash seed. HLLs intended for union operations must have been populated with identically-seeded hash values.

Last updated on