Skip to content

feat: size shared summaries for the strictest consumer - #519

Merged
zzylol merged 1 commit into
mainfrom
feat/pass2-strictest-consumer-sizing
Oct 2, 2026
Merged

zzylol merged 1 commit into
mainfrom
feat/pass2-strictest-consumer-sizing

Conversation

@zzylol

@zzylol zzylol commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Why

#509, logical Pass 2, summary-capability rule: when several computations have the same summary input data and window, one summary should serve all of them, sized for the strictest accuracy requirement. After #515 and #516, identical states are already shared, including p50 and p99 at equal accuracy. Queries whose accuracy targets differ still produce different sketch parameters, so they never share. Example: p50 at ε=0.01 and p99 at ε=0.001 over lat[5m].

What

All in crates/asap-aware-mapping/src/replacement.rs, about +110 lines.

  • Siblings. strictest_sibling_accuracy finds sibling targets: single-measure aggregates with the same child, grouping and filters, and the same intent apart from accuracy. A quantile's rank may also differ, since it is only a readout parameter. It returns the tightest ε/δ across them when that is stricter than the target's own.
  • Pass 1. search_cse_workload_with passes the result through TargetSubDAG.strictest_sibling_accuracy. SketchAlgorithmStrategy then adds one extra candidate per sketch, re-sized with the existing size_params, but only if the parameters actually change. Each reader's guarantee is recomputed from the new parameters and its own readout.
  • Sharing and cost. feat: share identical summary producers across queries after Pass 1 #515's CSE merges the equal variants and selection prices them: a shared state is costed once and split across its consumers. On its own, the larger variant costs more and is not chosen.
  • Docs. share_common_summary_subtrees now documents that sharing identical states is the summary-capability rule.

UnivMon sizing is fixed, so it gets no variant. Its distinct, entropy and L2 readouts already share one state when certified.

Not changed: accuracy gates, capability.rs, and AccuracyReconciliationStrategy. No DDSketch Count candidate is added.

Candidate growth

A target gains at most one extra candidate per sketch algorithm, and only when a stricter matching sibling exists.

Tests

New or updated in crates/planner/tests/summary_sharing.rs:

  • quantiles_share_one_producer_sized_for_the_strictest_consumer: p50 at ε=0.01 and p99 at ε=0.001 share one KLL. Its k is the ε=0.001 sizing, and both guarantees meet their own ε. Planned alone, the ε=0.01 query keeps its own sizing. The test fails when the new sibling field is forced to None.
  • different_producers_are_not_shared: dropped the old "different accuracy is not shared" case, because that sharing is now intended. Added stricter-accuracy cases with a different window or selector, which still don't share.
  • certified_frequency_readouts_share_one_univmon_state: distinct, entropy and L2 share one UnivMon state under a test accuracy model that certifies them. This test reproduces the MajorPass steps directly instead of going through e2e_plan, because MajorPass gives its accuracy model only to the final root check, not to the Pass 1 strategies. That will be tracked separately.

Notes

When siblings disagree on which of ε or δ is tighter, the variant takes the tightest of each. The result satisfies every sibling, though no single query asked for exactly that pair.

Validation

On Rust 1.99, all of these pass: cargo fmt --check, clippy with -D warnings, the vendored MetricsQL baseline, and cargo test --workspace.

🤖 Generated with Claude Code

Pass 1 also sizes each sketch candidate for the strictest sibling that
reads the same summary input (same child, grouping, filters and intent
apart from accuracy and quantile rank), so post-ASAP CSE can share one
state across consumers with different accuracy targets (#509 summary-
capability rule).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant