ddsketch
Provides ddsketch aggregate function
Repository
tvondra/ddsketch
https://github.com/tvondra/ddsketch
Source
ddsketch-1.0.1.tar.gz
ddsketch-1.0.1.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
ddsketch | 1.0.1 | FUNC | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4650 | ddsketch | No | Yes | No | Yes | No | Yes | - |
| Related | omnisketch quantile lower_quantile topn count_distinct hll first_last_agg |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0.1 | 1817161514 | ddsketch | - |
| RPM | PIGSTY | 1.0.1 | 1817161514 | ddsketch_$v | - |
| DEB | PIGSTY | 1.0.1 | 1817161514 | postgresql-$v-ddsketch | - |
Build
You can build the RPM / DEB packages for ddsketch using pig build:
pig build pkg ddsketch # build RPM / DEB packages
Install
You can install ddsketch directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install ddsketch; # Install for current active PG version
pig ext install -y ddsketch -v 18 # PG 18
pig ext install -y ddsketch -v 17 # PG 17
pig ext install -y ddsketch -v 16 # PG 16
pig ext install -y ddsketch -v 15 # PG 15
pig ext install -y ddsketch -v 14 # PG 14
dnf install -y ddsketch_18 # PG 18
dnf install -y ddsketch_17 # PG 17
dnf install -y ddsketch_16 # PG 16
dnf install -y ddsketch_15 # PG 15
dnf install -y ddsketch_14 # PG 14
apt install -y postgresql-18-ddsketch # PG 18
apt install -y postgresql-17-ddsketch # PG 17
apt install -y postgresql-16-ddsketch # PG 16
apt install -y postgresql-15-ddsketch # PG 15
apt install -y postgresql-14-ddsketch # PG 14
Create Extension:
CREATE EXTENSION ddsketch;
Usage
Implements DDSketch, a fully-mergeable quantile sketch with relative-error guarantees. Much faster than percentile_cont and supports parallelism.
CREATE EXTENSION ddsketch;
Direct Aggregation Functions
| Function | Description |
|---|---|
ddsketch_percentile(value, alpha, nbuckets, quantile) | Estimate a single percentile |
ddsketch_percentile(value, alpha, nbuckets, quantiles[]) | Estimate multiple percentiles |
ddsketch_percentile_of(value, alpha, nbuckets, value) | Estimate percentile rank of a value |
ddsketch_percentile_of(value, alpha, nbuckets, values[]) | Estimate percentile ranks of multiple values |
Pre-aggregation Functions
| Function | Description |
|---|---|
ddsketch(value, alpha, nbuckets) | Build a ddsketch from values |
ddsketch_percentile(sketch, quantile) | Estimate percentile from a pre-built sketch |
ddsketch_percentile(sketch, quantiles[]) | Estimate multiple percentiles from a pre-built sketch |
Utility Functions
| Function | Description |
|---|---|
ddsketch_count(sketch) | Return the number of items in the sketch |
ddsketch_sum(sketch, low, high) | Trimmed sum within a value range |
ddsketch_avg(sketch, low, high) | Trimmed average within a value range |
Parameters
alpha– controls accuracy and sketch size (lower = more accurate, larger)nbuckets– maximum number of buckets (each 8 bytes)
Examples
-- Instead of: SELECT percentile_cont(0.95) WITHIN GROUP (ORDER BY a) FROM t;
SELECT ddsketch_percentile(a, 0.05, 1024, 0.95) FROM t;
-- Multiple percentiles at once
SELECT ddsketch_percentile(a, 0.05, 1024, ARRAY[0.5, 0.95, 0.99]) FROM t;
-- Pre-aggregate for fast repeated queries
CREATE TABLE p AS SELECT a, b, ddsketch(c, 0.05, 1024) AS d FROM t GROUP BY a, b;
-- Query pre-aggregated data (~1.5ms vs ~7s for exact)
SELECT a, ddsketch_percentile(d, 0.95) FROM p GROUP BY a ORDER BY a;
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.