Repository navigation
feat(planner): HLL confidence from a deployment distinct-count bound (#678) - #693
Merged
Merged
Conversation
…678) A deployment-supplied upper bound on the distinct items any one distinct-count summary over a source counts per evaluation, including merged panes. Validation rejects a zero bound.
…678) Stage 1 sizes HLL precision from epsilon only and, for an HLL over a source's own rows, states relative error at most its RSE with failure probability left symbolic as classic_hll_failure_probability[p=P](max_distinct[source]). Stage 3 binds it with ClassicHllConfidence from the data workload's max_distinct_per_evaluation; a bound outside the contract's range binds to 1, and a missing bound leaves the target unmet. Tests: Example 2's HLL-only candidate is valid with a bound of 9 and invalid without one; bounds of 10, 100 and 10M leave delta unmet; Stage 1 candidates are identical with and without a bound.
…678) EstimatorContract, AccuracyEvidenceProvider::estimator_contract and EstimatorAccuracy fed classic HLL confidence only to the legacy candidate search; the data workload's distinct bound replaces them in the stage pipeline.
This was referenced Oct 14, 2026
Merged
zzylol
added a commit
that referenced
this pull request
Oct 15, 2026
…), provable KMV (#694) Classic HLL: - Pass 1 sizes precision from (ε, δ) without data: the smallest p with m ≥ 1/(2ε²δ) whose linear-counting tail bound certifies δ at the target ε for every distinct bound up to ⌈1/ε⌉. - SketchParams::Hll records the relative error it was sized for. The guarantee states that target ε as its error bound (not 1.04/√m), and its failure probability is evaluated at it: classic_hll_failure_probability[p=P,eps=E](max_distinct[source]). - Plan selection's enlargement (#669b) applies the same rule to the source's bound and δ/(n·G), at the recorded ε. - The contract's distinct-bound cap rises from 4096 to 2^17 (m/2 at precision 18). KMV: - A provable bound for asap_sketchlib's estimator: exact below k distinct items, and from k on two Chernoff tails of the k-th smallest hash, exp(-ε²(k-1)/((1+ε)(2+ε))) + exp(-ε²(k-1)/(2(1-ε))), for any number of distinct items, so no distinct bound is needed. - SketchParams::Kmv records its relative error; k is the smallest k meeting δ (k = 26,656 at ε = 0.02, δ = 0.01, down from 250,002). - Plan selection enlarges k for a smaller per-value δ. Fixes #700: the guarantee no longer reports a fixed 0.01 whatever δ was sized for. - Theta keeps its Chebyshev calibration (theta_k_99). Review nits from #693: negative tests for the HLL scope condition (a join, computed rows, Hydra grouping, a bound keyed to another source); max_distinct_per_evaluation must hold for the longest window any query over the source uses, per output row.
zzylol
added a commit
that referenced
this pull request
Oct 15, 2026
…), provable KMV (#694) (#715) feat(planner): certify distinct counts at scale: HLL sized from (ε, δ), provable KMV (#694) Classic HLL: - Pass 1 sizes precision from (ε, δ) without data: the smallest p with m ≥ 1/(2ε²δ) whose linear-counting tail bound certifies δ at the target ε for every distinct bound up to ⌈1/ε⌉. - SketchParams::Hll records the relative error it was sized for. The guarantee states that target ε as its error bound (not 1.04/√m), and its failure probability is evaluated at it: classic_hll_failure_probability[p=P,eps=E](max_distinct[source]). - Plan selection's enlargement (#669b) applies the same rule to the source's bound and δ/(n·G), at the recorded ε. - The contract's distinct-bound cap rises from 4096 to 2^17 (m/2 at precision 18). KMV: - A provable bound for asap_sketchlib's estimator: exact below k distinct items, and from k on two Chernoff tails of the k-th smallest hash, exp(-ε²(k-1)/((1+ε)(2+ε))) + exp(-ε²(k-1)/(2(1-ε))), for any number of distinct items, so no distinct bound is needed. - SketchParams::Kmv records its relative error; k is the smallest k meeting δ (k = 26,656 at ε = 0.02, δ = 0.01, down from 250,002). - Plan selection enlarges k for a smaller per-value δ. Fixes #700: the guarantee no longer reports a fixed 0.01 whatever δ was sized for. - Theta keeps its Chebyshev calibration (theta_k_99). Review nits from #693: negative tests for the HLL scope condition (a join, computed rows, Hydra grouping, a bound keyed to another source); max_distinct_per_evaluation must hold for the longest window any query over the source uses, per output row. test(planner): plan selection enlarges a tumbling-pane HLL (#694)
This was referenced Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Closes #678.
Why
The stage pipeline gave HLL distinct counts a relative error (RSE) but no failure probability, so an HLL candidate could never meet a target with δ. The classic HLL confidence model (
ClassicHllConfidence) existed but fed only the legacy candidate search.What
DataWorkload.max_distinct_per_evaluation: Evidence<BTreeMap<String, u64>>, per source (PromQL metric or SQL table), styled likestream_norms. It is an upper bound on the distinct items any one distinct-count summary over the source's own rows counts in one complete evaluation, including merged panes. A zero bound is rejected (WorkloadError::ZeroMaxDistinct).1.04/√m;classic_hll_failure_probability[p=P](max_distinct[source]).HLL over computed rows keeps the RSE-only guarantee, with δ unknown.
ClassicHllConfidence:EstimatorContract,AccuracyEvidenceProvider::estimator_contractandEstimatorAccuracy, with their test inreplacement.rs.ClassicHllConfidenceand its tests stay.How
Stage 1 does not read the data workload. The bound arrives as a deployment input, and one new branch in Stage 3's
workload_statisticresolves the symbolic statistic, the same pattern as stream norms in #687.Key code interfaces added / modified
crates/types/src/workload.rscrates/asap-aware-mapping/src/accuracy/estimators/hll.rs,estimators/mod.rscrates/asap-aware-mapping/src/accuracy/evidence.rs,accuracy/mod.rscrates/asap-aware-mapping/src/per_computation_candidates.rs,stage3_plan_selection.rsUsage, end to end (numbers from running the stages at this PR's merge commit
ac64c279):Before this PR
In Example 2, Q1's HLL candidate (ε = 0.02, δ = 0.01) was invalid: its failure probability was unknown.
After this PR
max_distinct_per_evaluationNoneVerification
cargo nextest run --workspace: 1613 passed, 50 skipped.cargo fmt --all --checkandcargo clippy --workspace --all-targets -- -D warningsclean.448e7491(test,format-and-lint).planner_layering_example2:stage3_plan_selection_accepts_hll_given_a_distinct_bound,stage3_plan_selection_rejects_hll_whose_distinct_bound_is_too_large, andstage1_logical_asap_optimization_leaves_the_hll_failure_probability_symbolic(Stage 1 output is identical with and without a bound).hll.rs: the statistic name round-trips, and binding matchesClassicHllConfidence.workload.rs: a zero bound is rejected.Limitations and follow-ups