Skip to content

fix(accuracy): split δ over the readout values the covered output values depend on - #1360

Open
zzylol wants to merge 23 commits into
mainfrom
fix/delta-split-over-dependent-readouts
Open

zzylol wants to merge 23 commits into
mainfrom
fix/delta-split-over-dependent-readouts

Conversation

@zzylol

@zzylol zzylol commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: Pass 2 split a query's failure probability δ per readout value by max(values the scope covers, readout values per evaluation). A per-value target on quantile_over_time(0.99, m[5m]) over 8 series got δ = 0.01 / 8 = 0.00125 per readout, although each output value is one readout value. KLL then needs k = 2863 instead of k = 1404.
  • Change: δ now splits over the readout values that the output values covered by one (ε, δ) statement depend on: min(R, V · fan_in). One function holds the rule, AccuracyTarget::failure_probability_per_readout_value. The readout walk in readout_caps computes both counts in the same pass.
  • Round 1: a readout group also counts its other candidates' readouts, a top-k readout depends on every value it ranks, a concatenation is classified with or, and a readout level that the same listed builds meet as a stricter level is dropped. The last keeps the MILP no larger than the base's.
  • Round 2: R from a readout's groups of rows is an upper bound only when the readout is keyed by the sources' labels or columns. A readout grouped by a computed key or a time (GROUP BY date_trunc('minute', ts)) now has R unknown, so with n_q unknown too it gets no per-value δ, as on the base.
  • Round 3: R is now a true upper bound across joins and for SQL keys. It is computed as SQL optimizers estimate a GROUP BY's groups (the product of the key columns' distinct counts, clamped to the input rows), but from declared facts only. Keys from different scans multiply: a join of two 6-value keys gives 36, not 6 + 6. A SQL key bounds R only through its declared distinct values; a measure key such as GROUP BY bytes is bounded only by the rows the query reads per evaluation (series_count × samples in the window, or rows_held), and is unknown without them.
  • Round 4: the query's value count n_q now follows the same rule as R. Stage 0 takes it from Memo::max_values_per_evaluation of the root group. Before, a grouped SQL result was capped by the table's series_count, so GROUP BY dst with 300 dst values over 6 groups of rows got n_q = 6 and a whole-result target split δ over 6 instead of 300. A join's keys now multiply in n_q too, and an undeclared key is bounded by the rows read. A PromQL instant vector is still at most its series read, and its n_q also tightens through the key lineage: quantile by (job) (0.5, a and on(job) b), a unless ignoring(instance) b, a + ignoring(side) b, count_values by (job), a subquery and a label_replace of another label each go from 200 or 400 to the 10 declared job values. The tree-walking copy of the group rule in workload::bounds is deleted.
  • Round 5: two more shapes under-counted R and n_q, and this round adds a check that finds such shapes by construction instead of by review.
    • A group_left/group_right match between two selectors of one metric pairs labels of two series, so its "one" side now counts as another scan, as a join's right side does: m{side="l"} * on(x) group_left(instance) m{side="r"} by (job, instance) gets 100, not 10.
    • An outer join's nullable side gains a NULL its source does not hold, so its columns count as computed and only the rows read bound them: flows LEFT JOIN hosts ... GROUP BY h.region no longer gets 6.
    • LIMIT n over the whole input caps the rows at n.
    • crates/integration-tests/tests/memo_value_bounds.rs runs each bounded group of 85 query shapes that the executor can run over data the declared facts allow, built to seek the worst case, and fails when a group returns more values than its bound. It finds both new bugs at 14330d53e, and the round-3 and round-4 bugs at the commits before their fixes. Bounds the executor cannot run yet are listed one by one in the test, so none goes unchecked silently.
    • The lineage rules in column_properties now list every variant (clippy's wildcard_enum_match_arm), so a new operator must state its lineage.
  • Round 6 polish: a LIMIT n above a grouping caps its values at n (… GROUP BY dst ORDER BY q DESC LIMIT 5: 96 → 5; topk(5, …) in the survey: 1000 → 5). The oracle now tracks coverage per bound, fails a bound that never runs or never returns a value unless listed, crosses few-valued keys first (so it now finds the j_full under-count too), and p13_unless reads two metrics so its result is not always empty.
  • Round 7: rebased onto main with the exact distinct-count cost refit. Two plan-choice tests now assert what measurement supports: the KLL test reads the ks Stage 1 offers, and the distinct rollup test expects KMV at its planned 60,000 rows per state, where KMV measures 1.26x faster than exact (exact is 1.39x faster at 12,000).
  • Round 8: rebased onto main 1760a69f5. query_levels keeps this PR's split; main's AccuracyTarget::failure_probability_per_output_value stays for constraint (K)'s root rows, and main's Memo::max_distinct_per_evaluation sits next to keys_of_values. build_meets_level, which drops redundant readout levels, now passes the state's value sign and distinct bound to theoretical_guarantee, as the edge check does since refactor(stage3): constraint (K) per execution and metric; sign-conditioned DDSketch guarantee, classic HLL certificate from the source's distinct bound (#1207 PR 8) #1238. The or/ratio readout test declares its values non-negative, so its DDSketch builds are certified.
  • Effect: the 8-series per-value example keeps δ = 0.01. Of the 209 surveyed workloads, 205 plans are unchanged, including all of RollupHeavy. Four RangeHeavy plans change between MILP near-ties (cost within 4e-8 relative), and their MILPs shrink by 720 variables. Round 5 changes no surveyed plan or level. Planning time on RollupHeavy-8u is unchanged (16.1 s → 16.4 s median, ranges overlapping, identical MILP size), and RangeHeavy-8u gets faster (6.7 s → 5.0 s).

Review guide

Round-1 fixes

Finding Fix Test
F1 (medium): a readout group was forced to (R_group, 1), ignoring its other candidates, so a reduction over readouts in the same group was under-split The group's own counts (R_group, 1) and its candidates' walked counts are combined field by field with ReadoutValueCounts::larger (unknown when either is) a_readout_group_holding_a_reduction_splits_over_the_readout_values_below_it: δ / 1000, was δ
F2: top-k readouts got fan-in 1, though their output keys are chosen by estimate A group holding a SummaryEstimate of TopK sets per_output_value = per_evaluation a_topk_readout_splits_over_every_value_it_ranks: CMS-heap top-10 over 1,000 series per value → δ / 1000, was δ
F3 Body: "Why the RollupHeavy KMV shrinks" replaced (see the plan survey section)
F4 Body: the no-raw lifetime flips are described; with E1 they are gone
E1 (medium): MILP grew and solved 1.75× slower on RollupHeavy-8u without_redundant_levels drops a level when the listed builds meeting it are exactly those meeting a stricter level of the group (builds_meeting, the same check as the logical edge, measured evidence first) a_level_met_by_the_same_builds_as_a_stricter_one_is_dropped (DDSketch, δ-independent: one level); levels_met_by_different_builds_are_both_kept (KLL: both kept)
A1 ReadoutValueCounts::larger and ::plus replace the two closures readout_value_counts_combine_count_by_count
A2 takes_each_value_from_one_input is evaluated once per candidate
A3 A concatenation is classified with or: its fan-in is the larger input's, and it no longer makes the query composed a_concatenation_takes_each_value_from_one_readout: δ per value, single level, was the composed grid
L1 Kept in asap-types, as the reviewer allows, for the upper accuracy refactor's per-value δ
L2 ReadoutValuesRead → ReadoutValueCounts
L3 Concepts doc paragraph re-wrapped; inputs_read_value_by_value's doc says both counts are per evaluation, not per subquery step

Round-2 fixes

Finding Fix Test
N1 (medium): a whole-result target grouped by a time bucket, with n_q unknown, split δ over R = series_count (6), though the result has one value per bucket (about 16): KLL k = 547, whose guarantee at δ / 16 is over the target Memo::max_values_per_evaluation bounds a readout by the groups of rows scanned and the declared label counts only when every key of its state or aggregate is a source label or column copied unchanged and not a time (keys_of_values). A computed key or a time key gives None. A readout over a state of unknown shape also gives None. The bucket bound ceil(range / width) × other keys' groups is not implemented: the scan's time range is no memo group property, so it would need new plumbing; None is the sound fallback a_whole_result_grouped_by_a_time_bucket_gives_its_readout_no_level (was δ / 6, live); a_whole_result_grouped_by_a_source_column_and_a_time_bucket_gives_its_readout_no_level (was δ / 6); a_whole_result_grouped_by_a_source_column_splits_over_the_groups_of_rows (src undeclared, n_q unknown: δ / 6, before and after); max_values_per_evaluation_is_unbounded_for_a_computed_or_time_key (date_trunc, job + date_trunc, ts → None; job → 20)
N1 doc Concepts doc: "splits over R alone" replaced; R and max_values_per_evaluation say they bound only label-keyed readouts
B1 Body: 16 new readout_caps tests, not 11
B2 Body: the RollupHeavy survey row covers the 1-user and 8-user variants

a_per_value_ratio_splits_over_the_two_readout_values_of_each_output_value now checks the walked counts (16, 2) and the query's grid directly: with E1, a DDSketch readout keeps only the strictest δ of each error level, so the loosest δ is no longer visible on the readout.

Round-3 fixes

Finding Fix Test
J1 (medium): max_values_per_evaluation summed series_count over the scanned sources, but a join multiplies them. flows JOIN hosts ... GROUP BY f.src, h.region, 6 src and 6 region values, n_q unknown: R = 6 + 6 = 12, KLL at δ / 12, though the result can hold 36 values Keys are grouped by the scan they come from (source and scan_ordinal), and the per-scan bounds multiply. This also fixes the self-join case (a.src, b.src over one table was 6, not 36). workload::bounds::group_count_bound is not reused: it works on operator trees with a DataWorkload and adds label counts across sources, while the memo reads lineage per scan and resolves histogram families (series_facts) a_whole_result_over_a_join_splits_over_the_product_of_its_sides_values (δ / 36, was δ / 12; and δ / 30 when the join reads at most 6 × 5 rows); max_values_per_evaluation_multiplies_the_keys_of_different_scans (self-join by both sides' job: 400, was 20)
V1 (low, decided): a SQL key that is a measure column (GROUP BY bytes) got R = series_count, though nothing says which columns form a table's groups of rows As SQL optimizers estimate a GROUP BY's groups (the product of the key columns' distinct counts, clamped to the input rows), but as an upper bound: R = min(product of the declared distinct values of the keys, per scan; the rows the readout's input reads per evaluation). A SQL key's scan contributes only its declared distinct values (distinct_values_per_label or a label set); with any key undeclared the product is unknown and the rows alone bound R. The rows read are new: max_rows_per_evaluation walks the memo below the readout (a TimeRange over a Scan holds series_count × (window / sample_interval + 1) rows, at most rows_held; a Scan alone rows_held; a join the product, a union the sum; operators that keep or drop rows their input's). PromQL label keys keep their series bound (each series has one label set), and per-series PromQL readouts keep the summed series (PromQL has no join) a_whole_result_grouped_by_an_undeclared_measure_column_splits_over_the_rows_read (no sample_interval: no level, was δ / 6; sampled every minute over 15 minutes: δ / 96); a_whole_result_grouped_by_a_declared_source_column_splits_over_its_distinct_values (renamed from ..._splits_over_the_groups_of_rows, which relied on the groups of rows with src undeclared; now src declares 4: δ / 4)
Body The "Decided" item and the correctness bullet no longer say R is an upper bound only for label-keyed readouts; the doc line the review flagged is wrapped

Round-4 fixes

Finding Fix Test
n_q under-split (recorded as a follow-up in round 3): workload::bounds::values_per_result capped a grouped SQL result by the table's series_count. GROUP BY dst, with 300 dst values declared over 6 groups of rows, got n_q = 6. A whole-result target covers n_q values, so δ split over min(R = 300, 6 × 1) = 6, although the result can hold 300 values. A join's keys were not traced at all (n_q unknown) n_q uses the rule R uses, from the same code: min(product over scans of the declared distinct values of the result's group keys, rows its grouping reads per evaluation). Stage 0 passes Memo::max_values_per_evaluation of the root group to values_per_result. keys_of_values now looks through the operators above a grouping that keep, drop or reorder its rows (projection, filter, sort, limit, dedup), through a finalization, and through a merge that keeps its states' groups. A PromQL instant vector is still also at most series_read. An undeclared SQL key leaves only the rows read, or nothing. smaller_known moves to workload::bounds and SourceFacts::max_rows_in_window uses it. The IR-side declared_group_bound and declared_distinct_combinations in bounds are deleted, so the group rule exists once a_result_grouped_by_a_declared_key_returns_up_to_its_declared_values (n_q 300, δ / 300; was 6 and δ / 6; sampled every minute: 96, δ / 96); a_result_grouped_by_an_undeclared_key_returns_at_most_the_rows_read (GROUP BY bytes: unknown without a sampling interval, 96 with one; was unknown in both cases); a_result_grouped_by_keys_of_joined_scans_returns_up_to_their_product (36, and 30 when the join reads 6 × 5 rows; was unknown); a_promql_result_returns_at_most_its_keys_declared_values_or_its_series (guard: sum by (job) 20 with job declared, 1000 without; rate(m[5m]) 1000)

Callers of n_q (MemoQuery::number_of_values_per_query_evaluation, set only by Stage 0). There is one reader, readout_caps::query_levels, which passes it to AccuracyTarget::failure_probability_per_readout_value as V = AccuracyScope::max_values_covered(n_q). What each consumer now gets:

  • Readout levels (Pass 2 set_readout_requirements). A whole-result query gets δ / min(R, n_q · fan_in). Since n_q and R now come from the same rule, n_q is never below the readout values it covers for a grouped SQL result. GROUP BY dst gets δ / 300 instead of δ / 6. GroupsWithRecordShareAtLeast gets min(⌊1 / share⌋, n_q), which is unchanged unless n_q was the smaller term. A query whose n_q was unknown and is now bounded (a join, an undeclared key over known rows) keeps the level R already gave it: min(R, n_q · fan_in) = R there.
  • Sizing (which listed θ a state candidate keeps) reads these levels (builds_meeting, without_redundant_levels). A stricter level keeps only builds that meet it, so GROUP BY dst now keeps only KLL builds that meet rank 0.01 at δ / 300.
  • The guarantee check on the logical edge (edge_meets_logical_requirements, build_meets_level) checks a producer's θ against the same levels. Stage 3 only re-checks guarantees. Neither reads n_q directly.
  • Exact-only queries (queries_without_per_value_failure_probability): a query whose n_q and R are both unknown still gets no level. No query newly enters or leaves this set in the survey.

Round-5 fixes

Finding Fix Test
S1 (medium): with group_left/group_right between two selectors of one metric, the labels copied from the "one" side kept the output side's scan ordinal, so one label-set count bounded labels of two series. quantile by (job, instance) (0.5, m{side="l"} * on(x) group_left(instance) m{side="r"}), 10 (job, instance) pairs declared: n_q = R = 10, though the output can hold 100 pairs The "one" side's columns move past the output side's scans with after_left_scans, the rule a join's right side already uses. job and instance then come from two scans and multiply: 10 × 10. A matched label keeps the output side's lineage (it is equal on both sides), and or still keeps what both sides agree on a_many_to_one_match_within_one_metric_returns_up_to_the_product_of_both_sides_labels: group_left, group_right(job) and m … m offset 1h, each 100 (was 10); by (job, instance) over m alone stays 10. a_same_source_group_right_takes_the_right_sides_labels (from main) now expects team at scan 1
S2 (low-medium): an outer join adds a NULL group the declared counts do not include. flows f LEFT JOIN hosts h ... GROUP BY h.region, 6 regions: n_q = R = 6, true worst case 7. FULL JOIN ... GROUP BY f.src, h.region: 36, true worst case 42 (WHERE f.ts >= … drops the rows with a NULL f, so the full join acts as a left join: 36 + 6) Of the two fixes the review offered, the nullable side's columns are now computed by the join: the Right side of a Left join, the Left side of a Right join, both of a Full join. They no longer hold their source column's values, which is what ColumnLineage requires for equal lineage. Its keys then fall back to the rows read. The match lists every JoinKind a_key_from_the_nullable_side_of_an_outer_join_is_bounded_by_the_rows_read: Left and Full, by h.region and by f.src, h.region, each 678, the rows bound (was 6 or 36); the inner join stays 36
L1 (low, no action) None. SQL top-k and distinct-count readouts lost the series_count bound in round 3, which was not sound for a SQL key
L2 (nit): max_rows_per_evaluation passed a Limit's input rows through LIMIT n with no partition keeps at most n rows. A partitioned limit (topk by) keeps its input's bound a_grouping_over_a_limit_returns_at_most_its_rows: 10 (was 96)
N1 The doc line of max_values_per_evaluation is re-wrapped
N2 The round sections are in order
N3 The Round 4 summary says PromQL n_q also tightens through key lineage, with the examples the review listed
Recurring class: each round found a new under-count The memo value bound oracle (below), plus exhaustive lineage arms: column_properties now lints wildcard_enum_match_arm as node.rs and time_window.rs do. #1330's lint covered only those modules and cost::node::usage, not this one. The operator arms were already exhaustive. The three wildcards it found (project_lineage and the sign rules expression_sign and measure_sign) now list every variant with the same answers. keys_of_values keeps its _ => None, which bounds nothing memo_value_bounds_hold_on_data_the_declared_facts_allow

Round 7: rebase onto main and two plan-choice tests

Rebased onto main 79d99326e. Two integration tests asserted plans that the new δ split changes. Both now assert what measurement supports.

Test Before After
default_cost_plan_ranking::quantile_rank_without_raw_data_charges_the_larger_kll_more Asserted k = 547 selected and k = 1,404 charged over 1.25x more. With the new split, Stage 1 offers stored KLL windows at k = 269, 547, 1,404 and 2,863 (this PR's per-value split lets k = 269 meet the 1% rank target at δ = 0.01; main offered 547, 1,404 and 2,863) Reads the ks Stage 1 offers from the memo. Asserts the selected plan keeps the smallest offered k, that k = 1,404 is charged over 1.25x more than k = 547 (the measured pair, 1.6-2.5x), and that the next larger k than the smallest is charged more
rollup_controlled::production_distinct_rollup_counts_exactly Asserted exact counts for COUNT(DISTINCT user_id) by service and by (service, endpoint) at 600,000,000 rows per evaluation. With the new split KMV is sized at k = 4,323 (not 26,656), and the planner picks KMV for both queries Renamed to production_distinct_rollup_builds_kmv_at_60k_rows_per_state. Asserts both queries read a KMV and the plan builds one. The comment records the measured crossover (below)

At 12,000 rows per state this PR already counts both queries exactly, as measurement supports. An earlier probe reported KMV there, but it changed only arrival.rows_per_second; the planner prices a scan from series_count × sample_interval, so that probe still planned 600,000,000 rows. Planned at 12,000 rows per state (10,000 series sampled every 25 ms), the selected plan is exact. The KMV build is still charged less than it measures (0.61–0.85 of its time); #1373 tracks that, and #1375 refits it.

The rollup's better plan depends on the rows per state. Measured on the executor, both plans over the same data:

shape exact KMV k = 4,323 faster
60,000,000 rows, 60,000 rows per state (the planned rows per state; scaled ×10 to one evaluation) 609.6 s 483.6 s KMV, 1.26x
12,000,000 rows, 12,000 rows per state 12.79 s 17.84 s exact, 1.39x

The planned shape (600,000,000 rows over 10,000 groups) has 60,000 rows per state, so the test expects KMV. No cost constant changed. The KMV build is still under-charged at the 60,000,000-row shape (553 operations per row charged, 755 measured); that is a KMV cost question outside this PR.

-fn production_distinct_rollup_counts_exactly()
+fn production_distinct_rollup_builds_kmv_at_600m_rows_per_evaluation()

production_rollup_workloads::production_sql_distinct_region_service_counts_exactly now passes with main's refit and picks exact counts.

Round-6 polish

Finding Fix Test
O1 (low): a case counted as run when any one of its bounds ran, so 15 bounds in 8 running cases went unchecked silently (the n_q of p11_scalar_pv, p12_vector_or, d_distinct, p_cv_by, p_cv_key, p_subq_outer, p_labelrep_qot_whole; d_distinct's Dedup, p11's Project) The report keeps each bound as case:what with the most values any dataset returned. EXECUTOR_GAPS now lists each unrun bound (63) with the operator it lacks; any other bound that never runs fails the test memo_value_bounds_hold_on_data_the_declared_facts_allow
O2 (low): p13_unless (qot(0.9, m) unless qot(0.5, m)) is empty on every dataset, so its n_q was never tested p13_unless reads a unless b over two metrics. A bound whose largest count is 0 fails unless listed in NEVER_REACHED (empty) Same test; with the old p13_unless it fails naming p13_unless:n_q
O3 (low): the crossed dataset gave the fastest digit to the label sorted first, so dst (300 values) cycled while src stayed fixed over the 96 rows a window reads, and joins were never filled Declared components are crossed smallest first. The join-key-aware strategy the review also offered is not added: it needs the join keys parsed from the query, and the sort already fills the join probes Against 14330d53e's bounds code the oracle now also finds j_full 36 → 42 on the crossed dataset (12 violations, as the review showed); 0 at this head
L3 (low): keys_of_values passes through a Limit above a grouping, so … GROUP BY dst ORDER BY q DESC LIMIT 5 got n_q = 96 max_values_per_evaluation also takes the rows the group itself returns (max_rows_per_evaluation), which caps a whole-input LIMIT by n, as L2 does below a grouping a_limit_over_a_grouping_returns_at_most_n_values: 5 (was 96)
Nit: the Join arm ran after_left_scans for semi and anti joins and threw the result away The right side's columns are computed only when the join keeps them
Nit: the lint header named no kept matches!/if let, and did not say tuple matches go unchecked The header names each kept identity check and why every other variant's answer is "no", and that arithmetic_sign's _ => Unknown is unchecked, where Unknown is the safe answer
B1, B2, B3 (body and doc) The S2 row says 42; the oracle wording says it runs the bounds the executor can run; the datasets doc comment says four worst-case datasets

Memo value bound oracle

crates/integration-tests/tests/memo_value_bounds.rs, with its corpus in memo_value_bounds_fixtures/cases.json. It checks soundness against data, so it does not rely on a reviewer thinking of the shape:

  1. Corpus. The default corpus has 85 queries: the review probes of rounds 2, 3 and 5, over the facts they were reviewed with. The ignored variant adds the dag-viewer workloads in the repo and any manifest of workloads named in ASAP_MEMO_VALUE_BOUNDS_WORKLOADS.
  2. Bounds. Each query is lowered as planning lowers it. Each node's group gets its bound from Memo::max_values_per_evaluation, the R of a readout over that group, and the query's n_q comes from Stage 0's memo_of_queries.
  3. Datasets. Each dataset keeps to the declared SourceFacts: at most series_count series (or groups of rows), each label within its distinct_values_per_label count, each label set within its distinct_values_per_label_set count, one sample per sample_interval, and at most rows_held rows.
    • Four datasets seek the worst case. In the first, labels declared together take random combinations per series or row. The second puts each component in a mixed radix, the fewest-valued first, so every combination of components appears within the rows a window reads. The third cycles them together. The fourth replaces half the series between the times a query reads, as with offset.
    • Labels the query compares with literals split the series into blocks, and free labels such as x in on(x) are unique within a block, so a match pairs series one to one across blocks.
    • Six random datasets follow (40 in the ignored variant).
  4. Check. The executor runs each bounded node it can run at query time and counts its rows. A count above the bound fails, and the message names the case, the group, the bound, the count and the dataset.
  5. Speed. About 5 s warm in a debug build (11 s with the test binary's link): cases run on up to 8 threads, at most 240 series and 20 samples each. The ignored variant runs at most 1,200 series and 40 samples each.
  6. Gaps. Coverage is tracked per bound (case:what). The executor cannot run 63 of the 244 bounds yet: all of 17 cases (date_trunc, CAST, upper, label_replace, a subquery, rate over histogram buckets, a UNION ALL below a grouping, row_number() as a key), and some bounds of 8 more (DISTINCT, a scalar() or vector() operand, a quantile over count_values). The frontend does not lower 2 cases. EXECUTOR_GAPS lists each unrun bound with the operator it lacks, and NEVER_REACHED each bound that runs but returns no values on every dataset (none). A bound joins the check once it can run, and any other bound that never runs or never returns a value fails the test.

What it catches:

Code under test Violations Examples (bound → observed)
14330d53e (round-4 head) S1 and S2 p_gl_same 10 → 63, p_gr_same 10 → 59, p_gl_same_offset 10 → 59 (the "replaced" dataset), j_left 6 → 7, j_full 36 → 42 (the "crossed" dataset, since round 6), for both R and n_q
3e61530a5 (round 3 fixed, before the round-4 n_q fix) n_q, and S1 and S2 c_dst n_q 6 → 80, g_two 6 → 88, r_dst_interval_small 6 → 12
a46b0ed9e (before the round-3 fix of J1 and V1) J1, V1, n_q, S1 and S2 J1: j_self 6 → 22, j_self_cross 6 → 93, j_two 12 → 17, j_three 12 → 18. V1: r_bytes_interval 6 → 90, c_value_col 6 → 90
This head none

N1 (date_trunc) is not shown: the executor cannot run date_trunc yet. The round-1 commits are not shown either: before round 2, max_values_per_evaluation meant a readout bound only, so other groups' counts do not apply to it.

Behavior: before → after

The user writes a per-value rank target on a per-series quantile:

{"data_workload": {"sources": {"m": {"series_count": 8}}},
 "query_workload": {"language": "promql", "repeating_queries": [{
   "query": "quantile_over_time(0.99, m[5m])",
   "requirements": {"accuracy": {"accuracy_metric": "rank", "max_error": 0.0025,
     "failure_probability": 0.01, "accuracy_scope": "per_value"}}}]}}
δ each KLL readout must meet KLL k
before 0.01 / max(1, 8) = 0.00125 2863
after 0.01 / min(8, 1 · 1) = 0.01 1404

Each output value is one series' readout, so a per-value statement fails only when that one readout fails. The k values are the closed-form sizes reported by the draft asap_run suite's kll_sized_by_closed_form_without_measured_table. This PR checks δ at the readout (a_per_value_target_without_a_reduction_keeps_the_whole_failure_probability).

The rule applied to each case:

Case before after
8 series, no reduction, per value 8 1
8 series, no reduction, whole result 8 8
global max over 1,000 series, any scope 1,000 1,000
sum by (job), 1,000 series in 10 jobs, per value 1,000 1,000 (see open question 1)
sum by (job), 10 jobs, whole result 1,000 1,000
q or r, 100 series each side, per value 200 1
q or r, whole result of 100 values 200 100
max by (job) (q or r), 3 series per side 6 6
concatenation of two readouts over 100 series, per value 200 (composed grid) 1 (one level)
CMS-heap top-10 over 1,000 series, per value 1,000 1,000
readout group also holding sum over 1,000 per-series readouts, per value 1,000 1,000
nested max(sum by (job) (q)), 1,000 series 1,000 1,000
record share 0.25 over 8 series, no reduction 8 4
ratio of two readouts, 8 series, per value 16 2
per value, series_count unknown, no reduction no per-value δ (readout pruned) 1
whole result, n_q unknown, R = 100 no per-value δ (readout pruned) 100

This serves correctness and cost: sketches are no larger than the union bound needs, and the bound still holds under any dependence between readouts.

Interfaces

Round 6 changes no signature. Memo::max_values_per_evaluation also takes the rows the group itself returns (doc comment updated with the LIMIT 5 example).

Round 5 changes no signature. ColumnLineage::Computed now also covers a column of an outer join's nullable side (doc comment updated), and Memo::max_values_per_evaluation's doc names the two new cases. The oracle is a test file.

Round 4 changes one public signature. Stage 0 is its only caller:

 // crates/types/src/workload/bounds.rs
 pub fn values_per_result(
     root: &QueryRoot,
     series_read: Option<u64>,
-    data: &DataWorkload,
+    values_by_keys: Option<u64>, // Memo::max_values_per_evaluation of the root group
 ) -> Option<u64>
-fn declared_group_bound(node: &OperatorNode, data: &DataWorkload) -> Option<u64>
-fn declared_distinct_combinations(node: &OperatorNode, columns: &[usize], data: &DataWorkload) -> Option<u64>
+pub(crate) fn smaller_known(a: Option<u64>, b: Option<u64>) -> Option<u64> // moved from stages::logical::memo

Memo::max_values_per_evaluation keeps its signature and now also bounds a query result over a grouping (doc comment updated).

Round 3 changes no public signature. Memo::max_values_per_evaluation now also clamps to the rows read and multiplies keys across scans (doc comment updated); new crate-private helpers are Memo::max_rows_per_evaluation, SourceFacts::max_rows_in_window and smaller_known, and KeysOfValues now holds the keys' source columns (PerSeries, SourceColumns(Vec<SourceColumn>), ComputedOrTime) with the input group they are computed from.

Round 2 changes no signature. Memo::max_values_per_evaluation(group) -> Option<u64> now returns None for a readout or state keyed by a computed or time key (doc comment updated), and its private helper declared_groups_of_state is replaced by keys_of_values.

crates/types/src/accuracy/target/mod.rs, re-exported from crates/types/src/accuracy/mod.rs

 impl AccuracyTarget {
     /// The metrics this target accepts an error in.
     pub fn metrics(&self) -> Vec<AccuracyMetric>;
+    /// The failure probability each readout value below the query must meet:
+    /// δ / min(R, V · fan_in), an unknown term dropping out of the min; 1 without
+    /// a δ; `None` when no bound is known. Pass 2 calls it for each query reaching a readout.
+    pub fn failure_probability_per_readout_value(
+        &self,
+        values_per_evaluation: Option<u64>,
+        readout_values: ReadoutValueCounts,
+    ) -> Option<f64>;
 }
+
+/// The readout values (sketch estimates) a query's output depends on, per
+/// evaluation: what its failure probability splits over. `None` is unknown.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct ReadoutValueCounts {
+    /// `R`: every readout value one evaluation reads.
+    pub per_evaluation: Option<u64>,
+    /// The fan-in: the most readout values one output value depends on.
+    pub per_output_value: Option<u64>,
+}
+
+impl ReadoutValueCounts {
+    /// The larger, count by count (alternative candidates of one group); unknown when either is.
+    pub fn larger(self, other: Self) -> Self;
+    /// The sum, count by count (the roots of one query); unknown when either is or on overflow.
+    pub fn plus(self, other: Self) -> Self;
+}

crates/accuracy/src/readout_caps/mod.rs, Pass 2's caller in crates/stage1-pass2-reuse-candidates/src/readout_requirements.rs passes the evidence it already has:

 pub fn readout_levels(
     memo: &Memo,
     error_metrics: &ErrorMetricsOfMemo,
     order: &[MemoGroupId],
+    evidence: &dyn AccuracyEvidence,
 ) -> BTreeMap<CandidateForMemoGroupId, ReadoutRequiredAccuracy>;

AccuracyScope::max_values_covered is unchanged. Its doc no longer says that a guarantee check multiplies a per-value δ by it, because no code on this base does.

The other changes in asap-accuracy are private: query_levels takes a ReadoutValueCounts instead of Option<u64>, ReadoutsReadByQueries::readout_values holds one per query, and inputs_read_value_by_value, without_redundant_levels, builds_meeting and build_meets_level are new private functions.

Usage (end to end, as the test a_per_value_target_without_a_reduction_keeps_the_whole_failure_probability runs it):

// The data facts: `m` holds 8 series, so a readout of it returns at most 8 values.
let mut memo = Memo::new(&with_series("m", 8));
// Stage 0/Pass 1 shape of `quantile_over_time(0.99, m[5m])`: range → KLL state → readout.
let (_, _, readout) = quantile_over_time(&mut memo, SketchAlgorithm::Kll, 0.99, 300);
// The query's target: rank error 0.0025, δ = 0.01, per value; it returns 8 values (n_q).
memo.add_query(MemoQuery {
    root: QueryRoot::Operator(readout),
    accuracy_target: Some(AccuracyTarget::max_error(0.0025).failure_probability(0.01)
        .accuracy_metric(AccuracyMetric::Rank).accuracy_scope(AccuracyScope::PerValue)),
    number_of_values_per_query_evaluation: Some(8),
});
// Pass 2: readout_levels walks the memo. For this query, R = 8 and fan_in = 1
// (the root is the readout itself), and it calls
// target.failure_probability_per_readout_value(Some(8), ReadoutValueCounts {
//     per_evaluation: Some(8), per_output_value: Some(1) }) == Some(0.01).
let order = memo.topological_order().unwrap();
let levels = readout_levels(&memo, &ErrorMetricsOfMemo::of(&memo, &order), &order, &NoMeasuredGuarantees);
// The readout's one requirement level: rank 0.0025 at failure probability 0.01
// (before: 0.00125). Each KLL edge then checks its k against it, and k = 1404 passes.
assert_eq!(levels[&own_candidate(readout)].levels[0].failure_probability, 0.01);

Design scope

New item Scope Why it is general
ReadoutValueCounts (struct, asap-types accuracy::target) Accuracy targets: what a target's δ splits over Any (ε, δ) statement over approximate values needs two counts: the values read per evaluation and the values one output depends on. It names no operator or summary. It sits beside AccuracyScope, and the IR layer can use it because it imports nothing from stages.
AccuracyTarget::failure_probability_per_readout_value (method) Accuracy targets It uses only the target's δ and scope plus the counts. It is the one place the union-bound split is stated. With #1238 it is defined on failure_probability_per_output_value (δ / V): δ / min(R, V · fan_in) = max(δ / R, per_output_value / fan_in); see "With #1238".
ReadoutValueCounts::larger / ::plus (methods) Accuracy targets Field-wise combining of the two counts, on the type whose data they use; the walk and the query fold call them.
without_redundant_levels, builds_meeting (private functions, asap-accuracy readout_caps) Stage 1 Pass 2 readout requirements Any readout's levels, for any summary type: a level is redundant when the listed builds that meet it equal those of a stricter level. They name no summary type.
build_meets_level (private function, asap-accuracy logical_edge) Stage 1 Pass 2 logical edges The build-against-level check the edge already did, extracted so the level pruning uses exactly the edge's test (measured evidence, else theory).
KeysOfValues (private enum) and Memo::keys_of_values (private method), asap-types stages::logical::memo Stage 0/1 memo: bounds on a group's values from the declared facts What a readout's or state's values are keyed by: one per series, the source columns it groups by (each naming its scan), or a computed or time key; and the group they are computed from. It reads only memo groups' expressions, lineage and schemas, beside max_values_per_evaluation, its one caller, and replaces the former declared_groups_of_state.
Memo::max_rows_per_evaluation (private method), asap-types stages::logical::memo Stage 0/1 memo: bounds on a group's rows from the declared facts The rows any relational group returns per evaluation, from its expression and its inputs' bounds; every non-ASAP operator is listed. It is the clamp of the GROUP BY estimate, and the memo-side counterpart of workload::bounds::row_bound, which works on operator trees and counts series rather than rows in a window.
SourceFacts::max_rows_in_window (crate-private method), asap-types workload::data Data workload facts The rows a window over one source holds, from its own series_count, sample_interval and rows_held: a fact about the source, so it sits on SourceFacts.
smaller_known (crate-private function), asap-types workload::bounds (moved there in round 4) Bounds read from the data workload The smaller of two optional upper bounds, either alone. The memo bounds, SourceFacts::max_rows_in_window and values_per_result use it.
inputs_read_value_by_value (private function, asap-accuracy readout_caps) Stage 1 Pass 2 readout requirements It classifies operators by whether one output value reads one value of each input. It sits next to takes_each_value_from_one_input, which the same walk uses, and every operator it does not list falls back to the conservative R.

Round 5 adds no production type. New test files:

New file Scope Why it is general
crates/integration-tests/tests/memo_value_bounds.rs Integration tests of the memo's value bounds (Stage 0/1 memo against the executor) It checks Memo::max_values_per_evaluation and n_q for any query and any declared facts, not one operator: a new corpus case needs only a query and its facts. Its types (Case, Report, BoundCoverage, Dataset, Component, Pattern) are private to the test. BoundCoverage (round 6) is what the datasets showed of one bound: the most values returned, and why the executor last rejected it
crates/integration-tests/tests/memo_value_bounds_fixtures/cases.json Its default corpus 85 queries and the 18 fact sets they are checked over, with one SQL catalog (flows, hosts)

No new production files.

Algorithm changes

Failure-probability split per readout value (Pass 2 readout requirements)

  • Problem: the split ignored which readout values an output value depends on. It used max(V, R), so a statement over few output values, each reading one readout, still split δ over all of R. Examples: 8 series per value gave δ / 8; a bare q or r per value gave δ / 200.
  • Before:
    1. readouts_read_by_queries sums R per query.
    2. query_levels computes δ / max(max_values_covered(n_q)?, R?).
    3. Either count unknown means no per-value δ.
  • After:
    1. The same topological walk carries ReadoutValueCounts per group.
      • A readout group is (max_values_per_evaluation, 1), or (R, R) for a top-k readout, combined with larger with its other candidates' counts (a reduction over readouts below it).
      • Per candidate, per_evaluation sums the inputs that read with error, as before.
      • per_output_value depends on the operator. For one that inputs_read_value_by_value lists, it is the sum of the inputs' per_output_value, or their largest for or and a concatenation; an input referenced only from a scalar expression contributes its whole per_evaluation. For any other operator, such as an aggregate, a window function, a time range or a limit, it equals per_evaluation.
      • Over a group's alternative candidates, the largest is taken.
    2. A query sums both counts over its roots.
    3. failure_probability_per_readout_value returns δ / min(R, V · fan_in), where an unknown term drops out and both unknown means None.
    4. Over the union of a readout group's levels, a level is dropped when the listed builds that meet it (per readout of the group and θ of its summary type's list, the only θ a state candidate may have) are exactly those that meet a stricter level (at most its error and δ). This is exact: every producer a copy at the looser level accepts, the stricter copy accepts too, at the same cost, and a stricter level only tightens a composed query's sum. Every strictest level is kept, so each dropped level's builds stay those of a kept one.
  • Correctness: the statement covers at most V output values, and each depends on at most fan_in readout values. So it fails only if one of at most V · fan_in readout values fails, and never more than the R that are read. The union bound over that set holds under any dependence. fan_in is an upper bound by construction: a listed operator copies or combines one value per input, and every other operator takes all of its inputs' values. Composed queries keep their grid, now capped at the per-value δ, so the levels of the readouts behind one output value still sum within δ. A ratio has fan-in 2, so the levels sum within δ / 1. Tests: 16 new readout_caps tests, plus failure_probability_splits_over_the_readout_values_covered for the rule.
  • Complexity: the same single walk over the memo, O(groups + candidates · inputs), with a second Option<u64> per group. Level pruning is O(L² · P) per readout group, with L its levels and P its readouts' listed θ; the non-MILP planning time does not change (608 → 606 ms on RollupHeavy-8u). Without it, the new split produced more distinct δ levels that the same builds meet (RollupHeavy-8u: 8,003 → 8,243 variables, solve 1.75× slower in review); with it, every RollupHeavy MILP has the base's size, and RangeHeavy's shrink (see the survey).
  • R is an upper bound: a readout's values are at most the distinct combinations of its keys, which are at most the product, over the scans the keys come from, of each scan's declared distinct values for its keys (a join or a self-join pairs values of different scans, so they multiply, and so does the "one" side of a group_left/group_right match, whose columns move past the output side's scans; a PromQL scan's keys are also at most its series, each series having one label set), and at most the rows its input reads per evaluation, since every group holds at most one row. A key with no declared count bounds nothing by itself: a SQL measure key, a computed key, a time, or a column of an outer join's nullable side, which can hold a NULL its source does not; the groups of rows a SQL table declares do not say which columns form them, so they bound no SQL key. Per-series PromQL readouts are at most the series scanned, summed, since PromQL has no join. This is the GROUP BY estimate of SQL optimizers (the product of the key columns' distinct counts, clamped to the input rows) with declared upper bounds in place of statistics (rounds 2, 3 and 5). Review found a new exception in every round, so round 5 checks the bound against execution: the memo value bound oracle runs every bounded group the executor can run over data the declared facts allow, and finds the round-3, round-4 and round-5 bugs at the commits before their fixes.
  • Assumptions and limits: a grouped reduction takes all of its input's readout values as the fan-in. The declared facts bound how many groups exist, not how many series one group holds (open question 1). Time steps of a subquery or range over a readout are not counted, as before.

Decisions and open questions

Needs reviewer decision

  1. Fan-in under sum by (job): pending your decision on max_series_per_label_value. The reviewer recommends deferring it: no surveyed plan needs it, and the fallback to R is safe; add it when a workload with per-value targets on grouped reductions shows a plan change. The reviewer's shape, if added:

    • Existing facts cannot bound it: distinct_values_per_label_set over {job} plus the identity labels counts combinations across all jobs, and counting only gives a lower bound (N / J) on the largest job. A product of the other identity labels' counts bounds it only if the full identity label set were declared, which SourceFacts does not do.
    • It belongs in SourceFacts, with the same "upper bound the deployment must ensure" contract as distinct_values_per_label:
      #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
      pub max_series_per_label_value: BTreeMap<String, u64>, // e.g. {"job": 100}
    • A reduction by (K) would then take fan_in = min(R, min over k in K of that count), since a group by K sits inside its group by any single k.

    Original analysis: The requested table expects sum by (job), 100 series per job, per value → divisor 100. This PR gives 1,000.

    • SourceFacts::distinct_values_per_label is documented as an upper bound on how many jobs exist. It does not bound how many series one job holds: with 1,000 series and job: 10, one job may hold 991 of them. Using series_count / distinct = 100 would let a 991-series job fail with up to 9.91 δ.
    • The sound value today is the reduction's input R. That is the conservative fallback the rule allows, so a_grouped_sum_per_value_splits_over_every_readout_value_when_group_sizes_are_unbound pins 1,000.
    • Proposal: if per-group bounds matter, add a declared data fact, for example max_series_per_label_value: {"job": 100} in SourceFacts (data workload scope). A grouped Aggregate would then take min(R, that bound) as its fan-in. failure_probability_per_readout_value already handles it: the rule's own test checks (per_value, R = 1000, fan_in = 100) → 100.
    • This adds a new workload fact, so it is your call.
  2. The per-value δ with refactor(stage3): constraint (K) per execution and metric; sign-conditioned DDSketch guarantee, classic HLL certificate from the source's distinct bound (#1207 PR 8) #1238. refactor(stage3): constraint (K) per execution and metric; sign-conditioned DDSketch guarantee, classic HLL certificate from the source's distinct bound (#1207 PR 8) #1238 (Tracking: implement the optimization formulation (memo candidates, properties, edges y_{u,c,i}, MILP) as named code per stage #1207 PR 8) adds AccuracyTarget::failure_probability_per_output_value(n_q) = δ / V, the δ of one output value, and keeps (K)'s root rows on it. Whichever PR merges second defines this PR's per-readout δ on it: failure_probability_per_readout_value(n_q, counts) = δ / min(R, V · fan_in) = max(δ / R, per_output_value / fan_in), an unknown term dropping out, 1 without a δ; readout_caps::query_levels then calls it alone. (K) stays on the per-output-value δ. See "With refactor(stage3): constraint (K) per execution and metric; sign-conditioned DDSketch guarantee, classic HLL certificate from the source's distinct bound (#1207 PR 8) #1238".

Decided

  • 2026-11-16: an unknown term drops out of the min instead of making the whole split unknown. A per-value target over series of unknown count now gets a level (divisor 1), and a whole-result target with unknown n_q splits over R. This is sound only because R is kept an upper bound across joins and SQL keys (the correctness bullet under Algorithm changes): keys from different scans multiply, a SQL key counts only through its declared distinct values, and every readout is clamped to the rows it reads (round 3). The round-1 wording claimed each fallback "is an upper bound" without these conditions, which was wrong for time-bucketed SQL results (round 2), for joins and for SQL measure keys (round 3), and for many-to-one matches within one metric and outer joins (round 5). Rejected: keeping "both known" (it prunes sketches that are provably fine).
  • 2026-11-16 (V1, decided by you; you can still override it): R must be a true upper bound, so a SQL key bounds it only through declared distinct values, clamped to the rows read: R = min(product of the keys' declared distinct values, rows read per evaluation), as SQL optimizers estimate a GROUP BY. A key with no declared count bounds nothing by itself; with the rows unknown too, R is unknown. Rejected: documenting that a SQL series_count must bound every non-time key combination (the second option in the review), which would put a new obligation on every SQL data workload.
  • 2026-11-16 (round 5): an outer join's nullable columns are computed, so a key from them is bounded only by the rows read. In the j_left probe that is 1.3e13 (3.6 million rows on each side), so the KLL level is δ / 1.3e13. On main the readout was pruned and read exactly. The tighter alternative, one more value per key scan reached through a nullable side (7 for j_left), needs a nullability mark on ColumnLineage::SourceColumn. It is not done: no surveyed workload has an outer join.
  • 2026-11-16: the composed grid stays unchanged. Only its cap, the per-value δ, uses the new split.

Verification

Round 8 (head 793859e2d on main 1760a69f5; local release build, cargo test --release --no-fail-fast -p asap-cost -p asap-accuracy -p asap-types -p asap-stage0-memo -p asap-stage1-pass1-per-computation-candidates -p asap-stage1-pass2-reuse-candidates -p asap-integration-tests and -p asap-stage3-plan-selection --lib, run on main too and compared by name):

Run Result
asap-cost 83 pass (main: 83)
asap-accuracy 62 pass (main: 46)
asap-types lib / tests 183 / 80 pass (main: 179 / 80)
asap-stage0-memo, Pass 1, Pass 2 9, 37, 28 pass (same as main)
asap-stage3-plan-selection lib 30 pass (main: 30)
Integration tests 210 pass, 6 fail, 5 ignored (main: 196, 6, 4). The same 6 tests fail on main by name (listed under round 7). memo_value_bounds, both rollup_controlled tests and the KLL ranking test pass
cargo fmt --all --check; cargo clippy --release --all-targets -- -D warnings on the eight crates clean

Round 7 (head 5e17d5727 on main 79d99326e; local release build, cargo test --release --no-fail-fast -p asap-cost -p asap-stage3-plan-selection -p asap-integration-tests, run on main too and compared by name):

Run Result
asap-cost 83 pass, 0 fail (main: 83, 0)
asap-stage3-plan-selection lib 18 pass, 0 fail (main: 18, 0)
Integration tests 206 pass, 6 fail, 5 ignored (main: 192, 6, 4). The 6 failures are the same tests by name as on main: joint_search_equivalence::{rootless_request_overhead_respects_capacity_and_latency, unsupported_exact_operation_never_returns_an_unvalidated_plan}, materialized_views::materialized_views_equal_the_stored_outputs_main_listed, plan_sharing::{nested_exact_sum_reuses_newest_tumbling_windows, slower_repeat_reuses_faster_sum}, promql_to_post_asap::promql_quantile_of_rate_binds_kll_over_rate_accumulator
The two round-7 tests, production_sql_distinct_region_service_counts_exactly, the oracle pass
cargo fmt --all --check; cargo clippy --release on the six changed crates --all-targets -- -D warnings clean

Round 6 (head 94ee2a503 on main 863153e3c; local debug build, the same six-crate cargo test --no-fail-fast as round 5, compared by name with main):

Run Result
Round-6 test on 78289c000 (0ba0cf89b) Fails for the intended reason: n_q = Some(96) instead of Some(5)
Head 588 pass, 7 fail, 5 ignored (main: 554, 7, 4). The 7 failures are the same tests by name as on main; the extra pass is the round-6 test
Oracle, default corpus 85 cases, 244 bounds (63 listed as executor gaps), 627 executions, 0 violations, 0 never reached; 4.6 s warm, 11 s with the link
Oracle against 14330d53e's bounds code 12 bounds broken: S1 (p_gl_same, p_gr_same, p_gl_same_offset) and S2 (j_left, and now j_full 36 → 42), each for R and n_q
Oracle with the old p13_unless Fails: p13_unless:n_q never reached
cargo fmt --all -- --check; cargo clippy on the six crates --all-targets -- -D warnings clean
Plan survey, 209 workloads, 78289c000 → head (remote, release) 0 plans changed. Statuses are the same (186 planned, 20 without a plan, 3 crashes p24/p32/p34 on both sides). RollupHeavy MILP sizes identical in all 4 variants
Readout levels and n_q, 209 workloads 1,963 readouts, 1,533 with a level, 12 pruned, on both sides; no level changed. n_q changes only for the five global topk(k, …) workloads (c03, c12, c17, p05: 1000 → 5; p28: 1000 → 3), the LIMIT-above-a-grouping shape
Readout levels and n_q, the review's 46 probes Only l_limit_over changes: n_q 96 → 5. Its readouts' levels are unchanged (none on either side)

Round 5 (head 78289c000 on main 863153e3c; local debug build, cargo test --no-fail-fast -p asap-types -p asap-accuracy -p asap-stage0-memo -p asap-stage1-pass1-per-computation-candidates -p asap-stage1-pass2-reuse-candidates -p asap-integration-tests, run on main too and compared by name):

Run Result
Round-5 tests on 14330d53e (3de89b150) All 3 fail for the intended reason: the group_left query gets n_q = Some(10) instead of Some(100), the left join Some(6) instead of Some(678), the grouping over LIMIT 10 Some(96) instead of Some(10)
Head 587 pass, 7 fail, 5 ignored (main: 554, 7, 4). The 7 failures are the same tests by name as on main. The extra passes are the 3 round-5 tests and the oracle; the extra ignored test is the oracle's large variant
Oracle, default corpus 85 cases, 244 bounds, 628 executions, 0 violations, 9 s
Oracle against 14330d53e's bounds code (this head's tests, with the round-5 fix reverted in crates/types/src) 9 bounds broken, in 23 executions: S1 (p_gl_same, p_gr_same, p_gl_same_offset) and S2 (j_left), each for R and n_q
Oracle at 3e61530a5 and a46b0ed9e the n_q bug, and J1 and V1 (table above)
Oracle, large variant over the 209 survey workloads and the dag-viewer workloads (remote, release) 325 cases, 5,036 bounds, 68,046 executions, 0 violations, 20 min on 8 threads. 57 cases the executor cannot run on any dataset; the executor rejected 154 datasets
cargo fmt --all -- --check; cargo clippy on the six crates --all-targets -- -D warnings clean
Plan survey, 209 workloads, 14330d53e → 78289c000 (remote, same main) 0 plans changed. Statuses are the same (186 planned, 20 without a plan, 3 crashes p24/p32/p34 on both sides). RollupHeavy MILP sizes are identical in all 4 variants
Readout levels and n_q, 209 workloads 1,963 readouts, 1,533 with a level, 12 pruned for unknown values, on both sides. No n_q and no level changed: no surveyed workload has a many-to-one match within one metric, an outer join, or a grouping over a LIMIT
Readout levels and n_q, the review's 46 probes Only the review's cases changed. p_gl_same, p_gr_same, p_gl_same_offset: n_q and R 10 → 100, DDSketch δ 1e-3 → 1e-4. j_left: 6 → 1.3e13 (the rows bound: 3.6 million flows rows times 3.6 million hosts rows), KLL δ / 6 → δ / 1.3e13. j_full: 36 → 1.3e13, KLL δ / 36 → δ / 1.3e13. l_limit_under: 96 → 10, KLL δ / 96 → δ / 10

Round 4 (head 14330d53e on main 863153e3c; local, cargo test --release --no-fail-fast -p asap-types -p asap-accuracy -p asap-stage0-memo -p asap-stage1-pass1-per-computation-candidates -p asap-stage1-pass2-reuse-candidates -p asap-integration-tests, compared by name with the round-3 main 863153e3c run):

Run Result
Round-4 tests on 6c2d763bc (3e61530a5) The 3 SQL tests fail for the intended reason. GROUP BY dst gets n_q = Some(6) instead of Some(300). GROUP BY bytes, sampled, gets None instead of Some(96). The join gets None instead of Some(36). The PromQL guard passes
Head 583 pass, 7 fail, 4 ignored. The 7 failures are the same tests by name as on main (joint_search_equivalence ×2, materialized_views, plan_sharing ×2, promql_to_post_asap ×2). asap-stage0-memo: 9 of 9 pass
cargo fmt --all -- --check; cargo clippy --release on the six crates above --all-targets -- -D warnings clean
Plan survey, 209 workloads, 6c2d763bc → 14330d53e (remote, same main) 0 plans changed. Statuses are the same (186 planned, 20 without a plan, 3 crashes p24/p32/p34 on both sides). RollupHeavy MILP sizes are identical in all 4 variants
Readout levels and n_q (209 workloads + 30 probes), 6c2d763bc → 14330d53e 2,015 readouts and 1,557 levels on both sides. One level changed: the GROUP BY dst probe, δ / 6 → δ / 300. 15 queries changed n_q, all SQL; no PromQL n_q changed. In the 209 workloads only n09_sql_topk_window changed (unknown → 3,600,000, the rows_held, from its top-k's rows read), and it gained no level. In the probes, GROUP BY dst went 6 → 300. The two-table join and the self-join went unknown → 36, and their one-key variants unknown → 6. Nine probes keyed by a measure, a computed key, a cast or a time (CASE, casts, upper, a subquery alias, a raw ts, value, time buckets) went unknown → 3,600,000 (their rows_held). Those levels did not change: each already split over the same R

Round 3 (head 6c2d763bc on main 863153e3c; remote, cargo nextest run --release --no-fail-fast -p asap-types -p asap-accuracy -p asap-stage1-pass1-per-computation-candidates -p asap-stage1-pass2-reuse-candidates -p asap-integration-tests, compared by name with main 863153e3c):

Run Result
Round-3 tests on 89bf188fe (a46b0ed9e) The 3 new tests fail for the intended reason: the join gets δ / 12 = 0.000833 (the review's J1 repro) instead of δ / 36; GROUP BY bytes gets (live, δ / 6) instead of no level; the self-join memo test gets Some(20) instead of Some(400). The rewritten declared-src test passes (it guards the declared-key case)
Head 569 run: 562 pass, 7 fail, 4 skipped. The 7 failures are the same tests by name as on main (joint_search_equivalence ×2, materialized_views, plan_sharing ×2, promql_to_post_asap ×2); no test that passes on main fails here. (The first head run also failed the two new tests on a test bug: the self-join used series scans, which a join rejects, and the time predicate above a join is a filter, not a window. Both were fixed in the test commit and pass on rerun.)
cargo fmt --all -- --check; cargo clippy --release -p asap-types -p asap-accuracy -p asap-stage1-pass1-per-computation-candidates -p asap-stage1-pass2-reuse-candidates --all-targets -- -D warnings; cargo clippy --release -p asap-integration-tests --lib --test integration -- -D warnings clean (main now lints wildcard arms in two modules; max_rows_per_evaluation lists every operator anyway)
Plan survey, 209 workloads (197 set + 12 paper workloads), 89bf188fe (round-2 head on the same main) → 6c2d763bc 0 plans changed; same statuses (186 planned, 20 without a plan, 3 crashes p24/p32/p34 on both sides); RollupHeavy MILP sizes identical in all 4 variants
Readout levels after Pass 2 (209 workloads + 30 review probes), 34b5827e2 → 6c2d763bc 2,015 readouts on both sides; 1,550 → 1,557 have a level. Every changed level is a SQL readout keyed by a measure, a computed key or a time, or over a join. No PromQL level changed. Changes: the join probe δ / 12 → δ / 36; GROUP BY bytes δ / 6 → δ / 3.6e6 (the probe declares rows_held 3,600,000 and no sample_interval, so the rows held bound R); the time-bucket, CASE, cast, subquery-alias and upper key probes no level → δ / 3.6e6, for the same reason; n09_sql_topk_window and x14_sql_global_from_grouped readouts without a target (an exact requirement) switch between "exact level" and "pruned for unknown values" with no plan change. R changed without a level change in 11 more: SQL top-k and distinct-count readouts lose the groups-of-rows bound (R 1000 → unknown, n_q still sets their level), GROUP BY dst (300 declared) gets R = 300 instead of 6, and a PromQL label_replace key gets R = 100 from the rows of its instant vector instead of unknown. The levels of 89bf188fe on the same main equal those of 34b5827e2

Round 2 (same command and crates, head 34b5827e2, compared by name with the base bc48168dc run of round 1):

Run Result
Round-2 tests on d5f171d96 (4ec3a316b) 3 of 4 fail for the intended reason: the two bucket tests get (live, Some(0.00167)) instead of (pruned, None); the memo test gets Some(1000) instead of None for by [date_trunc]. The src test passes (it guards the label-keyed case)
Head 547 run: 540 pass, 7 fail, 4 skipped. The same 7 fail by name as on the base; no base pass is lost; the 4 extra passes over d5f171d96 are the round-2 tests
cargo fmt --all -- --check; cargo clippy --release -p asap-types -p asap-accuracy -p asap-stage1-pass1-per-computation-candidates -p asap-stage1-pass2-reuse-candidates -p asap-integration-tests --all-targets -- -D warnings clean
Plan survey, 209 workloads (197 set + 12 paper workloads), d5f171d96 → 34b5827e2 0 plans changed; same statuses (186 planned, 20 without a plan, 3 timeouts p24/p32/p34); RollupHeavy MILP sizes identical in all 4 variants. The narrower R changed no selected plan (levels inside Pass 2 were not compared)

Round 1 (cargo nextest run --release --no-fail-fast -p asap-types -p asap-accuracy -p asap-stage1-pass1-per-computation-candidates -p asap-stage1-pass2-reuse-candidates -p asap-integration-tests, base bc48168dc and head d5f171d96, compared by name):

Run Result
Round-1 tests on b1be9955e (cd15dc540) 4 of the 5 new readout_caps tests fail for the intended reason: 0.01 != 0.00001 (F1, F2), the composed grid instead of one level (A3), two levels instead of one (E1); the KLL guard passes
Base 525 run: 518 pass, 7 fail, 4 skipped
Head 543 run: 536 pass, 7 fail, 4 skipped. The same 7 fail by name (joint_search_equivalence ×2, plan_sharing ×2, promql_to_post_asap ×2, materialized_views ×1); no base pass is lost; the 18 extra passes are this PR's tests
cargo fmt --all -- --check; cargo clippy -p asap-types -p asap-accuracy -p asap-stage1-pass1-per-computation-candidates -p asap-stage1-pass2-reuse-candidates --all-targets -- -D warnings clean

Initial version (all runs cargo nextest, remotely, on b1be9955e and on the base bc48168dc, compared by test name):

Scope Result Newly failing vs base Notes
cargo nextest run -p asap-accuracy -E 'test(readout_caps)' on the test commit only (a577c752e) 13 pass, 7 fail 7 (intended) Each failure is an over-split: 0.00125 != 0.01, 0.00005 != 0.01, 0.00125 != 0.0025, loosest ratio level 1e-4 (expected 1e-3), an_or_takes_each_value_from_one_readout (5e-5 vs 1e-4), and two "no per-value failure probability" where only the fan-in is known
cargo nextest run -p asap-types -p asap-accuracy -p asap-stage1-pass2-reuse-candidates -p asap-stage1-pass1-per-computation-candidates 355 / 355 pass none
cargo nextest run -p asap-integration-tests -p asap-devtools -p asap-planner --no-fail-fast 246 pass, 65 fail, 8 skipped (base: the same 65) none The 65 fail on the base too (todo!("#1207 PR 9") paths)
cargo fmt --all -- --check; cargo clippy -p asap-accuracy -p asap-types --all-targets clean

New tests (in readout_caps/tests.rs, plus one in target/tests.rs):

  • a_per_value_target_without_a_reduction_keeps_the_whole_failure_probability: 8 series, KLL, per value → 0.01.
  • a_whole_result_target_without_a_reduction_splits_over_the_values_returned: → 0.01 / 8.
  • a_global_max_splits_over_every_readout_value_in_any_scope: per value, whole result and share 0.5 → 1e-5.
  • a_grouped_sum_per_value_splits_over_every_readout_value_when_group_sizes_are_unbound and a_grouped_sum_over_its_whole_result_splits_over_every_readout_value: → 1e-5.
  • an_or_per_value_keeps_the_whole_failure_probability: → 0.01. The existing an_or_takes_each_value_from_one_readout now expects 1e-4 (whole result of 100).
  • nested_reductions_split_over_every_readout_value_below_them: max(sum by (job)) → 1e-5.
  • unknown_readout_values_split_by_the_fan_in_when_it_is_known: → 0.01 without a reduction, no level under max.
  • a_whole_result_with_unknown_values_returned_splits_over_the_readout_values: → 0.01 / 100.
  • a_record_share_scope_splits_over_the_readout_values_of_the_groups_it_covers: share 0.25 over 8 series → 0.01 / 4.
  • a_per_value_ratio_splits_over_the_two_readout_values_of_each_output_value: loosest grid level 1e-3.
  • failure_probability_splits_over_the_readout_values_covered: the rule's table, including unknown terms.

Plan survey (selected plans, base bc48168dc → this head d5f171d96)

Each workload was planned with run_default_search_over and the executor's summary families, as plan_installable does. The RollupHeavy entries use the corrected manifest lines with rollup_tables.json (the paper manifest's RollupHeavy line has no tables file and fails with "table flows not found").

Set Workloads Plans changed Status changes
197-workload review set (functional, offset, stored-shift, windowed SQL, public o11y corpus, viewer) 197 0 none (186 planned, 20 without a plan, 3 timeouts p24/p32/p34, on both sides)
Paper sets (RangeHeavy and RollupHeavy, 1 and 8 users, counter variants, with and without raw data) 12 4 (RangeHeavy only) none
Workload MILP vars / rows Plan change Cost per second
RollupHeavy, 1 and 8 users, with and without raw data (4) identical to base (8,003 / 20,770 for 8 users) none: same nodes, sizes and lifetimes identical
RangeHeavy 4,807 / 5,663 → 4,087 / 4,943 18 FinalizeExactAccumulator lifetimes flip None ↔ OneEvaluation(Memory) 10343.568009734 → 10343.568009764
RangeHeavy 8 users 4,777 / 10,728 → 4,057 / 9,288 261 → 257 nodes 10344.195993 → 10344.195590 (lower)
RangeHeavy counter 4,847 / 5,728 → 4,127 / 5,008 one DDSketch α = 0.05 state → KLL k = 2863 10351.968009683 → 10351.968009794
RangeHeavy 8 users counter 4,817 / 10,853 → 4,097 / 9,413 one DDSketch α = 0.05 state → KLL k = 1404 10352.595589599 → 10352.595589583

The RangeHeavy changes are MILP near-ties, at most 4e-8 relative. The MILP shrinks because a composed DDSketch quantile readout had 11 levels, (5%, 1e-6) plus each finer error at both 1e-7 and 1e-8. DDSketch's relative error does not depend on δ, so the 1e-7 copies are met by the same builds as the 1e-8 copies and are dropped, which leaves 6 levels. Every remaining change is an equal-cost choice the smaller MILP resolves differently.

The RollupHeavy KMV. In round 1, the flows COUNT DISTINCT KMV chain went from k = 106,263 to k = 26,656. The reason the body gave was wrong:

  • At the base, the flows 5%-share levels are δ = 0.05 / 1000 = 5e-5 and 0.05 / 3000 = 1.67e-5. k = 26,656 already meets both: it guarantees ε = 0.0277 and 0.0295, under 0.05. So k = 106,263 was never required. The base picked it as a MILP near-tie: cost 1744.7604085 against 1744.7604070, about 1e-9 relative.
  • The new levels: a group read only by 5%-share queries gets 0.05 / min(R, 20 · 1) = 0.0025. A group that other scopes also read gets the union, less redundant levels: {5e-4, 0.0025, 8e-5} → 8e-5, {5e-4, 0.0025} → 5e-4, {0.002, 0.0025} → 0.002, because k = 26,656 is the smallest listed k meeting each (k = 4,323 reaches only ε = 0.0564 at 0.0025; the closed-form minimum is 5,468, the gap is grid granularity). HLL readouts of the same groups collapse the same way. KLL readouts keep 2e-5, 8e-5, 5e-4, 0.002 and 0.0125, one level per group.
  • At this head, the MILP has the base's size again and picks k = 106,263 again: the same near-tie, now resolved as on the base. The plan equals the base's in all four RollupHeavy variants.

Without raw data (round 1). The round-1 body said the no-raw plans were the same. They were not: in both no-raw variants, the lifetimes of 14–20 SummaryEstimate/Project nodes flipped between None and OneEvaluation(Memory), at equal cost (about 1e-12). At this head, both no-raw plans equal the base's.

Planning time (median of 5 serial runs pinned to one core, base and head alternating)

Workload Total MILP solve Non-MILP MILP size
RollupHeavy-8u 16.06 s → 16.38 s (runs: base 15.9–17.1 s, head 16.0–16.8 s) 15.31 s → 15.66 s 608 → 606 ms 8,003 vars / 20,770 rows, both
RangeHeavy-8u 6.73 s → 5.02 s 6.21 s → 4.53 s 461 → 442 ms 4,777 / 10,728 → 4,057 / 9,288

Round 1 measured RollupHeavy-8u at 19.0 s → 32.8 s (MILP 8,003 → 8,243 variables). With level pruning the MILP has the base's size and the times overlap, so there is no slowdown to follow up. The round-1 body's "planning time is unchanged" was wrong for that head; this table replaces it.

Accuracy check (executed, round-1 head)

Run on the round-1 head, where the plan used k = 26,656 for the flows chain. This head's RollupHeavy plan equals the base's (k = 106,263), so the check below bounds the smaller choice the MILP may also make.

A local harness (not committed) planned the 48 COUNT DISTINCT queries of RollupHeavy through the production path. It ran the selected plan with the executor at query time over generated http and flows rows: 600,000 rows each over 15 minutes, skewed so the large groups hold about 80k–240k distinct values, above k. It then compared every group in each query's scope with its exact distinct count.

Run KMV sizes in the plan Values checked Over ε = 0.05 Worst relative error (changed flows queries) Worst overall
this PR, seed 1 46 × k = 26,656 1,510 0 0.0084 0.0142
this PR, seed 2 46 × k = 26,656 1,492 0 0.0075 0.0091
this PR, seed 3 46 × k = 26,656 1,508 0 0.0110 0.0125
base, seed 1 13 × k = 106,263, 33 × k = 26,656 1,510 0 0.0022 0.0142

Follow-ups

With #1238

#1238 (#1207 PR 8) adds AccuracyTarget::failure_probability_per_output_value(n_q) = δ / V, the δ of one output value. It returns None without a δ, or when a whole-result δ has an unknown n_q. (K)'s root rows read it. #1238 keeps its readout_caps::query_levels change minimal: min(per_output_value, δ / R), bit-identical to main's δ / max(V, R).

Whichever PR merges second defines this PR's per-readout δ on the per-output one, so each rule is written once:

…e covered output values depend on

Cases: per-value and whole-result targets without a reduction, a global
max, a grouped sum per value and over the whole result, nested
reductions, `or` per value and over the whole result, unknown readout
values, a record-share scope and a per-value ratio. Seven fail on the
current split, which divides by max(values covered, readout values).
…ues depend on

A query's failure probability was split per readout value by
max(values covered, readout values per evaluation): a per-value target on
`quantile_over_time(0.99, m[5m])` over 8 series got δ / 8 although each
output value is one readout value, doubling KLL's k (1404 -> 2863).

The union bound needs only the readout values the output values one
statement covers depend on: min(R, V * fan_in), with R the readout values
per evaluation, V the values the scope covers and fan_in the most readout
values one output value depends on (1 at a readout, carried value by value
through filters, projections, binary operators and `or`, all of the input's
values through a reduction). One function states it,
`AccuracyTarget::failure_probability_per_readout_value` over
`ReadoutValuesRead`; the readout walk computes both counts. An unknown
term drops out of the min, so a per-value target over series of unknown
count keeps δ, and a whole-result target with unknown n_q splits over R.
…ncatenations and redundant levels

A readout group that also holds a reduction over other readouts, a top-k
readout, and a concatenation each split δ over the readout values their
output values depend on; a level the same listed builds meet as a
stricter one is dropped.
…ver all values, drop redundant levels

- A readout group takes the larger of its own readout counts and its other
  candidates' (a reduction over readouts below it), field by field.
- A top-k readout's output value depends on every value it ranks.
- A concatenation takes each value from one input, like `or`.
- A level the same listed builds meet as a stricter level of the group is
  dropped: a copy at it accepts the same producers.
- ReadoutValuesRead is renamed ReadoutValueCounts, with larger and plus.
…the declared groups of rows

A whole-result quantile grouped by date_trunc('minute', ts) over a table
declaring 6 groups of rows returns about 16 values per evaluation, so its
readout must not split δ over 6. Grouped by src alone, the split over the
6 groups of rows still holds.
…en it is keyed by source labels

Memo::max_values_per_evaluation bounded every readout by the series (groups
of rows) scanned below it. A readout grouped by a computed key or a time,
such as date_trunc('minute', ts), returns one value per bucket, which that
count does not bound: a whole-result target with an unknown value count
split δ over 6 for about 16 values. The bound now applies only when every
key of the readout's state (or aggregate) is a source label or column
copied unchanged and not a time; otherwise R is unknown and, with n_q
unknown too, no per-value failure probability follows, as on the base.
… clamped to the rows read

- `flows JOIN hosts ... GROUP BY f.src, h.region` splits δ over 6 × 6 = 36
  readout values, or over the rows the join reads when fewer.
- `GROUP BY bytes`, a measure key with no declared count, splits over the
  rows read (96 for 6 groups of rows sampled every minute over 15
  minutes), and gets no level when they are unknown.
- A declared SQL key uses its declared distinct values.
- A self-join's readout keyed by both sides' `job` returns up to 20 × 20.
…t values per scan, clamped to the rows read

As SQL optimizers estimate a GROUP BY's groups (the product of the key
columns' distinct counts, clamped to the input rows), but as an upper
bound from declared facts only:

- keys from different scans (a join, or a self-join's two sides) multiply;
- a SQL key bounds the values only through its declared distinct values,
  not through the groups of rows the table declares, which do not say
  which columns form them;
- PromQL labels keep their series bound;
- every readout's values are at most the rows its input reads per
  evaluation: each source's series times the samples its window holds at
  its sample interval, or the rows it holds.
…values per scan, clamped to the rows read

GROUP BY dst with 300 dst values declared returns up to 300 values, not
the 6 groups of rows the table declares; an undeclared key is bounded by
the rows read; keys of joined scans multiply. A PromQL result keeps its
series bound.
…r scan, clamped to the rows read

A grouped SQL result's n_q was the groups its keys declare, at most the
groups of rows the table declares: GROUP BY dst with 300 dst values over
a table of 6 groups of rows gave 6, so a whole-result target split delta
over 6 instead of 300. n_q now comes from the memo's bound on the root
group (Memo::max_values_per_evaluation), the rule R uses: the product,
per scan, of the keys' declared distinct values, clamped to the rows the
grouping reads. A PromQL instant vector keeps its series bound. The
IR-side copy of the group rule in bounds is deleted.
…r join adds a NULL, a LIMIT caps the rows

m{side="l"} * on(x) group_left(instance) m{side="r"}, grouped by job and
instance, pairs a left series' job with a right series' instance: up to
10 x 10 values, not the 10 pairs one series holds (also group_right and
an offset side). flows LEFT JOIN hosts grouped by h.region returns the 6
regions and a NULL group, so the declared 6 do not bound it (also FULL
JOIN and two keys). A grouping over LIMIT 10 returns at most 10 values.
… side's scans; an outer join's nullable side is computed

A group_left/group_right match pairs each output series with one series
of the other side, as a join pairs rows: the labels it copies from that
side now move past the output side's scan ordinals (after_left_scans,
as for a join), so job and instance of two series of one metric multiply
instead of sharing one label-set count.

The columns of an outer join's nullable side (Left: right, Right: left,
Full: both) gain a NULL their source may not hold, so their lineage is
computed by the join; a key from them is bounded by the rows read.

LIMIT n over the whole input keeps at most n rows.

column_properties now lints wildcard enum arms: every lineage and sign
rule lists each variant, so a new operator states its rule.
…ta the declared facts allow

Each review round found another shape where Memo::max_values_per_evaluation
(the readout values R and a query's n_q) fell below the values a query can
return. This test checks the bounds against data directly: each query of
a corpus is lowered as planning lowers it, its Stage 0 memo built, and the
query run by the executor over datasets that keep to the declared source
facts (series, distinct values per label and label set, sample interval,
rows held). Worst-case seekers make the labels the facts bound only
together independent, crossed or aligned across series and rows, replace
series between the times a query reads, and split series into blocks by
literal labels so matches pair them one to one; random datasets add
more. Every bounded group's result rows, and the query's, must be at most
its bound.

The default corpus is the reviewed probe shapes (85 queries, 9 s); an
ignored variant runs larger datasets over the dag-viewer workloads and a
manifest of workloads. Cases the executor or the frontend cannot run yet
are listed by name, so a case joins the check once it can run.
SELECT dst, approx_percentile_cont(bytes, 0.9) AS q FROM flows ... GROUP
BY dst ORDER BY q DESC LIMIT 5 returns at most 5 values; the memo gives
96, the rows the window holds. Fails before the fix with Some(96).
`SELECT dst, approx_percentile_cont(bytes, 0.9) AS q FROM flows ... GROUP
BY dst ORDER BY q DESC LIMIT 5` returns at most 5 values, but
Memo::max_values_per_evaluation read the keys through the Limit and gave
the 96 rows the window holds. The bound now also takes the rows the
group itself returns (max_rows_per_evaluation), which caps a whole-input
LIMIT by n, as it already does for a LIMIT below the grouping.
…name the kept identity checks

The Join arm computed the right side's columns after the left's scans
even for a semi or anti join, whose output keeps only the left side's
columns. The lint header now names each kept `if let`/`matches!` and why
every other variant's answer is "no", and says that arithmetic_sign's
tuple match ends in an unchecked `_ => Unknown`, the safe answer there.
…ew-valued keys first

The value-bounds oracle counted a case as run when any one of its bounds
ran, so bounds that compile only alone (the n_q of a scalar() or vector()
operand, a DISTINCT, a quantile over count_values) went unchecked
silently. It now tracks each bound as `case:what` with the most values
any dataset returned: EXECUTOR_GAPS lists the bounds the executor cannot
run with the operator each lacks, and NEVER_REACHED the bounds that run
but return nothing on every dataset (none now). Any other unrun or
always-empty bound fails the test.

p13_unless read `qot(0.9, m) unless qot(0.5, m)`, empty on every dataset;
it now reads `a unless b` over two metrics.

The crossed dataset gave the fastest digit to the label sorted first, so
`dst` (300 values) cycled while `src` stayed fixed over the 96 rows a
window reads. Declared components are now crossed smallest first: against
the earlier bounds code the oracle finds j_full's 42 groups over a bound
of 36, and j_left's 7 over 6, on the crossed dataset.
…up expects KMV at its planned 600M-row shape

The δ split offers stored KLL windows at several k, so the KLL test
compares the smallest k offered with the next larger one instead of
fixed values.

The distinct rollup test asserted exact counts. Measured, KMV is 1.26x
faster at 60,000 rows per state (the planned shape) and exact is 1.39x
faster at 12,000. The test is renamed for what it asserts and records
the crossover.
…istinct bound, as the edge check does

After the rebase onto main, theoretical_guarantee takes the read state's
value sign and its sources' distinct bound (DDSketch is certified over
values of one sign, classic HLL over a bounded source). build_meets_level
now takes the readout's state group and passes both, so dropping a
redundant readout level uses the same guarantee as the logical edge check.
The `or`/ratio readout test declares its values non-negative, so its
DDSketch builds are certified and the ratio keeps the composed grid.
@zzylol
zzylol force-pushed the fix/delta-split-over-dependent-readouts branch from 50cf197 to 793859e Compare November 16, 2026 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accuracy Accuracy requirements, guarantees, and propagation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant