Repository navigation
Conversation
zzylol
marked this pull request as draft
November 16, 2026 01:52
zzylol
force-pushed
the
fix/delta-split-over-dependent-readouts
branch
from
November 16, 2026 04:46
34b5827 to
6c2d763
Compare
zzylol
changed the base branch from
fix/1307-relative-error-through-negation
to
main
November 16, 2026 04:47
zzylol
force-pushed
the
fix/delta-split-over-dependent-readouts
branch
from
November 16, 2026 14:03
94ee2a5 to
4f069ac
Compare
zzylol
force-pushed
the
fix/delta-split-over-dependent-readouts
branch
from
November 16, 2026 18:50
4f069ac to
5e17d57
Compare
zzylol
marked this pull request as ready for review
November 16, 2026 18:51
3 tasks
…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.
…outer join's nullable side is computed
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.
…ollup test by rows per state
…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
force-pushed
the
fix/delta-split-over-dependent-readouts
branch
from
November 16, 2026 23:48
50cf197 to
793859e
Compare
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.
Summary
max(values the scope covers, readout values per evaluation). A per-value target onquantile_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.min(R, V · fan_in). One function holds the rule,AccuracyTarget::failure_probability_per_readout_value. The readout walk inreadout_capscomputes both counts in the same pass.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.Rfrom 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 hasRunknown, so withn_qunknown too it gets no per-value δ, as on the base.Ris now a true upper bound across joins and for SQL keys. It is computed as SQL optimizers estimate aGROUP 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 boundsRonly through its declared distinct values; a measure key such asGROUP BY bytesis bounded only by the rows the query reads per evaluation (series_count× samples in the window, orrows_held), and is unknown without them.n_qnow follows the same rule asR. Stage 0 takes it fromMemo::max_values_per_evaluationof the root group. Before, a grouped SQL result was capped by the table'sseries_count, soGROUP BY dstwith 300dstvalues over 6 groups of rows gotn_q= 6 and a whole-result target split δ over 6 instead of 300. A join's keys now multiply inn_qtoo, and an undeclared key is bounded by the rows read. A PromQL instant vector is still at most its series read, and itsn_qalso 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 alabel_replaceof another label each go from 200 or 400 to the 10 declaredjobvalues. The tree-walking copy of the group rule inworkload::boundsis deleted.Randn_q, and this round adds a check that finds such shapes by construction instead of by review.group_left/group_rightmatch 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.flows LEFT JOIN hosts ... GROUP BY h.regionno longer gets 6.LIMIT nover the whole input caps the rows at n.crates/integration-tests/tests/memo_value_bounds.rsruns 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 at14330d53e, 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.column_propertiesnow list every variant (clippy'swildcard_enum_match_arm), so a new operator must state its lineage.LIMIT nabove 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 thej_fullunder-count too), andp13_unlessreads two metrics so its result is not always empty.mainwith the exact distinct-count cost refit. Two plan-choice tests now assert what measurement supports: the KLL test reads theks 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).main1760a69f5.query_levelskeeps this PR's split;main'sAccuracyTarget::failure_probability_per_output_valuestays for constraint (K)'s root rows, andmain'sMemo::max_distinct_per_evaluationsits next tokeys_of_values.build_meets_level, which drops redundant readout levels, now passes the state's value sign and distinct bound totheoretical_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. Theor/ratio readout test declares its values non-negative, so its DDSketch builds are certified.Review guide
mainat1760a69f5(round 8), which includes the exact distinct-count cost refit (fix(cost): charge an exact distinct count per value and pair lookup that misses the cache; declare the production workloads' column-wide distinct users #1368), Stage 3's constraint (K) (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), fix(stage3, accuracy): name the missed query when the second solve finds no plan; widen accuracy limits relatively only #1376 and refactor: tools and snapshots over the #1207 memo, edges and contexts (#1207 PR 9) #1239. The former base, the accuracy PR this one stacked on, was squash-merged intomain; this PR keeps only its own commits.AccuracyTarget::failure_probability_per_readout_valueandReadoutValueCountsin crates/types/src/accuracy/target/mod.rs (the method at L317, the struct at L348,larger/plusat L359/L370). This is the rule.readouts_read_by_queries(L414) andinputs_read_value_by_value(L545) in crates/accuracy/src/readout_caps/mod.rs. These compute the fan-in alongsideR.without_redundant_levels(L204) andbuilds_meeting(L238) in the same file, andbuild_meets_level(L171) in crates/accuracy/src/logical_edge/mod.rs, which the edge check now shares.inputs_read_value_by_value. A wrongSomethere would under-split δ.Memo::max_values_per_evaluation(L138),max_rows_per_evaluation(L192) andkeys_of_values(L288) in crates/types/src/stages/logical/memo/mod.rs, andSourceFacts::max_rows_in_window(L279) in crates/types/src/workload/data.rs. Round 4:values_per_result(L153) in crates/types/src/workload/bounds.rs and its caller incrates/stage0-memo/src/lib.rs.JoinandBinaryOparms ofnon_asap_columnsandafter_left_scansin crates/types/src/stages/logical/group/column_properties.rs (L198, L295, L342); theLimitarm ofmax_rows_per_evaluation(L233 in the memo file). Then the oracle, crates/integration-tests/tests/memo_value_bounds.rs: its generator (source_data,Dataset::rows) must keep to the declared facts, or it reports bugs that are not there.query_levelssignature, doc comments, and the concepts doc (docs/design_docs/concepts/accuracy-models.md).14ead6760adds the tests, and 7 of them fail on the base.7a89d15deis the fix. Round 1:c60fdd18cadds 5 tests (4 fail on7a89d15de),11976aa6ffixes them. Round 2:45e522ac6adds 4 tests (3 fail on11976aa6f),b72373488fixes them. Round 3:edc1b437dadds 3 tests and rewrites 1 (the 3 new ones fail onb72373488),000d41dc5fixes them. Round 4:ac615cfabadds 4 tests (the 3 SQL ones fail on000d41dc5; the PromQL one is a guard and passes on both),97aef2987fixes them. Round 5:e647f5dbdadds 3 tests (all fail on97aef2987),903ccc838fixes them,91364efa9adds the oracle,63f9997a2updates the concepts doc, and90b51f09eupdates a lineage test frommainthat encoded thegroup_rightbug. Round 6:41c4c2257adds theLIMIT-above-a-grouping test (fails on2d0b8ac78withSome(96);2d0b8ac78names the nullable join side),d1e7278f0fixes it,bfaecb296is theJoin-arm and lint-header nit, and2430c275bis the oracle polish. Round 7:5e17d5727updates two plan-choice tests for the new split (below), and the head commit restores the measured KLL pair and renames the rollup test.Round-1 fixes
(R_group, 1), ignoring its other candidates, so a reduction over readouts in the same group was under-split(R_group, 1)and its candidates' walked counts are combined field by field withReadoutValueCounts::larger(unknown when either is)a_readout_group_holding_a_reduction_splits_over_the_readout_values_below_it: δ / 1000, was δSummaryEstimateofTopKsetsper_output_value = per_evaluationa_topk_readout_splits_over_every_value_it_ranks: CMS-heap top-10 over 1,000 series per value → δ / 1000, was δwithout_redundant_levelsdrops 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)ReadoutValueCounts::largerand::plusreplace the two closuresreadout_value_counts_combine_count_by_counttakes_each_value_from_one_inputis evaluated once per candidateor: its fan-in is the larger input's, and it no longer makes the query composeda_concatenation_takes_each_value_from_one_readout: δ per value, single level, was the composed gridasap-types, as the reviewer allows, for the upper accuracy refactor's per-value δReadoutValuesRead→ReadoutValueCountsinputs_read_value_by_value's doc says both counts are per evaluation, not per subquery stepRound-2 fixes
n_qunknown, split δ overR=series_count(6), though the result has one value per bucket (about 16): KLL k = 547, whose guarantee at δ / 16 is over the targetMemo::max_values_per_evaluationbounds 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 givesNone. A readout over a state of unknown shape also givesNone. 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;Noneis the sound fallbacka_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(srcundeclared,n_qunknown: δ / 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)Ralone" replaced;Randmax_values_per_evaluationsay they bound only label-keyed readoutsreadout_capstests, not 11a_per_value_ratio_splits_over_the_two_readout_values_of_each_output_valuenow 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
max_values_per_evaluationsummedseries_countover the scanned sources, but a join multiplies them.flows JOIN hosts ... GROUP BY f.src, h.region, 6srcand 6regionvalues,n_qunknown:R= 6 + 6 = 12, KLL at δ / 12, though the result can hold 36 valuesscan_ordinal), and the per-scan bounds multiply. This also fixes the self-join case (a.src, b.srcover one table was 6, not 36).workload::bounds::group_count_boundis not reused: it works on operator trees with aDataWorkloadand 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)GROUP BY bytes) gotR=series_count, though nothing says which columns form a table's groups of rowsGROUP 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_labelor a label set); with any key undeclared the product is unknown and the rows alone boundR. The rows read are new:max_rows_per_evaluationwalks the memo below the readout (aTimeRangeover aScanholdsseries_count× (window /sample_interval+ 1) rows, at mostrows_held; aScanalonerows_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(nosample_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 withsrcundeclared; nowsrcdeclares 4: δ / 4)Ris an upper bound only for label-keyed readouts; the doc line the review flagged is wrappedRound-4 fixes
n_qunder-split (recorded as a follow-up in round 3):workload::bounds::values_per_resultcapped a grouped SQL result by the table'sseries_count.GROUP BY dst, with 300dstvalues declared over 6 groups of rows, gotn_q= 6. A whole-result target coversn_qvalues, 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_qunknown)n_quses the ruleRuses, 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 passesMemo::max_values_per_evaluationof the root group tovalues_per_result.keys_of_valuesnow 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 mostseries_read. An undeclared SQL key leaves only the rows read, or nothing.smaller_knownmoves toworkload::boundsandSourceFacts::max_rows_in_windowuses it. The IR-sidedeclared_group_boundanddeclared_distinct_combinationsinboundsare deleted, so the group rule exists oncea_result_grouped_by_a_declared_key_returns_up_to_its_declared_values(n_q300, δ / 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 withjobdeclared, 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 toAccuracyTarget::failure_probability_per_readout_valueasV=AccuracyScope::max_values_covered(n_q). What each consumer now gets:set_readout_requirements). A whole-result query gets δ / min(R,n_q· fan_in). Sincen_qandRnow come from the same rule,n_qis never below the readout values it covers for a grouped SQL result.GROUP BY dstgets δ / 300 instead of δ / 6.GroupsWithRecordShareAtLeastgets min(⌊1 / share⌋,n_q), which is unchanged unlessn_qwas the smaller term. A query whosen_qwas unknown and is now bounded (a join, an undeclared key over known rows) keeps the levelRalready gave it: min(R,n_q· fan_in) =Rthere.builds_meeting,without_redundant_levels). A stricter level keeps only builds that meet it, soGROUP BY dstnow keeps only KLL builds that meet rank 0.01 at δ / 300.edge_meets_logical_requirements,build_meets_level) checks a producer's θ against the same levels. Stage 3 only re-checks guarantees. Neither readsn_qdirectly.queries_without_per_value_failure_probability): a query whosen_qandRare both unknown still gets no level. No query newly enters or leaves this set in the survey.Round-5 fixes
group_left/group_rightbetween 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 pairsafter_left_scans, the rule a join's right side already uses.jobandinstancethen come from two scans and multiply: 10 × 10. A matched label keeps the output side's lineage (it is equal on both sides), andorstill keeps what both sides agree ona_many_to_one_match_within_one_metric_returns_up_to_the_product_of_both_sides_labels:group_left,group_right(job)andm … m offset 1h, each 100 (was 10);by (job, instance)overmalone stays 10.a_same_source_group_right_takes_the_right_sides_labels(frommain) now expectsteamat scan 1flows 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 NULLf, so the full join acts as a left join: 36 + 6)ColumnLineagerequires for equal lineage. Its keys then fall back to the rows read. Thematchlists everyJoinKinda_key_from_the_nullable_side_of_an_outer_join_is_bounded_by_the_rows_read: Left and Full, byh.regionand byf.src, h.region, each 678, the rows bound (was 6 or 36); the inner join stays 36series_countbound in round 3, which was not sound for a SQL keymax_rows_per_evaluationpassed aLimit's input rows throughLIMIT nwith no partition keeps at most n rows. A partitioned limit (topk by) keeps its input's bounda_grouping_over_a_limit_returns_at_most_its_rows: 10 (was 96)max_values_per_evaluationis re-wrappedn_qalso tightens through key lineage, with the examples the review listedcolumn_propertiesnow lintswildcard_enum_match_armasnode.rsandtime_window.rsdo. #1330's lint covered only those modules andcost::node::usage, not this one. The operator arms were already exhaustive. The three wildcards it found (project_lineageand the sign rulesexpression_signandmeasure_sign) now list every variant with the same answers.keys_of_valueskeeps its_ => None, which bounds nothingmemo_value_bounds_hold_on_data_the_declared_facts_allowRound 7: rebase onto
mainand two plan-choice testsRebased onto
main79d99326e. Two integration tests asserted plans that the new δ split changes. Both now assert what measurement supports.default_cost_plan_ranking::quantile_rank_without_raw_data_charges_the_larger_kll_moreks Stage 1 offers from the memo. Asserts the selected plan keeps the smallest offeredk, that k = 1,404 is charged over 1.25x more than k = 547 (the measured pair, 1.6-2.5x), and that the next largerkthan the smallest is charged morerollup_controlled::production_distinct_rollup_counts_exactlyCOUNT(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 queriesproduction_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 fromseries_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:
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.
production_rollup_workloads::production_sql_distinct_region_service_counts_exactlynow passes withmain's refit and picks exact counts.Round-6 polish
n_qofp11_scalar_pv,p12_vector_or,d_distinct,p_cv_by,p_cv_key,p_subq_outer,p_labelrep_qot_whole;d_distinct'sDedup,p11'sProject)case:whatwith the most values any dataset returned.EXECUTOR_GAPSnow lists each unrun bound (63) with the operator it lacks; any other bound that never runs fails the testmemo_value_bounds_hold_on_data_the_declared_facts_allowp13_unless(qot(0.9, m) unless qot(0.5, m)) is empty on every dataset, so itsn_qwas never testedp13_unlessreadsa unless bover two metrics. A bound whose largest count is 0 fails unless listed inNEVER_REACHED(empty)p13_unlessit fails namingp13_unless:n_qdst(300 values) cycled whilesrcstayed fixed over the 96 rows a window reads, and joins were never filled14330d53e's bounds code the oracle now also findsj_full36 → 42 on the crossed dataset (12 violations, as the review showed); 0 at this headkeys_of_valuespasses through aLimitabove a grouping, so… GROUP BY dst ORDER BY q DESC LIMIT 5gotn_q= 96max_values_per_evaluationalso takes the rows the group itself returns (max_rows_per_evaluation), which caps a whole-inputLIMITby n, as L2 does below a groupinga_limit_over_a_grouping_returns_at_most_n_values: 5 (was 96)Joinarm ranafter_left_scansfor semi and anti joins and threw the result awaymatches!/if let, and did not say tuple matches go uncheckedarithmetic_sign's_ => Unknownis unchecked, whereUnknownis the safe answerdatasetsdoc comment says four worst-case datasetsMemo value bound oracle
crates/integration-tests/tests/memo_value_bounds.rs, with its corpus inmemo_value_bounds_fixtures/cases.json. It checks soundness against data, so it does not rely on a reviewer thinking of the shape:ASAP_MEMO_VALUE_BOUNDS_WORKLOADS.Memo::max_values_per_evaluation, theRof a readout over that group, and the query'sn_qcomes from Stage 0'smemo_of_queries.SourceFacts: at mostseries_countseries (or groups of rows), each label within itsdistinct_values_per_labelcount, each label set within itsdistinct_values_per_label_setcount, one sample persample_interval, and at mostrows_heldrows.offset.xinon(x)are unique within a block, so a match pairs series one to one across blocks.case:what). The executor cannot run 63 of the 244 bounds yet: all of 17 cases (date_trunc,CAST,upper,label_replace, a subquery,rateover histogram buckets, aUNION ALLbelow a grouping,row_number()as a key), and some bounds of 8 more (DISTINCT, ascalar()orvector()operand, a quantile overcount_values). The frontend does not lower 2 cases.EXECUTOR_GAPSlists each unrun bound with the operator it lacks, andNEVER_REACHEDeach 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:
14330d53e(round-4 head)p_gl_same10 → 63,p_gr_same10 → 59,p_gl_same_offset10 → 59 (the "replaced" dataset),j_left6 → 7,j_full36 → 42 (the "crossed" dataset, since round 6), for bothRandn_q3e61530a5(round 3 fixed, before the round-4n_qfix)n_q, and S1 and S2c_dstn_q6 → 80,g_two6 → 88,r_dst_interval_small6 → 12a46b0ed9e(before the round-3 fix of J1 and V1)n_q, S1 and S2j_self6 → 22,j_self_cross6 → 93,j_two12 → 17,j_three12 → 18. V1:r_bytes_interval6 → 90,c_value_col6 → 90N1 (
date_trunc) is not shown: the executor cannot rundate_truncyet. The round-1 commits are not shown either: before round 2,max_values_per_evaluationmeant 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 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_runsuite'skll_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:
maxover 1,000 series, any scopesum by (job), 1,000 series in 10 jobs, per valuesum by (job), 10 jobs, whole resultq or r, 100 series each side, per valueq or r, whole result of 100 valuesmax by (job) (q or r), 3 series per sidesumover 1,000 per-series readouts, per valuemax(sum by (job) (q)), 1,000 seriesseries_countunknown, no reductionn_qunknown,R= 100This 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_evaluationalso takes the rows the group itself returns (doc comment updated with theLIMIT 5example).Round 5 changes no signature.
ColumnLineage::Computednow also covers a column of an outer join's nullable side (doc comment updated), andMemo::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::memoMemo::max_values_per_evaluationkeeps 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_evaluationnow also clamps to the rows read and multiplies keys across scans (doc comment updated); new crate-private helpers areMemo::max_rows_per_evaluation,SourceFacts::max_rows_in_windowandsmaller_known, andKeysOfValuesnow 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 returnsNonefor a readout or state keyed by a computed or time key (doc comment updated), and its private helperdeclared_groups_of_stateis replaced bykeys_of_values.crates/types/src/accuracy/target/mod.rs, re-exported fromcrates/types/src/accuracy/mod.rsimpl 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 incrates/stage1-pass2-reuse-candidates/src/readout_requirements.rspasses 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_coveredis 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-accuracyare private:query_levelstakes aReadoutValueCountsinstead ofOption<u64>,ReadoutsReadByQueries::readout_valuesholds one per query, andinputs_read_value_by_value,without_redundant_levels,builds_meetingandbuild_meets_levelare new private functions.Usage (end to end, as the test
a_per_value_target_without_a_reduction_keeps_the_whole_failure_probabilityruns it):Design scope
ReadoutValueCounts(struct,asap-typesaccuracy::target)AccuracyScope, and the IR layer can use it because it imports nothing fromstages.AccuracyTarget::failure_probability_per_readout_value(method)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)without_redundant_levels,builds_meeting(private functions,asap-accuracyreadout_caps)build_meets_level(private function,asap-accuracylogical_edge)KeysOfValues(private enum) andMemo::keys_of_values(private method),asap-typesstages::logical::memomax_values_per_evaluation, its one caller, and replaces the formerdeclared_groups_of_state.Memo::max_rows_per_evaluation(private method),asap-typesstages::logical::memoGROUP BYestimate, and the memo-side counterpart ofworkload::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-typesworkload::dataseries_count,sample_intervalandrows_held: a fact about the source, so it sits onSourceFacts.smaller_known(crate-private function),asap-typesworkload::bounds(moved there in round 4)SourceFacts::max_rows_in_windowandvalues_per_resultuse it.inputs_read_value_by_value(private function,asap-accuracyreadout_caps)takes_each_value_from_one_input, which the same walk uses, and every operator it does not list falls back to the conservativeR.Round 5 adds no production type. New test files:
crates/integration-tests/tests/memo_value_bounds.rsMemo::max_values_per_evaluationandn_qfor 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 itcrates/integration-tests/tests/memo_value_bounds_fixtures/cases.jsonflows,hosts)No new production files.
Algorithm changes
Failure-probability split per readout value (Pass 2 readout requirements)
max(V, R), so a statement over few output values, each reading one readout, still split δ over all ofR. Examples: 8 series per value gave δ / 8; a bareq or rper value gave δ / 200.readouts_read_by_queriessumsRper query.query_levelscomputesδ / max(max_values_covered(n_q)?, R?).ReadoutValueCountsper group.(max_values_per_evaluation, 1), or(R, R)for a top-k readout, combined withlargerwith its other candidates' counts (a reduction over readouts below it).per_evaluationsums the inputs that read with error, as before.per_output_valuedepends on the operator. For one thatinputs_read_value_by_valuelists, it is the sum of the inputs'per_output_value, or their largest fororand a concatenation; an input referenced only from a scalar expression contributes its wholeper_evaluation. For any other operator, such as an aggregate, a window function, a time range or alimit, it equalsper_evaluation.failure_probability_per_readout_valuereturnsδ / min(R, V · fan_in), where an unknown term drops out and both unknown meansNone.Voutput values, and each depends on at mostfan_inreadout values. So it fails only if one of at mostV · fan_inreadout values fails, and never more than theRthat are read. The union bound over that set holds under any dependence.fan_inis 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 newreadout_capstests, plusfailure_probability_splits_over_the_readout_values_coveredfor the rule.O(groups + candidates · inputs), with a secondOption<u64>per group. Level pruning isO(L² · P)per readout group, withLits levels andPits 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).Ris 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 agroup_left/group_rightmatch, 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 theGROUP BYestimate 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.Decisions and open questions
Needs reviewer decision
Fan-in under
sum by (job): pending your decision onmax_series_per_label_value. The reviewer recommends deferring it: no surveyed plan needs it, and the fallback toRis safe; add it when a workload with per-value targets on grouped reductions shows a plan change. The reviewer's shape, if added:distinct_values_per_label_setover{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, whichSourceFactsdoes not do.SourceFacts, with the same "upper bound the deployment must ensure" contract asdistinct_values_per_label: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_labelis documented as an upper bound on how many jobs exist. It does not bound how many series one job holds: with 1,000 series andjob: 10, one job may hold 991 of them. Usingseries_count / distinct= 100 would let a 991-series job fail with up to 9.91 δ.R. That is the conservative fallback the rule allows, soa_grouped_sum_per_value_splits_over_every_readout_value_when_group_sizes_are_unboundpins 1,000.max_series_per_label_value: {"job": 100}inSourceFacts(data workload scope). A groupedAggregatewould then takemin(R, that bound)as its fan-in.failure_probability_per_readout_valuealready handles it: the rule's own test checks(per_value, R = 1000, fan_in = 100) → 100.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_levelsthen 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
mininstead 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 unknownn_qsplits overR. This is sound only becauseRis 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).Rmust 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 aGROUP BY. A key with no declared count bounds nothing by itself; with the rows unknown too,Ris unknown. Rejected: documenting that a SQLseries_countmust bound every non-time key combination (the second option in the review), which would put a new obligation on every SQL data workload.j_leftprobe that is 1.3e13 (3.6 million rows on each side), so the KLL level is δ / 1.3e13. Onmainthe readout was pruned and read exactly. The tighter alternative, one more value per key scan reached through a nullable side (7 forj_left), needs a nullability mark onColumnLineage::SourceColumn. It is not done: no surveyed workload has an outer join.Verification
Round 8 (head
793859e2donmain1760a69f5; 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-testsand-p asap-stage3-plan-selection --lib, run onmaintoo and compared by name):asap-costmain: 83)asap-accuracymain: 46)asap-typeslib / testsmain: 179 / 80)asap-stage0-memo, Pass 1, Pass 2main)asap-stage3-plan-selectionlibmain: 30)main: 196, 6, 4). The same 6 tests fail onmainby name (listed under round 7).memo_value_bounds, bothrollup_controlledtests and the KLL ranking test passcargo fmt --all --check;cargo clippy --release --all-targets -- -D warningson the eight cratesRound 7 (head
5e17d5727onmain79d99326e; local release build,cargo test --release --no-fail-fast -p asap-cost -p asap-stage3-plan-selection -p asap-integration-tests, run onmaintoo and compared by name):asap-costmain: 83, 0)asap-stage3-plan-selectionlibmain: 18, 0)main: 192, 6, 4). The 6 failures are the same tests by name as onmain: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_accumulatorproduction_sql_distinct_region_service_counts_exactly, the oraclecargo fmt --all --check;cargo clippy --releaseon the six changed crates--all-targets -- -D warningsRound 6 (head
94ee2a503onmain863153e3c; local debug build, the same six-cratecargo test --no-fail-fastas round 5, compared by name withmain):78289c000(0ba0cf89b)n_q=Some(96)instead ofSome(5)main: 554, 7, 4). The 7 failures are the same tests by name as onmain; the extra pass is the round-6 test14330d53e's bounds codep_gl_same,p_gr_same,p_gl_same_offset) and S2 (j_left, and nowj_full36 → 42), each forRandn_qp13_unlessp13_unless:n_qnever reachedcargo fmt --all -- --check;cargo clippyon the six crates--all-targets -- -D warnings78289c000→ head (remote, release)n_q, 209 workloadsn_qchanges only for the five globaltopk(k, …)workloads (c03,c12,c17,p05: 1000 → 5;p28: 1000 → 3), theLIMIT-above-a-grouping shapen_q, the review's 46 probesl_limit_overchanges:n_q96 → 5. Its readouts' levels are unchanged (none on either side)Round 5 (head
78289c000onmain863153e3c; 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 onmaintoo and compared by name):14330d53e(3de89b150)group_leftquery getsn_q=Some(10)instead ofSome(100), the left joinSome(6)instead ofSome(678), the grouping overLIMIT 10Some(96)instead ofSome(10)main: 554, 7, 4). The 7 failures are the same tests by name as onmain. The extra passes are the 3 round-5 tests and the oracle; the extra ignored test is the oracle's large variant14330d53e's bounds code (this head's tests, with the round-5 fix reverted incrates/types/src)p_gl_same,p_gr_same,p_gl_same_offset) and S2 (j_left), each forRandn_q3e61530a5anda46b0ed9en_qbug, and J1 and V1 (table above)cargo fmt --all -- --check;cargo clippyon the six crates--all-targets -- -D warnings14330d53e→78289c000(remote, samemain)n_q, 209 workloadsn_qand no level changed: no surveyed workload has a many-to-one match within one metric, an outer join, or a grouping over aLIMITn_q, the review's 46 probesp_gl_same,p_gr_same,p_gl_same_offset:n_qandR10 → 100, DDSketch δ 1e-3 → 1e-4.j_left: 6 → 1.3e13 (the rows bound: 3.6 millionflowsrows times 3.6 millionhostsrows), KLL δ / 6 → δ / 1.3e13.j_full: 36 → 1.3e13, KLL δ / 36 → δ / 1.3e13.l_limit_under: 96 → 10, KLL δ / 96 → δ / 10Round 4 (head
14330d53eonmain863153e3c; 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-3main863153e3crun):6c2d763bc(3e61530a5)GROUP BY dstgetsn_q=Some(6)instead ofSome(300).GROUP BY bytes, sampled, getsNoneinstead ofSome(96). The join getsNoneinstead ofSome(36). The PromQL guard passesmain(joint_search_equivalence×2,materialized_views,plan_sharing×2,promql_to_post_asap×2).asap-stage0-memo: 9 of 9 passcargo fmt --all -- --check;cargo clippy --releaseon the six crates above--all-targets -- -D warnings6c2d763bc→14330d53e(remote, samemain)n_q(209 workloads + 30 probes),6c2d763bc→14330d53eGROUP BY dstprobe, δ / 6 → δ / 300. 15 queries changedn_q, all SQL; no PromQLn_qchanged. In the 209 workloads onlyn09_sql_topk_windowchanged (unknown → 3,600,000, therows_held, from its top-k's rows read), and it gained no level. In the probes,GROUP BY dstwent 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 rawts,value, time buckets) went unknown → 3,600,000 (theirrows_held). Those levels did not change: each already split over the sameRRound 3 (head
6c2d763bconmain863153e3c; 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 withmain863153e3c):89bf188fe(a46b0ed9e)GROUP BY bytesgets(live, δ / 6)instead of no level; the self-join memo test getsSome(20)instead ofSome(400). The rewritten declared-srctest passes (it guards the declared-key case)main(joint_search_equivalence×2,materialized_views,plan_sharing×2,promql_to_post_asap×2); no test that passes onmainfails 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 warningsmainnow lints wildcard arms in two modules;max_rows_per_evaluationlists every operator anyway)89bf188fe(round-2 head on the samemain) →6c2d763bc34b5827e2→6c2d763bcGROUP BY bytesδ / 6 → δ / 3.6e6 (the probe declaresrows_held3,600,000 and nosample_interval, so the rows held boundR); the time-bucket,CASE, cast, subquery-alias andupperkey probes no level → δ / 3.6e6, for the same reason;n09_sql_topk_windowandx14_sql_global_from_groupedreadouts without a target (an exact requirement) switch between "exact level" and "pruned for unknown values" with no plan change.Rchanged without a level change in 11 more: SQL top-k and distinct-count readouts lose the groups-of-rows bound (R1000 → unknown,n_qstill sets their level),GROUP BY dst(300 declared) getsR= 300 instead of 6, and a PromQLlabel_replacekey getsR= 100 from the rows of its instant vector instead of unknown. The levels of89bf188feon the samemainequal those of34b5827e2Round 2 (same command and crates, head
34b5827e2, compared by name with the basebc48168dcrun of round 1):d5f171d96(4ec3a316b)(live, Some(0.00167))instead of(pruned, None); the memo test getsSome(1000)instead ofNoneforby [date_trunc]. Thesrctest passes (it guards the label-keyed case)d5f171d96are the round-2 testscargo 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 warningsd5f171d96→34b5827e2Rchanged 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, basebc48168dcand headd5f171d96, compared by name):b1be9955e(cd15dc540)readout_capstests 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 passesjoint_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 testscargo 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 warningsInitial version (all runs
cargo nextest, remotely, onb1be9955eand on the basebc48168dc, compared by test name):cargo nextest run -p asap-accuracy -E 'test(readout_caps)'on the test commit only (a577c752e)0.00125 != 0.01,0.00005 != 0.01,0.00125 != 0.0025, loosest ratio level1e-4(expected1e-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 knowncargo nextest run -p asap-types -p asap-accuracy -p asap-stage1-pass2-reuse-candidates -p asap-stage1-pass1-per-computation-candidatescargo nextest run -p asap-integration-tests -p asap-devtools -p asap-planner --no-fail-fasttodo!("#1207 PR 9")paths)cargo fmt --all -- --check;cargo clippy -p asap-accuracy -p asap-types --all-targetsNew tests (in
readout_caps/tests.rs, plus one intarget/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_unboundanda_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 existingan_or_takes_each_value_from_one_readoutnow 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 undermax.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 headd5f171d96)Each workload was planned with
run_default_search_overand the executor's summary families, asplan_installabledoes. The RollupHeavy entries use the corrected manifest lines withrollup_tables.json(the paper manifest's RollupHeavy line has no tables file and fails with "table flows not found").FinalizeExactAccumulatorlifetimes flipNone↔OneEvaluation(Memory)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
flowsCOUNT DISTINCT KMV chain went from k = 106,263 to k = 26,656. The reason the body gave was wrong:flows5%-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.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/Projectnodes flipped betweenNoneandOneEvaluation(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)
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
flowschain. 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
httpandflowsrows: 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.flowsqueries)Follow-ups
max_series_per_label_value, pending your decision (reviewer: defer).failure_probability_per_readout_valueonfailure_probability_per_output_valueand makesquery_levelscall it alone. (K)'s root rows stay 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").asap_runsuite'skll_sized_by_closed_form_without_measured_table(k = 1404) should pass once its stack includes this change. It was not run here because that branch is on a different base.With #1238
#1238 (#1207 PR 8) adds
AccuracyTarget::failure_probability_per_output_value(n_q)= δ / V, the δ of one output value. It returnsNonewithout a δ, or when a whole-result δ has an unknownn_q. (K)'s root rows read it. #1238 keeps itsreadout_caps::query_levelschange 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:
failure_probability_per_readout_value(n_q, counts)= δ / min(R, V · fan_in) = max(δ / R,failure_probability_per_output_value(n_q)/ fan_in). An unknown term drops out, and the result is 1 without a δ.query_levelsthen callsfailure_probability_per_readout_valuealone, which replaces 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'sminline.