Skip to content

Commit 49c5187

Browse files
zzylolclaude
andcommitted
docs: describe the stage pipeline instead of the removed legacy search
Library API, architecture overview, planner pipeline and the accuracy and cost developer docs now describe the #509 stage pipeline. Docs that only describe removed APIs (legacy search, CostModel, explanation, physical-plan cost adapter) are marked historical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 6d28dba commit 49c5187

34 files changed

Lines changed: 390 additions & 910 deletions

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# ASAPPlanner
22

3-
ASAPPlanner turns SQL, PromQL, and MetricsQL query workloads into legal candidate plans that may use Approximate Streaming Analytics Primitives (ASAPs), such as sketches and exact summaries. It normalizes language-specific queries into a shared representation, then enumerates and ranks semantically equivalent alternatives. Downstream systems choose, deploy, and execute a physical plan.
3+
ASAPPlanner turns SQL, PromQL, and MetricsQL query workloads into plans that may use Approximate Streaming Analytics Primitives (ASAPs), such as sketches and exact summaries. It normalizes language-specific queries into a shared representation, enumerates semantically equivalent alternatives, and selects the cheapest one that meets each query's accuracy target. Downstream systems deploy and execute the physical plan.
44

55
## Start here
66

77
- New to the repository? Read the [planner pipeline](docs/design_docs/concepts/planner-pipeline.md), then the [glossary](docs/design_docs/concepts/glossary.md).
88
- Want to run a query? Follow [Run and inspect a query](docs/user_guide_docs/run-a-query.md).
99
- Embedding Planner? Use the [library API guide](docs/develop_docs/library-api.md).
10-
- Extending Planner? Start with the [ASAP-aware mapping architecture](docs/develop_docs/asap-aware-mapping-architecture.md), then [extend ASAP-aware mapping](docs/develop_docs/extend-asap-aware-mapping.md).
10+
- Extending Planner? Start with the [ASAP-aware mapping architecture](docs/develop_docs/asap-aware-mapping-architecture.md).
1111
- Evaluating a design? Browse the [design documentation](docs/design_docs/README.md), [developer documentation](docs/develop_docs/README.md), and [user guides](docs/user_guide_docs/README.md).
1212

1313
The [documentation map](docs/README.md) gives each audience a complete reading path.

