Repository navigation
Conversation
|
@QinXi-ai Can you isolate the benchmark creation in its own commit and rebase it as the first commit so that we can run benchmark like #27435 (comment) |
c624a1f to
024788c
Compare
|
Thanks @kosiew. I split the PR into two commits. You can run the grouped COUNT(DISTINCT) suite at a9807de for the baseline, then at 024788c for the inline-first accumulator. The final tree matches the previous PR head. One observation from a separate local experiment: Q10 and Q11 have dense integer group keys and at most two distinct values per group. A prototype that exploits both properties took Q10 from 381 to 4.9 ms and Q11 from 407 to 4.9 ms on a Xeon, relative to the benchmark-only commit. That was with one SQL partition and eight workers inside the prototype. With eight SQL partitions, both queries were slightly slower than baseline. I’ve kept the prototype on a separate branch. |
|
run benchmark grouped_count_distinct baseline:
ref: a9807de48a
env:
DATAFUSION_OPTIMIZER_SINGLE_DISTINCT_PREFER_NATIVE: "true"
DATAFUSION_EXECUTION_TARGET_PARTITIONS: "1"
MEM_POOL_TYPE: greedy
MEMORY_LIMIT: 1G |
|
Benchmark for this request failed before finishing (Kubernetes reason: Benchmarks requested: Runner log (last 40 lines)Kubernetes messageFile an issue against this benchmark runner |
024788c to
3afc0b8
Compare
|
run benchmark grouped_count_distinct baseline:
ref: 312ca330b6d76ef93b2cbfec3fd1b6f48cea174f
env:
DATAFUSION_OPTIMIZER_SINGLE_DISTINCT_PREFER_NATIVE: "true"
DATAFUSION_EXECUTION_TARGET_PARTITIONS: "1"
MEM_POOL_TYPE: greedy
MEMORY_LIMIT: 1G |
|
Hi @QinXi-ai, thanks for the request (#27299 (comment)). Only whitelisted users can trigger benchmarks. Allowed users: 2010YOUY01, Dandandan, Fokko, Jefffrey, Omega359, Rachelint, Rich-T-kid, adriangb, alamb, andygrove, asubiotto, avantgardnerio, brunal, buraksenn, cetra3, codephage2020, coderfender, comphead, erenavsarogullari, etseidl, friendlymatthew, gabotechs, geoffreyclaude, grtlr, gruuya, haohuaijin, jayzhan211, jonathanc-n, kevinjqliu, klion26, kosiew, kumarUjjawal, kunalsinghdadhwal, liamzwbao, mbutrovich, mkleen, mzabaluev, neilconway, rluvaton, sdf-jkl, timsaucer, xudong963, zhuqi-lucas. File an issue against this benchmark runner |
|
@kosiew I rebased both commits onto Could you rerun this benchmark command with the updated baseline? The runner requires an allowlisted account. |
|
run benchmark grouped_count_distinct baseline:
ref: 312ca330b6d76ef93b2cbfec3fd1b6f48cea174f
env:
DATAFUSION_OPTIMIZER_SINGLE_DISTINCT_PREFER_NATIVE: "true"
DATAFUSION_EXECUTION_TARGET_PARTITIONS: "1"
MEM_POOL_TYPE: greedy
MEMORY_LIMIT: 1G |
|
🤖 Benchmark running (GKE) | trigger CPU Details (lscpu)Comparing perf/25936-inline-first-distinct-20261110 (3afc0b8) to 312ca33 diff Run configurationrun benchmark grouped_count_distinct
env:
DATAFUSION_EXECUTION_TARGET_PARTITIONS: "1"
DATAFUSION_OPTIMIZER_SINGLE_DISTINCT_PREFER_NATIVE: "true"
MEMORY_LIMIT: "1G"
MEM_POOL_TYPE: "greedy"
baseline:
ref: "312ca330b6d76ef93b2cbfec3fd1b6f48cea174f"Trigger commentResults will be posted here when complete File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Instance: Comparing perf/25936-inline-first-distinct-20261110 (3afc0b8) to 312ca33 diff Run configurationrun benchmark grouped_count_distinct
env:
DATAFUSION_EXECUTION_TARGET_PARTITIONS: "1"
DATAFUSION_OPTIMIZER_SINGLE_DISTINCT_PREFER_NATIVE: "true"
MEMORY_LIMIT: "1G"
MEM_POOL_TYPE: "greedy"
baseline:
ref: "312ca330b6d76ef93b2cbfec3fd1b6f48cea174f"Trigger commentCPU Details (lscpu)Details
Memory Pool PeaksPeak Base:
Pool accounting vs. process RSS Max pool peak is the largest reservation any single query in the run reached; peak RSS covers the whole invocation, including data loading and allocator retention, and the two high-water marks need not coincide in time. The gap is therefore an upper bound on what the pool did not account for, not a measurement of it.
Resource Usagegrouped_count_distinct — base (merge-base)
grouped_count_distinct — branch
File an issue against this benchmark runner |
There was a problem hiding this comment.
Thanks for the optimization. The inline fast path preserves distinct-count semantics and partial-state compatibility while substantially improving singleton performance and memory usage.
Benchmark results look great.
Approving with suggestions. The increased memory usage for very sparse inputs is a bounded trade-off worth documenting or addressing separately.
| } | ||
| }); | ||
| if let Some(first_values) = &mut self.first_values { | ||
| first_values.resize(total_num_groups, T::Native::default()); |
There was a problem hiding this comment.
Could we consider density-based promotion in update_batch and merge_batch? With twelve sparse DISTINCT expressions, peak reservations increased from 5.24 MB to 8.38 MB, introducing spills at 6M. Any guard should preserve Q10/Q11 gains; otherwise, documenting the trade-off is sufficient.
| fn evaluate(&mut self, emit_to: EmitTo) -> datafusion_common::Result<ArrayRef> { | ||
| let counts = emit_to.take_needed(&mut self.counts); | ||
| if let Some(first_values) = &mut self.first_values { | ||
| let _ = emit_to.take_needed(first_values); |
There was a problem hiding this comment.
Optional: consider dropping drain(..n) directly for small discarded inline prefixes to avoid allocation. Retain split-and-drop for large prefixes so the remaining buffer can shrink.
| first value, which lets repeated singleton values skip the distinct hash set. | ||
| The rewrite's outer aggregate only sees the deduplicated pairs. | ||
|
|
||
| When the average number of additional distinct values per group exceeds eight, |
There was a problem hiding this comment.
Could we clarify that promotion is checked after each update or merge batch, includes NULL-only groups in the average, and remains active through partial emissions until EmitTo::All resets the accumulator?
Which issue does this PR close?
Part of #25936. This implements the accumulator step in the follow-up plan.
Rationale for this change
The native grouped integer
COUNT(DISTINCT)accumulator currently probes the shared distinct hash set for every non-null input row. For Q10, which has a million groups with four copies of one value per group, keeping that value inline avoids those probes.I built both versions from
c8265b68on a shared Linux host, using a Xeon Gold 6238T, Rust 1.99.1 andrelease-nonlto. The suite used four million rows, one target partition, greedy / 1 GiB, withsingle_distinct_prefer_nativeenabled. These are medians from three alternating rounds, six iterations per round with the first discarded, giving 15 retained samples per version. CPU affinity was 0-7, with builds stopped during timing.The inline buffer allocates a typed slot for every group, including groups with only NULL arguments. Q12 exposes that cost, with about 6.7 MiB more peak pool memory.
What changes are included in this PR?
Keep each group's first non-null value in a typed vector and put additional values in the shared hash set. After a batch where the average number of additional distinct values per group exceeds eight, move the inline values into the set and release the vector. Subsequent batches use the hash-only loop. This avoids the per-row cache check for the large sets in Q07 and Q09. CPU-0 repeats measured -2.9% and -3.5% elapsed changes for those two queries.
Both modes use the existing List state format. State emission, partial emission, merge and memory accounting handle the inline values and the switch to the hash-only mode.
Add Q11 and Q12 to the SQL benchmark suite to cover small distinct sets and NULL-heavy groups.
What is the testing strategy for this PR?
Added unit tests for partial emission, overlapping merges, group-index shifts, promotion, buffer accounting and reuse. SQL tests exercise small batches and overlapping partial states through the normal query path.
Validated on Linux with Rust 1.99.1.
uv run ./dev/rust_lint.shsuite passed.Are there any user-facing changes?
Native grouped integer
COUNT(DISTINCT)has the runtime and memory changes shown above.Prepared with Codex assistance. Opening as a draft for author review.