Repository navigation
refactor(stage3): baseline selection MILP and its PhysicalASAPDAG; executor θ, native chains and a time-indexed store (#1207 PR 6) - #1236
Draft
zzylol wants to merge 1 commit into
Conversation
zzylol
force-pushed
the
refactor/1207-stage2
branch
from
November 9, 2026 07:43
d11f12e to
616f765
Compare
…ive tumbling-window chains and a time-indexed store in the executor (#1207 PR 6) Stage 3 costs each physical candidate (w_v) and each selectable edge (c_{u,c,i}) with asap-cost, solves the baseline MILP over x, y, z, t (constraints (A)-(F), (E) only inside strongly connected components, a query-time result that is not materialized read by at most one consumer), and builds the PhysicalASAPDAG of the optimum directly, each node with its timing, lifetime, θ, retention and, materialized, its summary coverage. asap-cost sizes summaries from the node's θ and prices chains and raw data by the node's retention_ms. The executor builds and runs summaries with θ, runs tumbling-window chains natively (TimeRange/TimeShift over a chain select windows), keeps materialized rows in a time-indexed store with retention, and evaluates TimeShift{at} once per request. Installation no longer expands chains.
zzylol
force-pushed
the
refactor/1207-stage3-baseline
branch
from
November 9, 2026 09:01
09d69f1 to
7d1bd55
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.
Stacked on #1235 (base
refactor/1207-stage2). Part of #1207 (PR 6 of the restack plan). One commit,7d1bd5590.Why
After PR 5, Stage 3's$x, y, z, t$ and builds the
select_plan, the executor's θ and chain handling, the plan's retention and the installer were alltodo!(): no workload could be planned or installed. This PR is the baseline of the formulation (concepts doc §3 "Stage 3: baseline selection and plan output", "Plan output", "Executing the plan"): Stage 3 selects with the MILP overPhysicalASAPDAGitself; the executor runs what the planner may choose (θ from the node, native chains, a time-indexed store).What
asap-stage3-plan-selection):asap-cost; MILP (A)–(F) with (G)/(H) by allocatingSelection { accepted_accuracy_per_query, pruned_candidates, milp_* }.PhysicalASAPDAGNode::parameters(missing θ for a sketch is an error everywhere); chains,TimeRangeover a chain, query-time scans and raw data materialized at ingestion priced from the node'sretention_ms(plan_cost(dag, entries, data, settings).TimeRange/TimeShiftover a chain select windows by window end); one time-indexed append-only store with retention (InMemoryDataStore);TimeShift { at: End | Start | T }above aTimeRangeevaluates its child at the request's end/start/T, once per run;ScanWindowdeleted.materialized_view.rstodos filled for native chains; aScanthat keeps raw data (query time, or materialized at ingestion) is raw-data retention, not a view; chain expansion andset_retentiondeleted;plan_installableinstallsPlanOutput::planwith itsplan_costreport.price, peak-memory warning,avgfrom sum and count).How
select_plan: selectable edges = admissible ∧ the producerdelivers_onthe evaluation context of every query reaching a query-time consumer (gridevaluation_grid_ms, phase 0; unknown times = a 1 ms grid).cost::selection_costs: each candidate becomes one node (candidate_node, shared with plan building). Groups are visited inMemo::topological_order; each candidate is costed withasap_cost::node_usageover its input groups' logical outputs (per group, the most rows/bytes any costed candidate outputs, the θ of the largest state). That isretention_need_ms(most offset + range over its consumers'TimeShift/TimeRangepaths, + range-evaluation span; a chain reads back its width).milp::model::solve_selection: HiGHS, gap 0, one thread, coefficients scaled to max 1,000.plan::plan_of: Kahn order over selected edges,PhysicalASAPDAG::newderives the edges;retention_ms= most need over the selected consumers (and the span of a query it answers).Key code interfaces added / modified
Permalinks at
7d1bd5590.types/src/ir/physical_export.rstypes/src/ir/properties/execution_data_state.rstypes/src/stages/physical/memo_candidates.rstypes/src/ir/materialized_view.rscost/src/usage.rs,cost/src/state_bytes.rsexecutor(I6)planner/src/installable.rsWire version stays 14 (the stack's; nodes gain
summary_coverage, build/merge operators an optionalparameters).Usage (planner test
runtime_install::the_plan_carries_stage3s_predicted_usage, passing):Major algorithm changes
Baseline selection. Problem:$w$ +$c$, the one-consumer rule (infeasible without a
select_planwastodo!(). After: steps in How. Correctness: (A)–(F) as the doc;milp::model::testscheck the cheaper producer byOneEvaluationcandidate) and (E) on a two-group cycle (Ga = m offset 1s,Gb = m offset 2s, each from the other). Complexity: onenode_usageper candidate plus one per selectable edge; MILP size |C| + |E_sel| + Σ|G_q| variables. Limits: see spec questions S1–S4.Native chains / time-indexed store. Before: the installer expanded a chain into N
SummaryAggwindows. After: an ingestion run over (start, end] builds one window state (window_end = end); the store appends it and drops rows older thanretention_ms; a query reads the windows withwindow_end ∈ (T − o − r, T − o](w | r and w | o checked). Testexecutor/tests/tumbling_window_chain.rs: 24 refreshes of a 10-min exact-sum chain, queries throughTimeRange(1h)andTimeShift(1h)→TimeRange(1h)equal direct sums; a read past 2 h retention fails.Executor gaps (handoff watch-outs) and where they are covered
Operator::evaluate_at)validate_ingestion_time_summary)Deleted
PhysicalASAPDAG::set_retentionretention_msExpandedWithRetention,reader_span_ms_by_node,PredictedNodeUsage::{stage3_node_id, installed_node_ids})ScanWindow,union,scan_windows,view_windowstumbling_window_retention_ms(_of_plan),retained_tumbling_windows,tumbling_windows_ofInMemoryDataStore::with_materialized_view,RawDataWindow::lookback_ms,test_support::lookback_msappend_materialized_view/ retention checksprice(.., last_root_is_key_filter)parametercoverage_of(todo)node.summary_coveragePending approval (new pub items not in the doc)
PhysicalASAPDAG::new(nodes, roots, scalar_roots) -> Result<Self, PhysicalASAPDAGValidationError>— edges derived from payloads (the edge fields staypub(crate)). Example: nodes[0 Scan, 1 TimeRange{child: 0}], roots[1]→ one edge0→1with the scan's schema and data state. Also used by the test export.DataPrimitive::of(operator, result_kind)— shared by Stage 3 and the test export. Example:SummaryMerge(result State) →SummaryState;Project→Raw.PhysicalASAPMemoCandidates::edge(id) -> &PhysicalEdge(review D8).plan_cost(dag, entries, data, settings)signature (four callers built the same vectors).Operator::evaluate_at,PhysicalOperator::input_context,InMemoryDataStore::append_materialized_view,InstallablePlanError::PlanCostFailed, test-supportViewCoverage::new,set_build_parameters(signatures above). Exampleappend_materialized_view(&view, (0, 600_000), vec![state])stores the window ending at 600 000.is_raw_data_scan(crate-private) semantics: aScanmaterialized at ingestion keeps raw data withretention_msand is reported byraw_data_retention, not as a view (it has no coverage).Spec questions (code kept independent where possible)
OneEvaluation, so two chains over oneScan (IT, None)would be infeasible; the baseline applies the rule to query-time producers only. Confirm, and say what PR 7 should do per pipeline context.retention_msto cost and install chains and raw data, so PR 6 sets it post-solve as the largest need over the selected consumers (and costscost::retention_need_ms) for (R) and@ Tstays unbounded (None).fixed_intervalwithout a phase has no known grid, so no chain or stored result delivers on it; tests that expect sharing switched tofixed_interval_at { phase 0 }(joint_search, planner install tests). The issue-fixture JSONs ([Bug] A nested shorter window of an exact sum does not reuse the newest panes of the longer window's chain #924/[Bug] The same query at a longer repeat interval recomputes instead of reusing the shorter-interval result #925 sharing regressions) were not changed and still fail on this.@-anchored subtree keep the anchor time (not restamped to each step).Before this PR
Planning stopped at
select_plan(todo!()); executor summaries panicked without θ; chains could not be run or installed.After this PR
Every workload whose queries have known evaluation grids plans end to end to one
PhysicalASAPDAG, installs, and runs on the executor with native chains.Verification
cargo testper crate (--all-features --no-fail-fast),cargo fmt --check,cargo clippy --workspace --all-features --all-targets -D warningsclean,crate_graphpasses.By test name vs PR 5: 0 newly failing, 129 newly passing, 1 removed (
values::weighted_state_tests::weighted_state_family_and_shape_must_match, replaced by state-kind checks).Still failing (none at a PR 6 todo):
summary_sharing×2 (plan-shape pins: an exact plan or a chain is chosen where the test expectsSummaryAggstates; PR 9 M9);check_compiles_reports_the_executors_error(exact Reduce TopK, executor gap 12 → feat(executor): grouped stddev/variance, corr, group, count_values, exact topk and without grouping #1242).Self-review: no shims;
candidate_nodeshared by costing and plan building; oneretention_need_msfor costing and the plan; cost helpers used only inside asap-cost made private. Not done:RejectionCausekeeps variants of the deleted engine (onlyInfeasibleis produced; the viewer contract lists them — delete with the viewer in PR 9);ErrorSelectingPlan::Costis unused for the same reason.