Repository navigation
refactor(stage1): top-k reuse and finer-aggregate reads as one operator over groups (#1203 2a-3) - #1220
Closed
zzylol wants to merge 2 commits into
Closed
refactor(stage1): top-k reuse and finer-aggregate reads as one operator over groups (#1203 2a-3)#1220zzylol wants to merge 2 commits into
zzylol wants to merge 2 commits into
Conversation
zzylol
force-pushed
the
refactor/1203-2a-2-summary-results-inputs
branch
from
November 5, 2026 15:44
b3c7b5a to
ef701a7
Compare
zzylol
added a commit
that referenced
this pull request
Nov 5, 2026
…s candidates when found `exact_input_group` replaced the candidates of the group `find_or_add_group` returned, also when it found an existing group. Now the exact candidates replace the own candidate only of a group it added; a found group keeps its candidates and gets the new ones through `push_candidate_if_new`. Top-k and finer-aggregate reads follow #1218's interface changes (`MemoGroupId` owner, `find_or_add_producer` without budget parts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1M6br9PL4SDeVS1XpezKJ
zzylol
force-pushed
the
refactor/1203-2a-3-topk-finer-aggregate
branch
from
November 5, 2026 16:01
c4f1267 to
9fbfc54
Compare
zzylol
force-pushed
the
refactor/1203-2a-2-summary-results-inputs
branch
from
November 5, 2026 17:08
ef701a7 to
f27b38f
Compare
zzylol
added a commit
that referenced
this pull request
Nov 5, 2026
…s candidates when found `exact_input_group` replaced the candidates of the group `find_or_add_group` returned, also when it found an existing group. Now the exact candidates replace the own candidate only of a group it added; a found group keeps its candidates and gets the new ones through `push_candidate_if_new`. Top-k and finer-aggregate reads follow #1218's interface changes (`MemoGroupId` owner, `find_or_add_producer` without budget parts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1M6br9PL4SDeVS1XpezKJ
zzylol
force-pushed
the
refactor/1203-2a-3-topk-finer-aggregate
branch
from
November 5, 2026 17:23
9fbfc54 to
7e3d360
Compare
zzylol
added a commit
that referenced
this pull request
Nov 5, 2026
…s candidates when found `exact_input_group` replaced the candidates of the group `find_or_add_group` returned, also when it found an existing group. Now the exact candidates replace the own candidate only of a group it added; a found group keeps its candidates and gets the new ones through `push_candidate_if_new`. Top-k and finer-aggregate reads follow #1218's interface changes (`MemoGroupId` owner, `find_or_add_producer` without budget parts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1M6br9PL4SDeVS1XpezKJ
zzylol
force-pushed
the
refactor/1203-2a-3-topk-finer-aggregate
branch
from
November 5, 2026 20:19
7e3d360 to
e8f39e8
Compare
zzylol
force-pushed
the
refactor/1203-2a-2-summary-results-inputs
branch
from
November 5, 2026 21:13
b8402c7 to
45c8d37
Compare
zzylol
added a commit
that referenced
this pull request
Nov 5, 2026
…s candidates when found `exact_input_group` replaced the candidates of the group `find_or_add_group` returned, also when it found an existing group. Now the exact candidates replace the own candidate only of a group it added; a found group keeps its candidates and gets the new ones through `push_candidate_if_new`. Top-k and finer-aggregate reads follow #1218's interface changes (`MemoGroupId` owner, `find_or_add_producer` without budget parts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1M6br9PL4SDeVS1XpezKJ
zzylol
force-pushed
the
refactor/1203-2a-3-topk-finer-aggregate
branch
from
November 5, 2026 21:13
e8f39e8 to
c418afa
Compare
…or over groups Rules 4 (top-k reuse) and 5 (finer aggregate) add their reader copies through `add_candidate_over_groups`, so the `Limit` of a top-k read and the compensating `Filter` of a finer-aggregate read are groups. Top-k's sort and ranking producers are found or added with Stage 0's equality (`find_or_add_producer`); its exact-only input groups through `Memo::find_or_add_group`, their exact guarantee keeping them apart from the group they copy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1M6br9PL4SDeVS1XpezKJ
…s candidates when found `exact_input_group` replaced the candidates of the group `find_or_add_group` returned, also when it found an existing group. Now the exact candidates replace the own candidate only of a group it added; a found group keeps its candidates and gets the new ones through `push_candidate_if_new`. Top-k and finer-aggregate reads follow #1218's interface changes (`MemoGroupId` owner, `find_or_add_producer` without budget parts). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K1M6br9PL4SDeVS1XpezKJ
zzylol
force-pushed
the
refactor/1203-2a-2-summary-results-inputs
branch
from
November 5, 2026 21:24
45c8d37 to
80bec5a
Compare
zzylol
force-pushed
the
refactor/1203-2a-3-topk-finer-aggregate
branch
from
November 5, 2026 21:24
c418afa to
a81ad4e
Compare
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #1218; part of #1203, tracked in #1207 (PR 2a-3).
Merge unit. This PR merges into main only together with the rest of #1207's merge unit (steps 1a–6, #1207 "Order"): interim items below are deleted by a later PR in the unit.
Why
#1203 decided one operator per candidate, every intermediate result its own memo group. #1218 switched rules 3 and 8 and added the shared
add_candidate_over_groups. This PR switches rules 4 (top-k reuse) and 5 (finer aggregate), which still added two-operator chains.What
topk): each top-k consumer copy is one operator over groups:Projectover aLimit(k)group over the shared ranking group. The sharedSortandLimit(k_max)ranking producers are found or added with Stage 0's equality (find_or_add_producer) instead ofappend_producer's origin-and-parts reuse. The exact-only copies of input groups (exact_input_group) are found or added withfind_or_add_group; their exact guarantee is what keeps them apart from the group they copy.finer_aggregate): a finer-aggregate read with a compensating filter isAggregateover aFiltergroup over the finer group; without a filter it was already one operator.New abstractions not in #1207 or the doc: decisions (2026-11-05)
Per #1207's interface policy, these names are not defined by #1207, #1203 or section 3 of
memo-groups-properties-requirements.md. #1207's steps 1a–6 merge into main as one merge unit (#1207, Order), so an interim abstraction may stay in this PR only when a later PR of the unit deletes it; none reaches main. Rows marked Pending approval are not deleted by any PR in the unit and need the user's decision.exact_input_group's group)How
Both rules call
reuse::add_candidate_over_groups(#1218) where they calledappend_reader, and top-k callsreuse::find_or_add_producerwhere it calledappend_producer. No new functions.Representation / rules / enumeration
find_or_add_group. Their matching is unchanged: top-k already checked exactness through groups (exact_input_grouprecurses into input groups), and the finer-aggregate rule matches groups' logical nodes.Key code interfaces added / modified
None.
topk.rsandfiner_aggregate.rschange only which crate-internal functions they call.Usage. Neither rule fires on the KLL example;
asap_planner --workload kll.json --run-until stage1_pass2 --format text(and the scan-widening workload) print byte-identical output before and after this PR. Two workloads where they fire,asap_planner --run-until stage1_pass2 --format text, Pass 2 output, before (#1218) vs after:Top-k:
topk by (job) (3, sum_over_time(data[1m]))andtopk by (job) (5, sum_over_time(data[1m])), exact, every 10 s (datafrom thetopk-ratesnapshot workload):(A partitioned
Limitover aLimitis not legal to share when equal (NonASAPOp::is_shareable_when_equal), so each consumer'sLimitis its own group.)Finer aggregate (SQL, table
metrics(ts, city, host, value)):SELECT city, host, SUM(value) FROM metrics WHERE ts > now() - INTERVAL '5' MINUTE GROUP BY city, hostandSELECT SUM(value) FROM metrics WHERE ts > now() - INTERVAL '5' MINUTE AND city = 'NYC', exact:Major algorithm changes
None.
Before this PR
Rules 4 and 5 added consumer chains through
append_readerand producer groups throughappend_producer(reused only by origin and budget parts).After this PR
Rules 4 and 5 add one operator over groups, with groups found by Stage 0's equality.
Deleted
topk.rs: itsappend_producer/append_readercalls and their?error paths (finding a group cannot fail).finer_aggregate.rs: itsappend_readercall.append_readerandappend_producerstay: rollup (6, 7) still uses them (deleted in the rollup PR).Plan cost, Stage 2 candidates and planning time
UPDATE_SNAPSHOTS=1left every snapshot file unchanged. Stage 2 physical candidates and--run-until stage3wall time per snapshot input, #1218 vs this PR, release builds on one host:Second review fixes (
7e3d360)exact_input_groupno longer overwrites a found group.find_or_add_groupmay return an existing group. The exact candidates now replace the own candidate only of a group it added. A found group keeps its candidates and gets the new ones throughMemo::add_candidate. No test or example reaches the found case: a temporary panic there did not fire in any test below. So plans are unchanged.add_candidate_over_groupstakes aMemoGroupIdowner, andfind_or_add_producerhas no budget-parts argument.dafb6f4alone uses refactor(stage1): summary readouts and inputs as one operator over groups; Memo::add_candidate; one node equality in Pass 1 (#1203 2a-2) #1218's old signatures, so it compiles only with7e3d360.Notation (formulation → code)
MemoGroup, idMemoGroupIdadd_candidate_over_groups,Memo::add_candidate(doc)exact_input_groupConcepts not in the formulation
exact_input_group): a group whose candidates are only the exact implementations of another group, kept apart by its exact guarantee. In the formulation it would be the original group withfind_or_add_producer), accuracy budget parts: see refactor(stage1): summary readouts and inputs as one operator over groups; Memo::add_candidate; one node equality in Pass 1 (#1203 2a-2) #1218 / refactor(stage1): Pass 1 adds a memo group for every intermediate result (#1203 PR 2a-1) #1215.Second review verification (
7e3d360)cargo test -p asap-types --lib: 146 passed.cargo test -p asap-logical-asap-optimization --lib: 198 passed.cargo test -p asap-integration-tests --test integration -- memo_enumeration reuse_rules operator_sharing sharing_issue_regressions finer_aggregate_reuse planner_layering_example having_shared_aggregate stage1_logical_asap_optimization joint_search_equivalence sketch_rollup rollup_controlled production_rollup_workloads: 154 passed, 23 ignored (pre-existing).cargo test -p asap-devtools --lib: 18 passed.--test devtools -- asap_planner:: asap_planner_acceptance:: memo_pricing::: 56 passed, 1 ignored.UPDATE_SNAPSHOTS=1 cargo test --release -p asap-devtools --test corpus_snapshots -- --include-ignored: 9 passed, no file changed.--run-until stage1_pass2 --format text: byte-identical toc4f1267.asap_planner --run-until stage1_pass2 --format text: byte-identical to the pre-review headc4f1267on 35 workloads besides the two examples: the reviewer's 20 workloads, six rollup / scan-widening /avgworkloads, five earlier finer-aggregate, rollup, top-k and scan-KLL examples, andrandom-mixed-seed-862workloads 01–04.cargo fmt --all;cargo clippy --workspace --all-targets -- -D warnings: clean.Restack on #1218 (
b8402c7)Rebased on #1218's interface alignment: the doc's
Memo::add_candidatereplacespush_candidate_if_new(same equality; returns the candidate'sCandidateForMemoGroupId), and #1218's CI fix ofsketch_rollup::quantiles_rolled_up_keep_the_sketch_bound. Plans unchanged.cargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warnings: clean.cargo test -p asap-logical-asap-optimization --lib: 198 passed.cargo test -p asap-integration-tests --test integration -- memo_enumeration reuse_rules operator_sharing sharing_issue_regressions finer_aggregate_reuse planner_layering_example having_shared_aggregate stage1_logical_asap_optimization joint_search_equivalence sketch_rollup rollup_controlled production_rollup_workloads topk: 161 passed, 23 ignored (pre-existing).Restack (2026-11-05)
On #1215's consumer naming (
build_of→build_of) and #1218's one node equality in Pass 1.cargo fmt --all -- --check;cargo clippy --workspace --all-targets -- -D warnings: clean;cargo test -p asap-logical-asap-optimization --lib: 197 passed.Viewer
Viewer tests not updated for the group shape (#1203 decision 6);
viewer_contractpasses.Verification
cargo test -p asap-logical-asap-optimization --lib: 198 passed.cargo test -p asap-physical-asap-optimization: 29 passed.cargo test -p asap-plan-selection --lib: 142 passed.cargo test -p asap-devtools --lib: 18 passed.cargo test -p asap-integration-tests --test integration -- memo_enumeration reuse_rules operator_sharing sharing_issue_regressions finer_aggregate_reuse planner_layering_example having_shared_aggregate stage1_logical_asap_optimization joint_search_equivalence sketch_rollup rollup_controlled production_rollup_workloads: 154 passed, 23 ignored (pre-existing).cargo test -p asap-devtools --test devtools -- asap_planner:: asap_planner_acceptance:: memo_pricing:: viewer_contract::: 58 passed, 1 ignored.UPDATE_SNAPSHOTS=1 cargo test --release -p asap-devtools --test corpus_snapshots -- --include-ignored: 9 passed, no file changed.cargo fmt --all;cargo clippy --workspace --all-targets -- -D warnings: clean.--run-until stage1_pass2 --format text: byte-identical to refactor(stage1): summary readouts and inputs as one operator over groups; Memo::add_candidate; one node equality in Pass 1 (#1203 2a-2) #1218's head.Left for 2a-4..k
Rollups (6, 7), scan widening (2), tumbling windows (1), state configurations (9) and step 10, then the deletions listed in #1215 and #1218.