Repository navigation
Add a footer-only approximate distinct count aggregate - #11214
Draft
joseph-isaacs wants to merge 3 commits into
Draft
joseph-isaacs wants to merge 3 commits into
joseph-isaacs wants to merge 3 commits into
Conversation
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.
Summary
Adds
vortex.approx_distinct_count, a footer-only file statistic in thepreview2026.08.0edition. DataFusion and DuckDB both receive it as a column distinct count for planning.The partial has two modes:
An exact set becomes inexact once it holds more than 64Ki values, which caps memory per column. The serialized partial is only the count: the set is dropped on write, so a reader always gets an inexact count.
Changes
vortex-array: adds theApproxDistinctCountaggregate and registers it.u128. Variable-length values go in an arena-backed byte set, so inserting a value allocates nothing per value.vortex-layout:vortex-edition: adds it topreview2026.08.0. The edition record is regenerated and the editions doc updated.vortex-datafusion: theVortexFormatand v2 sources fall back to it as an inexactdistinct_count.vortex-duckdb: passes it asdistinct_count. For numeric columns it takes the smaller of this value and the min/max span estimate. Strings now get distinct counts too.vortex-bench: enables the preview edition and writes nested file statistics, so benchmark files carry the stat.The stat is only written with
include_nested_statistics(), because the legacy statistics layout has no slot for it.Inputs that arrive as chunked arrays come out inexact. The generic chunked aggregate kernel passes partials through their scalar form, which keeps only the count.
Tests:
vortex-fileround trip that covers the edition gating.Local measurements (SF=1, 4 cores)
The arm without the stat was produced by a temporary local toggle that is not part of this PR.
Ingest (parquet → vortex including compression, median of 3 runs): TPC-H takes 5.86 s → 6.69 s (+14%), and TPC-DS 9.45 s → 10.73 s (+13%).
Queries (vortex format, 5 iterations × 2 alternating rounds; ratios are with-stat over without, below 1 is faster):
Between rounds of the same arm, the geomean varies by up to ±5%. Plans change in both engines. TPC-DS q19 on DuckDB is about 2.7× slower in every run: DuckDB's row estimate drops sharply and it picks a worse join order, even though the stored counts are mostly exact.
Generated by Claude Code