Skip to content

feat: start memo-first planning and candidate-connection MILP migration - #933

Merged
zzylol merged 12 commits into
mainfrom
feat/joint-candidate-connections
Oct 24, 2026
Merged

zzylol merged 12 commits into
mainfrom
feat/joint-candidate-connections

Conversation

@zzylol

@zzylol zzylol commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem and resulting behavior

Memo planning currently constructs logical group identity after Pass 1 and depends on orchestration/helpers housed under legacy search. This draft begins the implementation of the memo/candidate design discussed in #776: memo routes establish identity before Pass 1, populate those same groups after capability pruning, and continue through the existing Pass 2 rules and selection. The full legacy-removal migration is not complete.

Before this PR

P95/P99 workload roots first become a PerComputationCandidates inventory, then the selection layer interns groups. The MILP obtains its independent-query incumbent by calling legacy planning. Source-component analysis, diagnostic remapping, and public stage orchestration also live under search/legacy.

After this PR

  • LogicalMemo lives in the logical optimization crate and interns roots before Pass 1 on memo routes, including component workloads. Candidate population preserves group IDs and original-node references. Existing from-Pass-1 callers remain supported.
  • Pass 1 population and candidate metadata now live in logical optimization. Consumer-independent local rules are generated once per group/measure; HAVING, nullable checks, fusion, and absorption retain occurrence-specific handling. Shared-summary Pass 2 expansion also moves to logical optimization with compatibility reexports.
  • Shared orchestration, source dependencies, query-index remapping, and pane reuse move outside legacy. Public stage entry points keep their existing names.
  • The MILP baseline tries at most 16 local memo assignments and three materialization policies per query, validating candidates through Stage 3. It no longer calls legacy or materializes the complete group-choice product. It is a feasible baseline, not a guarantee of the per-query optimum or a strict wall-clock budget.
  • An internal fixed-context candidate-connection MILP core supports multiple selected candidates in one group, explicit producer requirements/connections, root coverage, activation, reverse support, acyclicity, and pay-once candidate costs. A separate tiny-graph enumerator checks optimal costs. The core is not yet a production search mode or an adapter for current demand-dependent pricing.
  • Opt-in concrete state-group expansion and a restricted memo-to-connection inventory now connect real P95/P99 candidates to the new solver. The integration test selects one KLL using synthetic fixed costs, reconstructs typed producer connections, and passes Stage 2 physical-DAG validation. It does not enable the solver as the production path.
  • Additive resource budgets charge each selected candidate once. Unsupported coefficient ranges are rejected before solving; a regression demonstrated the numeric issue before the fix.
  • Root-dependency matching uses node identity instead of recursive DAG equality, avoiding shared-diamond expansion and false mismatch on NaN scalar literals. Cost-range validation and decoded graph validation guard the new solver core.

Key code interfaces added / modified

  • Logical layer: LogicalMemo, MemoGroup, MemoGroupId, group_for_node, matches_root_dependencies, CandidateMemo, try_populate_pass1, generate_per_computation_candidates_with_memo, memo::shared_builds.
  • Stage bridge: populate_pass1, memo_from_initial, search_with_initial_memo, brute_force_with_initial_memo.
  • Shared orchestration: search::pipeline, source_connected_queries, remap_rejection_query_indices.
  • Baseline: group_choices_up_to, incumbent::feasible_plan.
  • State/connection bridge: expand_concrete_summary_state_groups, build_candidate_inventory, reconstruct_candidate_outputs, ResourceBudget.
  • Selection core: CandidateDependencyGraph, local PhysicalCandidate, ProducerRequirement, ProducerConsumerConnection, QueryRootAssignment, select_candidates.

Major algorithm changes

  1. Logical interning precedes Pass 1 for memo routes while preserving existing candidate generation and physical legality.
  2. Incumbent generation is bounded by attempted logical assignments/materialization policies rather than exhaustive independent-query optimization.
  3. The new isolated MILP selects candidate nodes and compatible connections jointly, using topological ranks and reverse support; it does not enforce one candidate per group.

Validation

  • Complete logical-optimization tests: 196 unit tests and 35 integration tests passed, including moved population/sharing tests, repeated-group caching, and consumer-specific HAVING/fusion equivalence.

  • Complete plan-selection unit suite after candidate ownership migration: 225 passed, zero failures. Includes all nine candidate-connection solver tests and the bounded-enumeration regression.

  • Zero-time-budget MILP incumbent integration regression passed with the bounded memo baseline.

  • Three-way integration subset after memo-aware generation: four passed, four intentionally ignored long-running randomized cases.

  • Strict clippy for both affected crates (--lib --tests -- -D warnings), workspace format check, and diff check passed.

  • Latest targeted validation: 3 state-group tests, 29 candidate-related tests, and 3 inventory tests including Stage 2 physicalization passed. Final strict clippy and workspace formatting checks passed.

Remaining migration work — draft, not ready for final replacement

  • Generate Pass 1 rules directly into memo groups rather than adapt the existing inventory.
  • Generalize concrete state contracts and integrate production physical-candidate/connection generation; the current bridge rejects unsupported constraints explicitly.
  • Integrate candidate-keyed physical decoding, partial sharing, rate/retention costs, and all configured feasibility/objective models.
  • Replace remaining legacy cost-model/exhaustive routing and default selection, remove old search machinery and options, and complete end-to-end benchmarks.

The implementation plan is included in docs/design_docs/proposals/joint-planning-implementation-plan.md. Moving helpers and adding the core must not be mistaken for completing legacy deletion. No runtime sketch/window algorithm is added by this draft.

@zzylol zzylol changed the title Start memo-first planning and candidate-connection MILP migration feat: start memo-first planning and candidate-connection MILP migration Oct 24, 2026
@zzylol
zzylol marked this pull request as ready for review October 24, 2026 03:05
@zzylol
zzylol merged commit 5697d05 into main Oct 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant