Repository navigation
feat(pass2): coarse sketch groupings roll up from the finest build (sketch rollup, part 2) - #869
Merged
Merged
Conversation
zzylol
force-pushed
the
fix/sketch-rollup-planning
branch
2 times, most recently
from
October 22, 2026 12:17
06da69e to
12d7c4b
Compare
… the same sketch The rollup rule also offers sketch rollups: a coarse per-group sketch build read only by estimates with a guaranteed merged readout is answered by a rollup (SummaryMerge with group_by) of the finest build of the same algorithm over the same rows, sized for every reader. Every coarse grouping of one finest build is one choice. Guarantees compose through the rollup and Stage 3 prices its merge and output groups.
zzylol
force-pushed
the
fix/sketch-rollup-planning
branch
from
October 22, 2026 12:23
12d7c4b to
b994c0d
Compare
This was referenced Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #719. Part 2 of 2: planning. Part 1, the IR and executor, is #856 (merged).
Why
W-RollupHeavy (the paper's appendix E) asks the same sketch question under many groupings of one table and window:
(region, service, endpoint, status), at 5 and 15 minutes;CUBE(region, service, endpoint).The planner built one KMV or KLL summary per query, each over its own scan of the raw rows: 30 summaries and 30 scans for template 12. KMV and KLL states merge, so the finest grouping's states could answer every coarser grouping. #856 added the operator for that (a rollup:
SummaryMergewithgroup_by), but no planning rule used it.What
Pass 2: rollup rule for sketches. It now also offers a sketch rollup. A coarse per-group sketch build qualifies when:
The coarse build then becomes a rollup of the finest such build's states, by the coarse keys. This covers KMV, HLL, KLL, DDSketch, Count-Min, Count Sketch and UnivMon, for SQL
GROUP BYand PromQLby.One choice per finest build. Every coarse grouping of one finest build rolls up together. Template 12's 14 coarser groupings per window are 1 choice, not 2^14 subsets, so the 20-choice cap counts choices.
Sized for the strictest consumer. The finest build is resized for every reader, its own and each coarse one's, with the same per-parameter rule the summary-capability rule uses for a shared build.
Guarantee through a rollup. An estimate over a rollup gets the guarantee of the same read of the finest states, when the family's merged error for that read is exact or "as if built over the union":
The per-value failure probability is unchanged. A whole-result target is checked at the coarse group count, so it is no looser.
Stage 3 pricing. A rollup costs one merge per input state. It outputs the groups of its keys, using the same estimate as any
by (keys), so declared per-label distinct values (feat(plan-selection): price groupings from declared per-label distinct values #849) apply. A rollup to no keys is one row.How
rollup_candidates. It finds sketch candidates after the exact ones (sketch_rollup_candidates).finer_keyscompares families withsame_family: a sketch's algorithm at any size, exact accumulators by equality as before.RollupCandidatestays one type. For a sketch,fineris the finestSummaryAggandrollupis the regrouping merge of its states.rollup_choices. It groups the candidates: each exact rollup is a choice of its own, and all sketch rollups of one finest build share one choice.rollup_pass2_candidatesenumerates subsets of choices. For a chosen sketch choice,sketch_rollupsresizes the finest build (sized_for_all) and replaces each coarse build withSummaryMerge { [resized], group_by }. The merge keeps the coarse build's column names, so every reader above it is unchanged.rolled_up_guarantee(per_computation_candidates.rs): composes the read of a rollup as the read of its input states, gated on the family-capability table.SummaryMergearm caps output groups atgroups(by(keys)).at_most_one_rowtreats a rollup to no keys as one row.Key code interfaces added / modified
crates/logical-asap-optimization/src/asap_aware_cse.rsUsage (the test
stage3_selects_a_distinct_count_rollup_when_it_is_cheaperincrates/integration-tests/tests/sketch_rollup_planning.rs):Before this PR
W-RollupHeavy templates 12 and 13, each planned alone with
stage_pipeline --enforce-accuracy-guarantees. Both runs use the samemain(6dd2320b, before #867 and #868), apply the eval's local search shortcuts (ASAP_EVAL_CHEAPEST_OWN_CANDIDATE=1, needed because the default search doesn't finish on these workloads), and declare no label counts:After this PR
stage_pipelinetestscans_projecting_different_labels_are_shared): Stage 3 now selectsKll for Q4 rolled up from Q3, with Q3's KLL built once per evaluation for both queries. It costs 0.1458/s, against 0.1536/s for the previously selected plan. The test's expected selection is updated.Verification
main, whererollup_candidatesoffers no sketch candidate):asap_aware_cseunit tests:a_coarse_sketch_rolls_up_from_the_finer_build: Instant quantile by (host, job) next to windowed quantiles: no scan sharing, no panes, no ingest-time variant, 100-group default #840 Q3/Q4 shapes; one KLL at the largerk; the coarse query readsgroup_by: [1]; both guarantees are within the tighter target.coarse_groupings_of_one_finest_build_roll_up_togethersketch_rollup_needs_the_same_rowsa_global_quantile_rolls_up_to_no_keysthe_rollup_source_does_not_depend_on_query_ordercrates/integration-tests/tests/sketch_rollup_planning.rs:sketch_rollup.rschecks that executor answers equal the separate summaries (KMV, HLL, UnivMon, DDSketch) or are within the bound (KLL).cargo test -p asap-logical-asap-optimization --lib(171 passed, rebased on fix(executor): SQL plans over tables compile and run: table-scan compile check, now(), Int64 ids and COUNT(DISTINCT), exact percentile_cont #864);-p asap-integration-tests --test sketch_rollup_planning --test reuse_rules;-p asap-plan-selection --lib;-p asap-devtools: the committed viewer examples are unchanged; one expectation changes (see After);cargo clippy -D warningson the touched crates andcargo fmt --check.merges_groups;Limitations and follow-up