Repository navigation
Conversation
… and SIL SCOPE per_value
- types: max_distinct_per_group_per_evaluation is keyed by label and positive
- accuracy: HLL is exact while a declared per-group bound keeps it sparse (<= m/8)
- frontend-sil: REQUIRE ... SCOPE per_value | whole_result
- integration (W1, E6 x1): whole-result keeps no HLL without the bound; with
{"host": 7200} Pass 2 keeps p16 and Stage 3 selects the chain below exact
- planner SIL: per-host distinct keeps p16 with the bound, p13 with SCOPE per_value
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…E ... SCOPE per_value
- SourceFacts::max_distinct_per_group_per_evaluation ({"host": 7200}): distinct
items one group's distinct count holds per evaluation, keyed by the grouping label;
validated positive (ZeroMaxDistinct)
- Memo::max_distinct_per_group_per_evaluation: the bound for a summary group's keys
- accuracy: exact_while_sparse_guarantee (HLL, bound <= 2^p/8): relative error 0,
failure probability <= n(n-1)/2^65; checked before measured/theoretical guarantees
on the logical edge and in build_meets_level
- SIL: REQUIRE ERROR m <= eps [DELTA d] [SCOPE per_value | whole_result] lowers to
AccuracyTarget::accuracy_scope
- docs: the new fact (input-output workflow), HLL row (accuracy models)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y for HLL distinct counts - Memo::max_distinct_per_group_per_evaluation: None unless the summary reads one scan through single-input operators (a self-join pairs rows the bound does not cover); memo test covers host, (host, dst), dst, ungrouped and a self-join - accuracy: one sparse_exact_guarantee (pub(crate)), checking HLL + Cardinality before computing the bound - SIL: EXACT SCOPE gets its own error; SCOPE before DELTA rejected (test) - docs: the fact holds over one scan of the source Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Stacked on #1562 (
feat/hll-measured-accuracy). Draft: do not merge.What to review first
crates/accuracy/src/guarantee/hll/mod.rssparse_exact_guarantee: HLL's sparse state is the exact set of distinct 64-bit item hashes while it holds at most2^p / 8of them, so over groups declared to hold at mostn ≤ 2^p / 8distinct items per evaluation the count is exact unless two hashes collide. Certified as relative error 0, failing with probability at mostn(n − 1) / 2^65(1.4e-12 at n = 7,200).crates/accuracy/src/logical_edge/mod.rsexact_or_measured_guarantee: that guarantee is checked before the measured table and the theoretical guarantee, both on the readout edge and inbuild_meets_level(Pass 2 sizing). The bound is computed only for an HLL distinct count.crates/types/src/stages/logical/memo/mod.rsMemo::max_distinct_per_group_per_evaluation: the bound applies only when the summary's rows come from one scan of one source (no join, union or binary operator below it) and its keys include a declared label. The smallest declared bound among the keys wins. Every other case getsNone: a coarser group (e.g. a rollup touserover a per-hostbound), a self-join, a per-series value, a computed key, or an ungrouped count.crates/frontend-sil/src/parse.rs:REQUIRE ERROR m <= ε [DELTA δ] [SCOPE per_value | whole_result].Problem
With the measured HLL table (#1562), the planner never keeps HLL for a grouped distinct count over the whole result. Example: E6's
SELECT host, count(DISTINCT value) FROM flows WHERE ts > now() - INTERVAL '1 hour' GROUP BY hostat rel 0.05, δ 0.05 over 10,000 hosts splits δ to 5e-6 per host. The table's smallest δ is 0.005, so no precision is certified and the plan is exact over raw data (7,154.9/s).Change
max_distinct_per_group_per_evaluation, keyed by the grouping label, e.g.{"host": 7200}. When the bound is at most2^p / 8, HLL at precisionpis certified exact (as above), so the δ split no longer matters. The fact holds only over one scan of the source. Without it, behaviour is unchanged.SCOPE per_valuesets the existingAccuracyTarget::accuracy_scopetoPerValue: each grouped value gets δ, with no split across values.SCOPE whole_resultspells out the default.EXACT SCOPE …is rejected with its own message.Interfaces
// crates/types/src/workload/data.rs pub struct SourceFacts { pub max_distinct_per_evaluation: Option<u64>, + /// Distinct items one group's distinct count holds per evaluation, keyed by + /// the grouping label, e.g. {"host": 7200}. Omitted from JSON when empty. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub max_distinct_per_group_per_evaluation: BTreeMap<String, u64>, ... } // crates/types/src/workload/planning.rs - #[error("a source's max_distinct_per_evaluation must be greater than zero")] + #[error("a source's max_distinct_per_evaluation and max_distinct_per_group_per_evaluation bounds must be greater than zero")] ZeroMaxDistinct, // crates/types/src/stages/logical/memo/mod.rs +impl Memo { + pub fn max_distinct_per_group_per_evaluation(&self, group: MemoGroupId) -> Option<u64>; +} // crates/accuracy/src/guarantee/mod.rs (crate-internal) +pub(crate) fn sparse_exact_guarantee( + parameters: &SketchParams, + statistic: &SketchStatistic, + max_distinct_per_group: impl FnOnce() -> Option<u64>, +) -> Option<AccuracyGuarantee>; // SIL grammar (crates/frontend-sil/src/parse.rs) -accuracy::= EXACT | ERROR (abs | rel | rank) '<=' number [ DELTA number ] +accuracy::= EXACT | ERROR (abs | rel | rank) '<=' number [ DELTA number ] + [ SCOPE (per_value | whole_result) ]Design scope
The fact sits beside
max_distinct_per_evaluationinSourceFacts. They differ in scope:max_distinct_per_evaluationmust hold for every distinct count over the source, an ungrouped one included. The new map holds only for groups keyed by the named label. The memo lookup sits besideMemo::max_distinct_per_evaluation. The HLL-specific rule lives inguarantee/hll, and the edge check takes it before the measured table.Usage
End to end with
asap_planner --run-until stage3 --measured-accuracy crates/accuracy/measured/hll_distinct.json. The workload is E6 x1'sflows(10,000 hosts, one row per host every 500 ms, so at most 7,200 rows per host in 1 h). The query is the per-host distinct count above, every 10 s, at rel 0.05 and δ 0.05. The exact baseline excludes every distinct-count sketch with--deployment-capabilities.In SIL the same targets are written as:
sil_intents::scope_per_value_keeps_measured_hllplans this with the measured table and reads HLL at precision 13.per_host_bound_keeps_sparse_exact_hllplans the default scope with{"host": 7200}declared and reads HLL at precision 16.Tests
Failing tests were committed first (db2c887), then the implementation (6f3da00) and review fixes (9a80ab0).
cargo test -p asap-types --lib: 218 pass (newmax_distinct_per_group_per_evaluation_is_per_label_and_positiveandmax_distinct_per_group_per_evaluation_reads_the_grouping_label, which includes a self-join; the round-trip example now carries the field).cargo test -p asap-accuracy: lib 75 pass,hll_measured_accuracy7 pass,measured_sketch_accuracy14 pass (newhll_is_exact_while_the_group_bound_keeps_it_sparse).cargo test -p asap-frontend-sil: 20 pass (newparses_the_accuracy_scope).-p asap-planner --test planner -- sil_intents: 20 pass, 1 fail. The failure isdrill_intent_keeps_hll_at_ingestion_per_mode, which needs feat(cost,accuracy): price HLL states by their distinct items; a ranking (Limit) keeps its input's error #1556's ranking contract and fails the same way on Accuracy: measured per-value tables for HLL and UnivMon, loaded by --measured-accuracy #1562. New:per_host_distinct_over_the_whole_result_reads_no_hll,per_host_bound_keeps_sparse_exact_hll,scope_per_value_keeps_measured_hll.-p asap-integration-tests --test integration -- hll_distinct_ingest univmon_measured: 17 pass, 1 fail. The failure isranked_distinct_keeps_estimates, feat(cost,accuracy): price HLL states by their distinct items; a ranking (Limit) keeps its input's error #1556's failing-first test, unchanged from Accuracy: measured per-value tables for HLL and UnivMon, loaded by --measured-accuracy #1562. New:whole_result_keeps_no_hll_without_a_host_bound,host_bound_keeps_sparse_exact_hll_over_the_whole_result,host_bound_selects_sparse_exact_hll_over_exact.cargo fmt --all --checkpasses.cargo clippy --all-targets -D warningsis clean on asap-types, asap-accuracy, asap-frontend-sil, asap-planner and asap-integration-tests.Not in this PR
SCOPE per_valuedoes not help a ranked query (ORDER BY c DESC LIMIT k): feat(cost,accuracy): price HLL states by their distinct items; a ranking (Limit) keeps its input's error #1556's Limit contract still splits δ over the ranked input's rows. For the ranked q1, the per-host bound is what keeps HLL.🤖 Generated with Claude Code