Skip to content

test(executor): exact Aggregate split by group key over worker threads (tests first) - #1571

Draft
zzylol wants to merge 1 commit into
eval/2026-12-plannerfrom
feat/parallel-exact-aggregate
Draft

zzylol wants to merge 1 commit into
eval/2026-12-plannerfrom
feat/parallel-exact-aggregate

Conversation

@zzylol

@zzylol zzylol commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem. The exact Aggregate runs on one thread. feat(executor): split grouped summary builds and merges by group key over worker threads #1563 split grouped summary builds and merges by group key over the worker pool, but a query-time Scan -> TimeRange -> Aggregate (an exact count distinct per group, an exact quantile per group) still reduces every row on the query thread. Example, measured at x4: SELECT target, count(DISTINCT user) … WHERE src IN $A … GROUP BY target over 1 h (72 M rows read) takes 10.5 s. 30% of all data-plane samples sit on that one query thread in GroupTable::group_ids, the (group, tuple) distinct set and ColumnParts. The raw read itself already runs on the pool.
  • Change (this PR: tests only). Six tests for splitting the exact Aggregate by group-key hash into P parts on the worker pool, reusing feat(executor): split grouped summary builds and merges by group key over worker threads #1563's split, wave, part-count and key-order combine. Each part keeps its own group table and measure states; the parts' disjoint groups are emitted in the one-thread key order.
  • Effect. E1, E2, E5 and E6 fail today ("not split": 0 partition tasks). E3 and E4 are guards and pass. The implementation waits for approval of the spec and test plan.

Review guide

  • Base: eval/2026-12-planner fa22fa2. One file: crates/executor/tests/parallel_execution.rs, new tests after the feat(executor): split grouped summary builds and merges by group key over worker threads #1563 tests. They reuse that file's rows, run, run_with and fingerprint helpers (every cell, float bits, row order).
  • The invariants under test, spec and test plan section 2.1:
    • I1 identical cells;
    • I2 one-thread key order;
    • I3 filters, NULLs, empty input;
    • I4 memory limit and worker CPU;
    • I5 global and small inputs stay on one thread.

Behavior: before → after (planned)

test input asserts today
E1 grouped_aggregates_split_by_group_key_equal_the_sequential_aggregate 24 k rows, every exact measure (count, int/float sum, avg, min/max float and text, count distinct of one and two columns, L2, entropy, quantile, percentile, stddev, variance, corr, group), grouped by (host), (host, fkey), (fkey, host), P = 2, 3, 5, 8 fingerprint == P=1 and tasks > 0 fails: not split
E2 split_aggregates_keep_filters_nulls_and_first_labels measure FILTERs, NULL values, a float key with ±0 / NaN payloads / NULL == P=1, tasks > 0 fails
E3 global_and_small_aggregates_stay_sequential no group column, empty input with emit_empty_global, 2 k rows == P=1, tasks == 0 passes (guard)
E4 a_split_aggregate_over_the_memory_limit_fails 256 KiB limit MemoryLimit at P = 1 and 4 passes (guard)
E5 split_aggregates_charge_worker_cpu_and_span_waves 300 k rows (two waves) == P=1, tasks >= 2, worker CPU > 0 fails
E6 a_split_count_distinct_equals_sequential_on_skewed_keys 200 k rows, one target with 60%, 50 k users, P = 4, 16 == P=1, tasks > 0 fails

Interfaces

No interface change: the tests use Operator::aggregate, Operator::with_measure_filters, Operator::with_emit_empty_global and RunContext::with_parallelism as they are. The planned implementation adds no public item:

 // crates/executor/src/operators/aggregate/columnar.rs (planned)
+/// An exact Aggregate whose first wave reaches the run's min split rows, with a group column,
+/// split by group-key hash into part_count(..) parts on the worker pool.
+async fn aggregate_split(..) -> Result<Batch, Error>;
 // crates/executor/src/operators/partitioned.rs (planned, moved from operators/summary/partitioned.rs)
+pub(crate) fn split / fold_wave / next_wave / part_count / groups_in_key_order

Usage (end to end, after the implementation): a query run's RunContext::with_parallelism(P) already reaches every operator. The exact Aggregate collects a first wave of input batches. When it has a group column and enough rows, it splits each batch by key hash into P order-kept parts. Each part folds its rows on a rayon worker with the existing per-chunk body: group_ids, ensure_groups, filter masks, update_measure. After each wave the run charges the parts' tables and states. At the end it orders the parts' groups by key, gathers the labels, finishes each measure per part, and interleaves the measures in that order.

Tests

cargo test -p asap-executor --test executor parallel_execution::: 9 passed, 4 failed (E1, E2, E5, E6: "not split"), as intended for this phase.

Spec and test plan: section 2–3 of the plan (parallel query-time execution). Measurement-only prototype numbers are in the comment below once taken.

🤖 Generated with Claude Code

https://claude.ai/code/session_01K1M6bpWvKMxYBvtAgpDYGp

…over worker threads

Test-first phase 3 of the parallel query-time execution plan (tests E1-E6):
every exact measure grouped by one or two keys (text and float) split 2-8
ways equals the one-thread run cell for cell and row for row; measure
filters, NULLs and float keys with zero signs and NaN payloads; global and
small inputs stay on one thread; the memory limit holds; two waves charge
worker CPU; count distinct on a skewed key (the SB q3 shape).

E1, E2, E5 and E6 fail (the exact Aggregate never splits: 0 partition
tasks); E3 and E4 are guards and pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1M6bpWvKMxYBvtAgpDYGp
@zzylol zzylol added enhancement New feature or request testing Corpus, regression, differential, or benchmark tests labels Dec 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request testing Corpus, regression, differential, or benchmark tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant