Repository navigation
Conversation
…olkit sketch variants Engine postgresql now runs periodic suites on a PostgreSQL server with TimescaleDB and the TimescaleDB Toolkit. Each arm runs each query's PromQL text (a subset: [agg by (...)] (f(metric[d]))) as SQL it writes itself; the variant name picks exact query-time SQL over the hypertable, one continuous aggregate per query (real-time aggregation off, refreshed at each ingest step), or uddsketch/tdigest quantiles at query time or per bucket. scripts/timescaledb-variants.sh adds the six variants to a run directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rom -infinity The first refresh with a NULL start committed once per batch of empty buckets since the epoch (seconds of WAL syncs per arm). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
approxbench benchmark-external run --engine postgresqlnow runs periodic suites (such as showcase-1m and showcase-1h) on PostgreSQL with TimescaleDB and the TimescaleDB Toolkit. Until now,postgresqlran only one-shot queries.Each arm runs each workload query's PromQL text. The adapter turns that text into SQL itself, so it needs no plan file (variants with
"plans": false). The variant name picks how the queries run:quantile_over_timetimescaledb.hypertablepercentile_contover the raw rowstimescaledb.continuous-aggregatearray_aggper bucket, thenpercentile_contover the window's valuessum/count/min/maxper bucket;counter_aggper bucket forrate/increasetimescaledb.uddsketchapprox_percentile(φ, uddsketch(200, 0.001, value))at query timetimescaledb.tdigestapprox_percentile(φ, tdigest(100, value))at query timetimescaledb.continuous-aggregate.uddsketchrollupover the windowtimescaledb.continuous-aggregate.tdigestrollupover the windowscripts/timescaledb-variants.sh <run-dir>adds the six variants withrun_by_default: false, so runs of the other engines over the same directory skip them.Semantics and where TimescaleDB differs
(T − d, T], the same as PromQL. A continuous aggregate usestime_bucket(b, ts, "offset" => 1 µs), so each bucket is(k·b, (k+1)·b]at the microsecond resolution oftimestamptz. The bucket width isb = gcd(range, evaluation interval).percentile_contis PromQL's linear interpolation at rank φ·(n−1), so the result is exact. The Toolkit'sapprox_percentiledoes not interpolate: it returns a value near one order statistic. Part of a sketch variant's error is therefore this difference in definition, not sketch error. For example, with 60 samples, p99 comes out near the 60th value instead of 59.41.extrapolatedRate(v3.15.1), computed the same way as ClickHouse's query-time translator: reset-corrected increase, the 1.1 × average-gap threshold, the zero-point clamp, and at least 2 samples. The continuous-aggregate variants take n, first/last time, first value and the reset-corrected delta fromrollup(counter_agg), so they match exactly too.timescaledb.materialized_only = true) and no refresh policy runs. At the end of every ingest step, the adapter callsrefresh_continuous_aggregateover that step's buckets. Every evaluation therefore reads complete, materialized buckets, and the refresh counts as ingest CPU. The raw hypertable stays, because TimescaleDB refreshes from it, soraw_retained_bytes> 0 in every variant.[sum|avg|min|max|count [by (...)]] (f(metric[d]))with f =*_over_time(sum/count/avg/min/max),rate,increase, orquantile_over_time. Anything else (label matchers,offset,without, nested expressions) is refused at install.Storage: each install gets its own schema,
bench_<pid>_<n>, with one hypertable per metric (ts timestamptz,value float8,series= the label map as JSON, and one text column perbylabel). Each chunk is written with one binaryCOPYper metric over a persistent connection.--postgresql-settingvalues are applied withSETon that connection; for example,max_parallel_workers_per_gather=0gives a single-worker row, matching ClickHouse'smax_threads=1. CPU and memory come from the container cgroup. The new dependency is thepostgrescrate (sync client).Interfaces
// system-bench/src/registry.rs System { name: "postgresql", - periodic_queries: None, + periodic_queries: Some(PeriodicQueries { + options: TimescaleDbOptions::augment_args, + build: timescaledb_server::periodic_queries, + }), +// system-bench/src/engines_external/timescaledb_server.rs (new) +pub struct TimescaleDbEngine; // EngineUnderTest +pub struct TimescaleDbServer { pub connection: String, pub settings: Vec<(String, String)>, pub cgroup: Option<CgroupSource> } +pub const VARIANTS: [(&str, Mode); 6]; +pub fn parse_query(text: &str) -> Result<RangeQuery, String>; +pub fn plan_queries(workload: &WorkloadSpec, mode: Mode, schema: &str) -> Result<(Vec<QueryPlan>, LabelColumns), EngineError>;Tests
system-bench/tests/timescaledb_server.rs(no server): all 24 query texts in showcase-1m and showcase-1h parse in all six modes; texts outside the subset and a range that differs from the window are refused; variant → mode; the cagg bucket is the gcd and stays left-open;postgresqlis listed for periodic queries.system-bench/tests/timescaledb_conformance.rs(#[ignore],AQPBM_POSTGRESQL_CONNECTION), on a real server (the pinned image, 8 cores). Each case runs on all six variants, and all 5 pass:--warmup 0 --runs 1, all 48 cells ran (21.5 min on a throttled host). Report with truthpostgresql/timescaledb.hypertable:timescaledb.continuous-aggregatemax relative error ≤ 1.2e-15 on every workload. Sketch variants on quantile workloads: max 9.1 % (tdigest) and 10.9 % (uddsketch), median 0.6–0.7 %. Non-quantile queries in the sketch variants stay exact.Run locally:
cargo nextest run -p system-bench timescaledb; against a server:AQPBM_POSTGRESQL_CONNECTION="host=… port=… dbname=bench" cargo test -p system-bench --test timescaledb_conformance -- --ignored --test-threads 1.🤖 Generated with Claude Code
https://claude.ai/code/session_01K1M6boFpwkpMtRc1FnZuYi