Repository navigation
Planning roadmap: move ASAPQuery planning into ASAPPlanner, MILP plan selection over shared DAGs, benchmark-based accuracy #671
Copy link
Copy link
Open
Description
This issue records a design discussion: reusing ASAPPlanner for ASAPQuery's planning, selecting a plan with a MILP solver over shared DAGs, and using benchmark data for accuracy.
1. Move ASAPQuery's planning logic into ASAPPlanner
- ASAPPlanner should be used for planning as much as possible. The planning logic that still lives in ASAPQuery should move here.
- Most of that logic isn't specific to ASAPQuery. It applies to any use case with the same deployment model: stored summaries, ingestion-time versus query-time computation, and a runtime that executes the plan as given.
- Boundary: the planner stays deployment-agnostic. Deployment-specific concepts arrive as inputs (capabilities, cost and accuracy models, constraints) and are not built into the planner. Execution remains the deployment runtime's job (Stage 4 in planner-layering.md).
- To do:
- List the ASAPQuery planning components (rule coverage, the greedy cross-query selection, sizing, and so on; see
docs/design_docs/proposals/asapquery-rule-coverage.md). - Map each one to a stage in planner-layering.md, or mark it as a deployment input.
- Move them stage by stage.
- List the ASAPQuery planning components (rule coverage, the greedy cross-query selection, sizing, and so on; see
2. Plan selection as a MILP over shared DAGs
-
Stage 3 (plan selection) could be written as a mixed-integer linear program. Variables would choose:
- a candidate per computation;
- sharing between computations (Pass 2);
- a materialization option per sub-DAG (Stage 2).
Constraints would cover accuracy, memory and disk budgets, and latency (see Stage 3: memory, disk and latency trade-offs per candidate, and cost models beyond cloud billing #660 for the deployment cost models).
-
Open question: how to express DAG sharing in the model.
- A straightforward formulation is an approximation. It cannot represent every way sub-DAGs can be shared.
- It may be possible to model sharing exactly if the formulation is designed carefully. Examples: an indicator per shared node; consumption constraints that link each consumer's choice to the shared node's existence and size; the strictest-consumer sizing rule.
-
To decide:
- an exact versus an approximate formulation, and what the approximation gives up;
- the problem size for realistic workloads;
- how it relates to the current enumeration and DP selection.
3. Accuracy from benchmarks where theory gives no bound
- Many summary error bounds depend on the shape of the data. Some combinations have no usable theoretical bound at all, for example rank-interval guarantees for differences of quantiles (Compose accuracy guarantees through arithmetic and comparisons over approximate values #669), heavy-hitter membership, and ratios.
- For those, Stage 3 needs an empirical accuracy model. Benchmarking summaries over representative data (sketch-bench, or a similar harness) can supply it.
- This matches the selection rule decided in the refactor(planner): plan the workload on the unified operator IR #542/feat(planner): compose candidate logical ASAP DAGs from Pass 1 per-computation candidates #575 reviews: automatic selection needs output-level evidence. That evidence is either a composed theoretical guarantee or the deployment's empirical accuracy for that candidate's output.
- To do: define which benchmark measurements feed the accuracy model (per family, size, data shape and query type), and how a candidate's output is matched to them.
Related: #509 (planning stages), #660 (deployment cost models), #669 (guarantee composition).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
zzylol commentedon Oct 13, 2026
Survey: how existing query optimizers search for plans
This is a survey of how existing systems search the plan space, written for part 2 (plan selection). Where a detail depends on a system's version or configuration, I say so.
1. Bottom-up dynamic programming (System R family)
geqo_thresholdrelations (12 by default), and a genetic algorithm (GEQO) above that.spark.sql.cbo.joinReorder.dp.threshold(12 by default).2. Top-down memoization with rules (Volcano / Cascades)
VolcanoPlanner. Calcite also hasHepPlanner, which only rewrites by rules.3. Rule-based rewriting to a fixed point (DataFusion)
OptimizerRules, applied over several passes until the plan stops changing (with a configurable pass limit). Examples:SimplifyExpressions,PushDownFilter,OptimizeProjections,EliminateCrossJoin, decorrelation rules.PhysicalOptimizerRules.JoinSelectionuses statistics to pick join sides and algorithms; others enforce distribution and sorting.Optimizer::with_rules(...)lets a caller run a chosen subset of rules (Run selected DataFusion optimizer rules in SQL lowering; a rule-list API for ASAPPlanner rewrites #670).egg) has been tried experimentally on top of DataFusion's expressions. It keeps every equivalent form and extracts the cheapest one, which makes it a close cousin of a Cascades memo.4. MILP and other formulations
5. Problems closest to ours: sharing and materialization
Our Stage 3 picks plans for a whole workload DAG with shared sub-DAGs (Pass 2) and materialization choices (Stage 2). The closest prior work:
Multi-query optimization (MQO). Sellis (TODS 1988) gives an exact search over plans with shared subexpressions. Roy, Seshadri, Sudarshan & Bhobe (SIGMOD 2000) extend a Volcano AND-OR DAG with sharable nodes and choose what to materialize and share greedily, because exact MQO is NP-hard.
Materialized view selection.
This corresponds to our Stage 2 decision (MatAtIngestion / MatAtQuery / NotMaterialized) together with Stage 3: memory, disk and latency trade-offs per candidate, and cost models beyond cloud billing #660's memory and disk budgets.
6. What this means for ASAPPlanner
CandidateLogicalASAPDAGs::global_selectioninreplacement.rsis a DP over the reference DAG. It memoizes each site's effective consumer count and re-decides share versus recompute against that count. Its doc says it is not an exhaustive global optimum, and there is an exhaustive fallback for cases where the DP's assumptions fail. (docs: propose workload-wide planning, summary sharing, and materialization #509 also notes that its MEMO-like layout resembles Cascades.)global_selection.Related: #670 (running selected DataFusion optimizer rules during SQL lowering), #660 (deployment cost models and budgets), #509.