‎docs/README.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ Start with [ASAPPlanner input, output, and workflows](design_docs/architecture/i
1919
for the integration boundary, nested inputs, and choice of planning workflow.
2020

2121
Use [Public library functions and examples](develop_docs/library-api.md) for
22-
frontend lowering, workload search, ranking, selection and DAG assembly.
22+
frontend lowering, planning a workload with the stage pipeline, and export.
2323

2424
## Extend the planner
2525

2626
1. Read the [ASAP-aware mapping architecture](develop_docs/asap-aware-mapping-architecture.md).
27-
2. Consult [mapping contracts](develop_docs/asap-aware-mapping-contracts.md).
28-
3. Follow [Extend ASAP-aware mapping](develop_docs/extend-asap-aware-mapping.md).
27+
2. Read [local logical candidates](develop_docs/local-logical-candidates.md) for Stage 1.
2928

3029
## Understand a design
3130

‎docs/design_docs/architecture/README.md‎

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,43 @@
11
# ASAPPlanner design overview
22

33
ASAPPlanner is a reusable planning library. It converts queries and workload
4-
requirements into a deployment-independent space of logical Post-ASAP candidates.
5-
It does not commit, deploy, or execute a physical plan; downstream systems such
6-
as ASAPQuery-backend bind the candidates to physical alternatives, make the
4+
requirements into a selected logical Post-ASAP plan, through the #509 stage
5+
pipeline. It does not deploy or execute a physical plan; downstream systems
6+
such as ASAPQuery-backend bind the plan to physical operators, make the
77
deployment-level decision, and run the selected contract.
88

9-
For the integration workflow, start with [ASAPPlanner input, output, and
10-
workflows](input-output-workflow.md). It defines inputs, `CandidateLogicalASAPDAGs`, selection
11-
and assembly workflows, and future replanning support.
9+
For the integration workflow, start with the
10+
[library API](../../develop_docs/library-api.md);
11+
[ASAPPlanner input, output, and workflows](input-output-workflow.md) defines
12+
the workload inputs.
1213

1314
## Planner component flow
1415

1516
```mermaid
1617
flowchart TD
1718
W["PlanningWorkload: query demand + optional data facts"]
1819
F["Frontend dependencies: SQL catalog or PromQL time"]
19-
E["Strategy, accuracy model, and applicable evidence"]
20-
PRE["Frontend lowering → canonical Pre-ASAP OperatorNode roots"]
21-
SEARCH["Whole-workload candidate search: sharing, legality, accuracy"]
22-
SPACE["CandidateLogicalASAPDAGs: compact logical candidate DAG space"]
23-
RANK["Optional cost_sorted: ranked inspection view"]
24-
SELECT["Optional global_selection + assemble_selected_dag"]
25-
DAG["Selected logical Post-ASAP DAG"]
26-
BACKEND["Downstream: bind physical alternatives, decide deployment, compile and execute"]
20+
M["PlanningModels: accuracy model, calibration, deployment capabilities"]
21+
PRE["Frontend lowering → canonical Pre-ASAP roots"]
22+
S1["Stage 1: Pass 1 alternatives per target; Pass 2 sharing variants"]
23+
S2["Stage 2: physical candidates (materialization)"]
24+
S3["Stage 3: accuracy and capability checks, pricing, selection"]
25+
PLAN["Selected logical Post-ASAP plan + selection report"]
26+
BACKEND["Downstream: bind physical operators, deploy, compile and execute"]
2727
W --> PRE
2828
F --> PRE
29-
PRE --> SEARCH
30-
E --> SEARCH
31-
SEARCH --> SPACE
32-
SPACE --> RANK --> BACKEND
33-
SPACE --> SELECT --> DAG --> BACKEND
29+
PRE --> S1 --> S2 --> S3
30+
M --> S3
31+
S3 --> PLAN --> BACKEND
3432
```
3533

36-
`CandidateLogicalASAPDAGs` is the output of logical candidate search. Each target's candidate set holds
37-
alternatives and rejection reasons, but no materialization decision.
38-
Choose between two branches: inspect candidates (optionally ranked), or select
39-
and assemble logical DAGs. Stage 2 materialization (#509) will decide per
40-
sub-DAG whether to materialize and whether at ingestion or query time; until
41-
then every summary runs at query time. No branch by itself deploys or executes
42-
a physical plan.
43-
Known-invalid evidence rejects a logical candidate. Missing accuracy evidence
44-
leaves a constructible candidate visible in `CandidateLogicalASAPDAGs` but uncertified; default
45-
selection does not commit it without the required guarantee. Cost evidence can
46-
rank eligible candidates, but it cannot establish a missing guarantee or turn
47-
an unsupported physical alternative into a deployable plan.
34+
Stage 1 lists alternatives without pricing them. Stage 3 rejects a candidate
35+
whose summary estimate misses its query's accuracy target (or has no accuracy
36+
model), that needs a capability the deployment lacks, or that exceeds its
37+
memory budget, and selects the cheapest remaining one. Rejection reasons are
38+
reported with the selection. Cost evidence can rank valid candidates, but it
39+
cannot establish a missing guarantee or turn an unsupported physical
40+
alternative into a deployable plan.
4841

4942
## Module map
5043

@@ -53,7 +46,7 @@ an unsupported physical alternative into a deployable plan.
5346
| Shared IR | `asap-types` | The unified operator IR (`ir`: one `OperatorNode` before and after ASAP optimization), schemas, workloads, guarantees, and exported plan data |
5447
| Front-end common | `frontend-common` | Name-based `UnresolvedOp` tree shared by the front ends, and `resolve_root` into the operator IR |
5548
| Query frontends | `frontend-sql`, `frontend-promql`, `frontend-metricsql` | Parse source languages and produce canonical Pre-ASAP queries |
56-
| ASAP-aware mapping | `asap-logical-optimizer`, `asap-physical-optimizer`, `asap-plan-selection` | #509 Stages 1–3: candidate generation, CSE, legality and accuracy propagation; physical candidates; costing and selection |
49+
| ASAP-aware mapping | `asap-logical-optimizer`, `asap-physical-optimizer`, `asap-plan-selection` | #509 Stages 1–3: logical alternatives and sharing; physical candidates; accuracy checks, costing and selection |
5750
| Planner facade | `asap-planner` | Lowering dispatch, the optimization pass (`OptimizationPass`, `StagePipeline`) and `optimize` |
5851
| Developer inspection | `devtools` | Expose planner DAGs, alternatives, decisions, and explanations for inspection |
5952
| End-to-end validation | `integration-tests` | Verify behavior across frontends, mapping, and output IR |
@@ -66,27 +59,18 @@ requirements, the planning horizon, available materialized state, downstream
6659
capabilities, and complete cost evidence. Missing or stale evidence must remain
6760
explicit rather than being treated as zero.
6861

69-
The primary output is `CandidateLogicalASAPDAGs`; `cost_sorted` derives an optional ranked
70-
view with index-aligned costs. Downstream may inspect compatible choices
71-
across targets rather than assuming the first candidate is a feasible
72-
physical workload plan. Candidates carry logical summary algorithms,
73-
parameters, and guarantees, but no materialization decision. Rejection reasons
74-
are retained in the candidate space.
62+
The output is the selected plan: one logical Post-ASAP root per query
63+
(`PlanOutput`), with the selection report — the priced candidates, the rejected
64+
ones with their reasons, and whether the selection is guaranteed optimal.
65+
`plan_stages` also returns Stage 1's alternatives for inspection.
7566

76-
ASAPQuery-backend and other downstream applications translate the candidates
67+
ASAPQuery-backend and other downstream applications translate the selected plan
7768
into physical alternatives. They own concrete implementations, storage layout,
7869
placement, sharding, deployment-level cost and compatibility, final commitment,
7970
serving, and operational feedback. Their physical planning can reorder
8071
candidates because it has evidence that the reusable Planner does not, but it
8172
must not silently change Planner-owned semantics.
8273

83-
`candidate_selection::global_selection` optionally coordinates structural choices across
84-
targets; `GlobalSelection::assemble_selected_dag` constructs a selected semantic DAG.
85-
Those APIs do not establish physical feasibility or a
86-
materialization decision. See the [library guide](../../develop_docs/library-api.md#optional-whole-plan-selection-and-dag-assembly)
87-
for the distinction. Downstream may consume candidates directly and retains
88-
responsibility for physical commitment.
89-
9074
## Further reading
9175

9276
- [Parsing and canonicalization](parse-and-canonicalize.md)

‎docs/design_docs/architecture/asap-aware-mapping.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ASAP-Aware Mapping
22

3+
> **Historical:** this document describes the legacy replacement search
4+
> (`ReplacementStrategy`, `CandidateLogicalASAPDAGs`, `global_selection`), which
5+
> was removed (#630, #635). The #509 stage pipeline replaced it; see
6+
> [planner layering](../proposals/planner-layering.md) and the
7+
> [library API](../../develop_docs/library-api.md).
8+
39
## Overview
410

511
ASAP-aware mapping decides **whether and how a query intent can be answered using summaries instead of scanning raw data**.

‎docs/design_docs/architecture/asap-aware-plan-search.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Candidate Plan Search
22

3+
> **Historical:** this document describes the legacy replacement search
4+
> (`ReplacementStrategy`, `CandidateLogicalASAPDAGs`, `global_selection`), which
5+
> was removed (#630, #635). The #509 stage pipeline replaced it; see
6+
> [planner layering](../proposals/planner-layering.md) and the
7+
> [library API](../../develop_docs/library-api.md).
8+
39
ASAP-aware mapping should consider all alternatives holistically rather than optimize prematurely.
410

511
Suppose a plan contains several independent-looking decision points:
@@ -91,6 +97,6 @@ order.
9197

9298
The [code architecture](../../develop_docs/asap-aware-mapping-architecture.md)
9399
describes current discovery and registry behavior; the
94-
[library guide](../../develop_docs/library-api.md#optional-whole-plan-selection-and-dag-assembly)
100+
[library guide](../../develop_docs/library-api.md)
95101
shows selection and its evidence boundaries. Broader optimization dimensions are
96102
tracked in the [proposal](../proposals/asap-aware-mapping/optimizations.md).

‎docs/design_docs/architecture/evidence-dependent-candidates.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Evidence-dependent candidates
22

3+
> **Historical:** this document describes the legacy replacement search
4+
> (`ReplacementStrategy`, `CandidateLogicalASAPDAGs`, `global_selection`), which
5+
> was removed (#630, #635). The #509 stage pipeline replaced it; see
6+
> [planner layering](../proposals/planner-layering.md) and the
7+
> [library API](../../develop_docs/library-api.md).
8+
39
Audience: ASAPPlanner library integrators, especially ASAPQuery-backend.
410

511
`CandidateLogicalASAPDAGs` is a space of constructible logical alternatives, not a list of

‎docs/design_docs/architecture/input-output-workflow.md‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
## Overview
44

5+
> **Status:** the candidate-space output and the ranking and selection
6+
> workflows this document describes (`CandidateLogicalASAPDAGs`, `cost_sorted`,
7+
> `global_selection`, `CostModel`) were removed with the legacy search (#630,
8+
> #635). ASAPPlanner now runs the #509 stage pipeline and returns the selected
9+
> plan: `asap_planner::e2e_plan` returns a `PlanOutput`, and
10+
> `asap_plan_selection::plan_stages` a `StagePipelineRun` with Stage 1's
11+
> alternatives and the selection report. See the
12+
> [library API](../../develop_docs/library-api.md) for the current workflow.
13+
> The input sections below still describe the current `PlanningWorkload`; the
14+
> output and workflow sections are kept as a historical record.
15+
516
This document is for library integrators such as ASAPQuery-backend, not users
617
submitting queries through a backend.
718

@@ -17,7 +28,7 @@ Post-ASAP alternatives for the workload.
1728
| `PlanningWorkload.query_workload` | Query language and one-time/repeating query workloads | Yes |
1829
| `PlanningWorkload.data_workload` | Data arrival and optional evidence about ingestion, cardinality, and distribution | No implicit default. Set `None` when unavailable for non-PromQL workloads; PromQL requires `Some(DataWorkload)` with a nonzero ingestion interval. |
1930
| Frontend-specific dependencies (outside `PlanningWorkload`) | `SqlCatalog` for SQL; `now_ms` and, when needed, `HistogramCatalog` for PromQL | `SqlCatalog` is required for SQL lowering; `now_ms` is required for PromQL lowering |
20-
| Planning models | Candidate cost/ranking and accuracy composition/checking | Used by the relevant APIs; built-in `DefaultCostModel` and `DefaultAccuracyModel` are available |
31+
| Planning models | Accuracy checking, cost calibration and deployment capabilities (`PlanningModels`) | `PlanningModels::builtin()` uses `DefaultAccuracyModel`, an illustrative calibration and unrestricted capabilities |
2132
| External evidence and capabilities | Domain facts, measured costs, workload statistics, and runtime support | Supply when available and when the chosen optimization depends on them; absence is not proof |
2233

2334
Frontend lowering and candidate search are stages within this workflow, not
@@ -277,8 +288,8 @@ latter cannot be fabricated by one.
277288

278289
| Input | Where it enters / default | Why it matters |
279290
|---|---|---|
280-
| Accuracy model | Target-aware search takes an `AccuracyModel`; `DefaultAccuracyModel` is available. Default strategies also use it for candidate construction. | Composes candidate guarantees and checks them against requested accuracy. The model does not itself provide missing data-domain facts. |
281-
| Cost model | Candidate strategies and `cost_sorted`/`global_selection` use a `CostModel`; `DefaultCostModel` is available. | Ranks or selects candidates. The built-in model is not a measured deployment cost for every physical implementation. |
291+
| Accuracy model | `PlanningModels.accuracy`; `DefaultAccuracyModel` by default. Stage 3 checks each summary estimate with it. | Derives each estimate's guarantee and checks it against the requested accuracy. The model does not itself provide missing data-domain facts. |
292+
| Cost calibration | `PlanningModels.calibration`; `Stage3Calibration::ILLUSTRATIVE` by default. | Stage 3 prices candidates analytically; the built-in calibration is not a measured deployment cost. |
282293
| Accuracy/domain evidence | `AccuracyEvidenceProvider`; default strategies use `NoAccuracyEvidence` when no provider is supplied. | Input ranges, nonempty populations, Top-K intervals, and similar facts can certify or rule out particular approximations. Missing facts remain unknown. |
283294
| Measured cost evidence | Supplied through a deployment-specific cost model or physical-evidence provider when cost-based physical comparison is needed. | CPU, memory, and I/O estimates must be comparable before claiming a summary beats raw recomputation. |
284295
| Runtime capabilities | Checked by deployment-specific providers. | Prevents choosing a maintenance/window operation the intended executor cannot implement. |
@@ -297,7 +308,7 @@ the applicable strategy, accuracy target, and helper; missing evidence is not
297308
a blanket reason to discard unrelated candidates. For the direct DDSketch
298309
ratio above, search retains a candidate without a proven root guarantee when
299310
domain evidence is missing; automatic `global_selection` does not choose it.
300-
See the [candidate-search reference](../../develop_docs/library-api.md#generate-and-rank-candidates)
311+
See the [candidate-search reference](../../develop_docs/library-api.md)
301312
for this backend-selection path.
302313

303314
---
@@ -414,16 +425,16 @@ the result for one query root.
414425
|:---:|
415426
| **Input:** [CandidateLogicalASAPDAGs](asap-aware-plan-search.md) + cost model |
416427
| ↓ |
417-
| **Select:** [global_selection](../../develop_docs/library-api.md#what-does-global-selection-mean) chooses compatible alternatives |
428+
| **Select:** [global_selection](../../develop_docs/library-api.md) chooses compatible alternatives |
418429
| ↓ |
419-
| **Assemble:** [assemble_selected_dag(root)](../../develop_docs/library-api.md#api-definition-and-example) connects those choices for each query root |
430+
| **Assemble:** [assemble_selected_dag(root)](../../develop_docs/library-api.md) connects those choices for each query root |
420431
| ↓ |
421432
| **Output:** one selected logical [Post-ASAP DAG](../concepts/post-asap-ir.md) per query root |
422433

423434
Each output DAG specifies the chosen operators, parameters, and accuracy
424435
guarantees. Its root is an `Rc<OperatorNode>` (the same IR as the input,
425436
with some nodes now ASAP operators) and carries no execution timing yet; the
426-
[API reference](../../develop_docs/library-api.md#api-definition-and-example)
437+
[API reference](../../develop_docs/library-api.md)
427438
describes the function signatures and return handling.
428439

429440
This path selects how to compute the query, not whether summary state is

‎docs/design_docs/architecture/updated_interface_with_pluggable_optimization.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ What that buys:
1414
* A new optimization algorithm can be freely implemented as a trait implementation, rather than a
1515
rule disguised to fit a two-phase pipeline it does not share.
1616

17-
Unchanged: `CandidateLogicalASAPDAGs`, `cost_sorted`, `global_selection`, and the interface
18-
[input, output, and workflows](input-output-workflow.md) describes.
17+
The legacy API (`CandidateLogicalASAPDAGs`, `cost_sorted`, `global_selection`)
18+
was later removed (#630, #635); the "before" example below uses it.
1919

2020
```text
2121
PlanningWorkload ──lowering──▶ ParsedWorkload ──OptimizationPass──▶ PlanOutput
@@ -123,8 +123,8 @@ and the target beneath it. When it fails, it builds every combination if
123123
there are at most 64, and otherwise flags `Selection::method` as not
124124
guaranteed optimal.
125125

126-
`ReplacementStrategy` remains a concept of the legacy candidate search, which
127-
the default pass no longer uses.
126+
`ReplacementStrategy` was a concept of the legacy candidate search, which has
127+
been removed (#635).
128128

129129
### 3.2 Plugging in another pass
130130

‎docs/design_docs/concepts/accuracy-models.md‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,11 @@ another implementation with the same algorithm name. In particular, a named
130130
empirical calibration is different from an arbitrary benchmark's maximum
131131
observed error; both its confidence and applicability must remain explicit.
132132

133-
The current interfaces still expose general parameter proposal through
134-
`CostModel::size_params`. Default sizing is dispatched to the estimator modules through the existing
135-
public candidate-construction entry point. Accuracy validation is independent of those proposals. The new
136-
source-contract path centralizes HLL sizing and guarantee derivation in
137-
Planner's accuracy module, overriding the generic proposal when the applicable
138-
contract is supplied. It does not yet move every algorithm's sizing interface
139-
out of CostModel. The design boundary is that parameter proposals never grant
140-
accuracy authority to the cost model.
133+
Stage 1 sizes every sketch through the estimator modules
134+
(`asap_logical_optimizer::pass1::realization::default_size_params`); no cost
135+
model proposes parameters. Accuracy validation (Stage 3's `AccuracyModel`) is
136+
independent of sizing. The design boundary is that parameter proposals never
137+
grant accuracy authority to the cost model.
141138

142139
## Composing guarantees through a DAG
143140

0 commit comments

Comments
 (0)