Skip to content

fix(query-engine): give range-query merges the CMS/KLL batch fast path - #614

Merged
milindsrivastava1997 merged 2 commits into
mainfrom
worktree-issue-596
Aug 25, 2026
Merged

fix(query-engine): give range-query merges the CMS/KLL batch fast path#614
milindsrivastava1997 merged 2 commits into
mainfrom
worktree-issue-596

Conversation

@milindsrivastava1997

Copy link
Copy Markdown
Contributor

Summary

  • NaiveMerger::merge_all (range path) never took the merge_multiple batch fast path that SimpleEngine::merge_accumulators (instant path) already had for CountMinSketch/DatasketchesKLL, so every range query merging those bucket types was slower than the equivalent instant query.
  • The two folds also disagreed on error handling: the instant path warned and silently kept a partial result on a merge_with failure, the range path aborted via ?.
  • Extracted the shared "try batch merge, else sequential fold" logic into engines::merge_utils::merge_accumulators_batch; both callers now delegate to it, so both take the fast path and both abort on the first merge_with failure (no more silent partial merges). Added AccumulatorError::MergeFailed for the new abort case on the instant path.
  • Scope was deliberately kept to the two fold implementations — the outer per-key (merge_precomputed_outputs) and per-timestamp (range step loop) catch-and-skip-with-warn behavior is unchanged.
  • Added 22 adversarial regression tests (cross-path equivalence vs. a self-computed oracle fold, non-commutative fold-order, abort-on-mid-batch-error, batch-merge-fallback, large-batch coverage, empty/single-element edges) written by an agent kept blind to the fix's implementation, targeting only the issue description and public/private API surface.

Test plan

  • cargo test --lib — 598 passed, 0 failed, 5 ignored
  • cargo clippy --lib --tests -- -D warnings — clean
  • cargo fmt --check — clean
  • pre-commit hooks (fmt/check/clippy/test) passed on commit

Closes #596

🤖 Generated with Claude Code

https://claude.ai/code/session_01WDS34V2EexpbihCfH9SDWh

milindsrivastava1997 and others added 2 commits August 25, 2026 19:06
#596)

NaiveMerger::merge_all (range path) only did a sequential merge_with
fold, never the merge_multiple batch fast path that
SimpleEngine::merge_accumulators (instant path) already had for
CountMinSketch/DatasketchesKLL. The two folds also disagreed on error
handling: SimpleEngine's warned and silently kept the partial result,
NaiveMerger's aborted via `?`.

Extract the shared "try batch merge, else fold" logic into
engines::merge_utils::merge_accumulators_batch and have both callers
delegate to it, so both now take the fast path and both abort on the
first merge_with failure instead of one of them dropping data
silently. Adds AccumulatorError::MergeFailed for the new abort case.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WDS34V2EexpbihCfH9SDWh
… test fixtures

Two follow-ups from review of the #596 fix:

- merge_accumulators_batch always cloned the first accumulator, even
  for the common single-bucket case, regressing the move-based
  shortcut SimpleEngine::merge_accumulators had before this refactor.
  Restore it at the call site (NaiveMerger can't do the same since it
  merges from a borrowed Vec it keeps for the next slide()).
- The new regression tests duplicated PoisonableAccumulator,
  cms_from_matrix, and oracle_sequential_fold verbatim between
  window_merger.rs and simple_engine/mod.rs; moved them into
  tests::test_utilities::merge_fixtures, shared by both.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WDS34V2EexpbihCfH9SDWh
@milindsrivastava1997
milindsrivastava1997 marked this pull request as ready for review August 25, 2026 23:42
@milindsrivastava1997
milindsrivastava1997 merged commit a3011ca into main Aug 25, 2026
13 checks passed
@milindsrivastava1997
milindsrivastava1997 deleted the worktree-issue-596 branch August 25, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Range query merges lack the CMS/KLL batch-merge fast path instant queries get

1 participant