Repository navigation
fix(stage3): retention and resident windows as shares of their largest need (#1533) - #1537
Merged
Merged
Conversation
Two selection tests over the chain retaining 300 s for its 1 m and 5 m readers: - every continuous variable of its selection model is within [0, 1], the retention h_v included, and the optimum still retains 300 s at 4.3 per second; - under a window cache keeping 6 and 30 windows at 2 per window, the resident-windows variable is within [0, 1] with the term 2 * 30, and the optimum (64 per second) is what plan_cost charges. Both fail on main: h_v is in seconds and r_v in windows, both unbounded.
…t need The selection MILP held h_v (seconds retained) and r_v (resident windows) as unbounded continuous columns with whole-number row coefficients (60 to 86,400 seconds; window counts). HiGHS's presolve takes such columns for integers, and its root reduced-cost fixing then steps through up to 1,024 values per column at every root LP solve, in time quadratic in the steps. On a dag-viewer random-mixed workload, 149 h_v columns took about 80 % of a 12 s solve. #1355's measured unit costs kept more executions, so more h_v columns (33 to 302 on the same workload) and the solve went from 0.9 s to 7.5 s. h_v is now RetentionShare: a share in [0, 1] of the longest need of its (R) rows, which read longest_need_s * share, so the rows keep their tolerance in seconds. The retention term, the raw-data rows and the answer horizon take the longest need as a factor. r_v is likewise a share of the most windows any kept read keeps. The feasible plans and the optimum are unchanged; plan_cost is unchanged.
…are; doc the share scaling - cost_per_retained_second for pi_v in selection_cost_terms, so "share" means only the [0, 1] variable; cost coefficients in quantity_expression and the resident-window caller named for what they hold. - Module table and the SelectionVariables::h doc describe h_v and r_v as held over a share; cost-terms-from-calibration.md notes the scaling. - retention_is_a_share_of_the_longest_need checks the h_v share and its 300 s longest need instead of every continuous column.
zzylol
added a commit
that referenced
this pull request
Nov 27, 2026
…two stale snapshots (#1429) #1537 changed two sketch plans at the committed cost, so their snapshots on main passed without being rewritten: chains-10m-5m-3m-10s now sizes its KLL chains with k = 2863 (was 1404), and sql-rollup-quantile-same-window keeps one more node's result. With plan_id and view_state_key removed, every regenerated snapshot equals the one main writes itself. The pinned 5-minute chain key follows (k = 2863).
zzylol
added a commit
that referenced
this pull request
Nov 27, 2026
…id (#1429) (#1536) * test(types): failing tests for the view state key and plan id (#1429) Phase 2 of #1429, tests first. A materialized view's stored state is named by ViewStateKey { definition_id, window, logical_properties }, taken from the view node alone, and an installed plan by its content id, PhysicalASAPDAG::plan_id. The tests check that: - views differing only in θ or in the view node's window width get different keys; - views differing only in refresh mode, retention or storage medium get one key and different plan ids; - merges of one range over 1-minute and 5-minute chains share a key; - the three planned views of one coverage in the chains-10m-5m-3m-10s workload get distinct keys; - a view planned in two workloads keeps its key; - the key is pinned and round-trips through JSON; - the plan id round-trips through a plan file, changes only with the plan, and is pinned for a committed plan file; - a store keyed by (view state key, time range) answers the five tumbling windows, and a k = 400 query misses k = 200 states. Two known limitations are ignored tests: #1493 (a finalized exact aggregate has no coverage) and #1494 (coverage depends on where a filter sits). plan_id, MaterializedView::plan_id and MaterializedView::view_state_key are todo!() stubs. LogicalProperties gains PartialEq, Eq, Hash and serde, and SketchParams gains Eq and Hash, so the key can key a hash map. * feat(types): name a materialized view by its view state key and plan id (#1429) A deployment filed stored view states by the view's coverage (definition_id and selection), which leaves out θ and the view's tumbling-window width: the three views of the planned chains-10m-5m-3m-10s workload (a 5-minute chain, a 10-second chain and 60-second windows merged from it) share one coverage. - PhysicalASAPDAG::plan_id: the content id of the plan's DAG (128-bit FNV-1a of its JSON, the hash definition_id already uses, moved to plan::content_id). With node_id it names a view in one installed plan. - MaterializedView::view_state_key: ViewStateKey { definition_id, window, logical_properties }, from the view node alone. A store keys states by it and the concrete selection, across plans. - MaterializedView::plan_id; MaterializedView::coverage and ViewCoverage::definition_id/selection are public. - asap-types turns on serde_json's float_roundtrip, so a plan file read back has the plan id it was written with. - Docs: physical-planning-and-deployment.md section 4 explains the two scopes and the layering; the DataStore doc, the primitive-schema proposal and the DAG viewer README follow. * fix(types): a TimeRange, TimeShift or TimeRangeCover view keeps its chain's windows in its key (#1429) Review fixes: - ViewWindow::of_node walks a TimeRange or TimeShift down to the chain it selects windows from, and gives a TimeRangeCover its levels' widths (ViewWindow::TumblingLevels): TimeRange(5m, Chain[1m]) and TimeRange(5m, Chain[5m]) hold 5 rows and 1 row and no longer share a key. - ViewStateKey::of_view builds the key next to its type. - The two-workload test matches views by operator before comparing keys. - Docs: plan-id equality is equality of serializations; the five-window example names the views it means; the store contract names the key. * test(planner-cli): regenerate snapshots with each view's plan_id and view_state_key (#1429) 22 snapshots with materialized views gain plan_id and view_state_key per view. Nothing else changes: every plan, cost and coverage is as before. 43 of the 54 views share their coverage with another view of their plan; all 54 have distinct keys. * docs: MaterializedView's fields and methods in the plan-file block (#1429) * test(types): a finalized counter rate has the view coverage of the rate (#1429) #1535 gave a finalized exact state its aggregate's coverage, so the #1493 known-limitation test is no longer ignored and now asserts full equality of the two view coverages. The design doc keeps #1494 as the one known limitation. * refactor(types): view state key review fixes (#1429) - ViewStateKey::of_view takes the view's coverage and the DAG's node map instead of a lookup closure; Candidate::new builds its logical properties with LogicalProperties::of_parameters. - A TimeRangeCover level that is no chain is a planner bug (debug_assert) rather than a silent loss of the window; a test keys a cover view's levels' widths. - The #1493 test duplicated #1535's a_finalized_rate_covers_what_the_rate_covers: removed, and that test now also asserts equal view coverages. - The integration tests share one view_over_chain helper. - Docs: concrete selection throughout; the key relies on chains serving only readers on their grid; the test table names the θ test. * test(planner-cli): pin the view state key at main's plan; regenerate two stale snapshots (#1429) #1537 changed two sketch plans at the committed cost, so their snapshots on main passed without being rewritten: chains-10m-5m-3m-10s now sizes its KLL chains with k = 2863 (was 1404), and sql-rollup-quantile-same-window keeps one more node's result. With plan_id and view_state_key removed, every regenerated snapshot equals the one main writes itself. The pinned 5-minute chain key follows (k = 2863).
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
Closes #1533.
HighsRedcostFixing::addRootRedcost) then steps through up to 1,024 values of each one at every root LP solve, in time quadratic in the steps. Onrandom-mixed-seed-862-long/workload-01, 149 such columns made that bookkeeping 81 % of a 12 s root-node solve. fix(cost): charge each operation the executor's measured time, so a sketch plan is no longer predicted cheaper than a faster exact plan #1355's measured unit costs kept more executions, so there were moreRetentionShare: a share inlong-01from 14.7 s to 2.5 s. r197 goes from 79.6 s to 53.9 s, and paper from 439.6 s to 196.9 s. Plan cost is equal in 742 of 747 runs (workload × seed). The 5 that differ are paper runs within HiGHS's optimality tolerance, at most 2e-7 relative, and are accepted as solver ties; see Decisions.Review guide
main(daaa2a207). Not stacked.crates/stage3-plan-selection/src/milp/retention.rs. It holdsRetentionShare,retention_variables(computesretention_constraints(rows overh.seconds()) andresident_window_terms(the share of the most windows).selection_cost_terms(milp/model/mod.rs), and the answer horizon inmilp/kept_results.rs.hinSelectionVariablesandKeptResultVariables.main. The second commit is the fix. The third applies review fixes: names (cost_per_retained_secondforcost-terms-from-calibration.md), and the first test now checks theBehavior: before → after
main(daaa2a207)The selected plan is the same. Only the MILP's formulation of two maxima changes: the user waits less for the same plan. This serves the dag-viewer and evaluation workloads, whose planning time #1533 tracks.
Interfaces
All of these are crate-internal (
pub(crate)/pub(super)). No public interface changes.crates/stage3-plan-selection/src/milp/retention.rscrates/stage3-plan-selection/src/milp/model/mod.rs,crates/stage3-plan-selection/src/milp/kept_results.rspub(super) struct SelectionVariables { pub(super) x: Vec<Variable>, pub(super) y: BTreeMap<usize, Variable>, pub(super) z: BTreeMap<(QueryId, usize), Variable>, t: Vec<Option<Variable>>, - /// $h_v$ in seconds retained. - pub(super) h: BTreeMap<PhysicalCandidateId, Variable>, + /// $h_v$ as a share of its longest need. + pub(super) h: BTreeMap<PhysicalCandidateId, RetentionShare>, raw_data_on_disk: BTreeMap<Source, Variable>, read_by_query: BTreeMap<(QueryId, usize), Variable>, } pub(crate) struct KeptResultVariables<'a> { pub(crate) x: &'a [Variable], pub(crate) z: &'a BTreeMap<(QueryId, usize), Variable>, - pub(crate) h: &'a BTreeMap<PhysicalCandidateId, Variable>, + pub(crate) h: &'a BTreeMap<PhysicalCandidateId, RetentionShare>, }Usage (end to end, the chain from
retention_is_a_share_of_the_longest_need):Algorithm changes
MILP formulation of the retention and resident-window maxima
long-01, HiGHS spent 81 % of its 12 s at the root node inaddRootRedcost(perf). That coversstd::_Rb_tree_increment(55 %) under the erase loop offindLurkingBounds, which runs for every implied-integer column with a nonzero reduced cost and a domain wider than 1, at every root LP resolve.retention_variables).resident_window_terms).lowest_mean_latency::a8then found a plan 1 byte over a disk limit. The tests:retention_is_a_share_of_the_longest_need(every continuous variable of the selection model is inresident_windows_are_a_share_of_the_most_any_read_keeps(the term is 2 × 30, the bound isplan_costcharges);objective_scale. On the paper workload with differing plans the scale is unchanged (same objective coefficients in the dumped MILP).Decisions and open questions
Plan-cost ties on paper (5 of 747 runs) are accepted as solver-tolerance ties; no tie-break on
plan_costand no tighter MIP tolerance. Every difference is at most 2e-7 relative, within HiGHS's optimality tolerance, which cuts off improvements under about 1e-6 of the objective. The 5 runs:main→ PRmain→ PRpaperwhole_rollupheavypaperwhole_rollupheavy-8userspaperwhole_rollupheavy-8userspaperwhole_rangeheavy-8usersplan_costtells them apart.mainitself returns the dearer of those plans onpaperwhole_rollupheavywith seed 1.This PR closes [Bug] Stage 3 solve on the dag-viewer random-mixed workloads ~8x slower since #1355 (measured unit costs) #1533. viewer34 is 99.2 s against about 85 s (2 × 42.6 s). The same-host
facaec8b2sum is 48.7 s, which is wall time because its planner panics after Stage 3, so the PR is 2.0× of it.long-01is 2.48 s againstfacaec8b2's 1.73 s, within 2×. The remaining viewer34 gap over the 11-14 baseline is the expected cost of the larger model (more executions kept by the measured unit costs), not a solver trap, and is not tracked further.The rows stay in seconds and windows ($H_v$ seconds, and
h.seconds() >= need * read), not over the bare share. The bare-share rows were just as fast, but they turned HiGHS's absolute tolerance into 1e-6 oflowest_mean_latency::a8caught a plan 1 byte over a disk limit.largest_retention_ms(which adds the newest-output floor), would change the measured MILP for no solver gain, so neither is done here.Verification
cargo fmt --all -- --checkcargo clippy -p asap-stage3-plan-selection --all-targets -D warningscargo test -p asap-stage3-plan-selectionmain(term 2 instead of 60;h_vbound(0, inf))cargo test -p asap-planner-cli(includes goldens)cargo test -p asap-integration-testslowest_mean_latency::a8caught the share-only rows (see Algorithm changes)random_seed0/1/2seconds()helper and doc edits, which build the same MILPmain→ PR (median of 3 seeds, summed)No wall-clock test is added (the repo ignores them). The guard is structural: both new tests fail if either maximum is unbounded again.
Follow-ups
findLurkingBoundsis quadratic in its steps. That is an upstream solver cost, worth reporting there.