Skip to content

Memo search solver: MILP over the memo for all cost models #888

Open

Description

@zzylol

Problem, by example

The memo-group search (#879) needs a solver: given the memo (groups, implementation candidates, local prices, coupling sites), pick one implementation per group and one value per coupling site at minimum cost.

Take three quantile queries over one metric that may share a DDSketch build: Qa with relative error 0.01, Qb with 0.02, Qc with 0.05. They run under two cost models:

  • Cost model 1 (usage over time, additive). The cost of a choice is a sum of local prices. Threshold enumeration on the shared build's size (sized for 0.01, 0.02, 0.05, or not shared), then dynamic programming over the other groups, finds the optimum. It is fast and predictable.
  • Cost model 3 (cluster capacity, say 256 GB of memory). Two groups whose cheapest choices use 200 GB each are each feasible alone and infeasible together. The DP must keep a Pareto frontier over cost, peak memory, cores, disk and worst latency per group, and check the capacity when frontiers combine. That is hand-written multi-dimensional bookkeeping. A capacity limit is a single linear constraint in a mixed-integer linear program (MILP).

Why it matters

The two solvers trade off differently, and the memo they read is the same:

DP + threshold enumeration + branch and bound MILP over the same memo
Exactness exact; checked against --exhaustive exact within solver tolerance, with an optimality gap
Speed fast and predictable with few shared groups; branch and bound can slow down on large sharing clusters fast on small models, less predictable on large ones; a time limit returns the incumbent and its gap
Global coupling (cost model 2 peaks, cost model 3 capacity) needs per-group Pareto frontiers natural: linear constraints
Cost shape calls Stage 3's pricing directly, any shape must be linear; sizes become threshold indicators; products such as latency × rate are precomputed into coefficients
Dependencies none a solver, e.g. good_lp with HiGHS
Debugging every pruning decision can be logged the solver is opaque; inspect the model
Relation to the evaluation new search same formulation family as the sketch-bench RQE optimizer the evaluation compares against

MILP sketch over the memo:

x[g,i] in {0,1}   group g uses implementation i
s[k,t] in {0,1}   coupling site k takes threshold t (shared size, pane grid, raw horizon, scan labels)
r[g,k] in {0,1}   group g reads shared site k

min  sum cost[g,i] x[g,i] + sum sitecost[k,t] s[k,t] + read costs
s.t. each group: exactly one implementation
     an implementation's child groups are implemented
     r[g,k] <= sum over thresholds t no stricter than g's requirement of s[k,t]
     raw horizon: indicator constraints for the longest raw-reading reader
     cost model 2: peak terms; cost model 3: capacity <= limit
     latency per evaluation <= max_latency_ms and <= repeat interval (path sums)

Proposal

Decided on 2026-10-22:

  1. Phase 1 (cost model 1): DP + threshold enumeration + branch and bound, as in the joint-planning-search design. It is additive, predictable and dependency-free, and it is what the memo workers are building.
  2. Cost models 2 and 3: a MILP solver over the same memo, replacing the hand-written Pareto frontiers. This comes after the memo switch-over.
  3. A cross-check mode: solve cost model 1 with both solvers and assert equal optimal cost on the equivalence workloads. This is an extra correctness oracle for the DP.

The memo generation (groups, implementations, local prices, coupling sites) is shared by both solvers.

Scope and acceptance

  • In scope: a MILP model builder from the memo; a good_lp/HiGHS backend behind a feature; solver selection by cost model; the cross-check mode.
  • Out of scope: approximate solving. A time limit that ends with a nonzero gap is reported as such, never as optimal.
  • Acceptance:
    • cost models 2 and 3 select the same plan as --exhaustive on small workloads, including a peak case and a capacity case;
    • the cross-check passes on every joint_search_equivalence workload;
    • planning time for the paper workloads under cost models 2 and 3 is reported.

Status and related work

Activity

  1. added
    cost-modelCost formulas, statistics, ranking, and selection
    enhancementNew feature or request
    optimizerWorkload optimization and plan selection
    searchCandidate-plan search space and algorithms
    on Oct 22, 2026
  2. zzylol commented on Oct 22, 2026

    @zzylol
    ContributorAuthor

    Decision update (2026-10-22): the memo search uses a MILP for all cost models, cost model 1 included. The hand-written branch and bound with dynamic programming is dropped.

    Why:

    • The memo is small: on the whole paper workloads, 74 groups and 284 candidates (W-RangeHeavy) and 158 and 584 (W-RollupHeavy), each built in under 0.3 s.
    • Cost model 1 is not additive per node: memory held while a query runs is bytes × that query's latency, and how often a node runs depends on the materialization choices above it. Bounds for a hand-written search are therefore hard to make tight.
    • In a MILP, these become standard exact linearizations: product variables for memory × latency, reach indicators for execution multipliers, threshold indicators for sizes, raw horizon and pane grids. Peaks and capacity (cost models 2 and 3) are linear constraints.

    Plan:

    1. The memo stays as built.
    2. A model builder takes its coefficients from Stage 3's per-node pricing (good_lp with HiGHS).
    3. The selected plan is re-priced by Stage 3, and the solver objective must match.
    4. A three-way cross-check: MILP vs brute force over the memo vs --exhaustive, under all three cost models.
    5. The MILP becomes the default search once it is exact. The legacy search stays reachable by a setting.

    This follows the standard exact approach to multi-query optimization over an AND-OR DAG (the memo). Greedy heuristics such as those of Roy et al. (SIGMOD 2000) give up optimality, and our sharing sizes depend on the strictest reader, which breaks their assumptions.

  3. changed the title [-]Memo search solvers: DP for cost model 1, MILP for cost models 2 and 3, with a cross-check[/-] [+]Memo search solver: MILP over the memo for all cost models[/+] on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cost-modelCost formulas, statistics, ranking, and selectionenhancementNew feature or requestoptimizerWorkload optimization and plan selectionsearchCandidate-plan search space and algorithms

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions