Skip to content

Stage 2 materialization: ingestion vs query time per summary - #604

Draft
zzylol wants to merge 2 commits into
stack/509-x8a-hydra-kernelfrom
stack/509-x5-stage2-materialization
Draft

zzylol wants to merge 2 commits into
stack/509-x8a-hydra-kernelfrom
stack/509-x5-stage2-materialization

Conversation

@zzylol

@zzylol zzylol commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Stack: Wave 2 chain: #599 → #601 → #600 → #604 → #606 → #603 → #605

Rebased on main d4869a7 (DF 54).

Stacked on #600. Part of #580, step 5; #509 Stage 2 "Materialization". Implements decisions S1–S6 and Q44 (pricing #594, panes #601).

Why

Stage 2 ran every summary at query time, so Stage 3 never compared maintaining state at ingestion time with rebuilding it at each evaluation. Example 4's B1 (tumbling KLLs at ingestion time) was not generated. Query latency bounds were not checked.

What

  1. Eligibility (S4). A SummaryAgg may run at ingestion time when all of these hold:

    • DataWorkload.arrival is ContinuouslyIngesting or Mixed. Unknown counts as not ingesting.
    • Every root that reaches it repeats and is Predictable.
    • It is a tumbling pane, or it reads one fixed window per evaluation: FixedIntervalAt, with a window no longer than the interval.

    A summary over a merge of panes reads a sliding window, so it stays at query time. The panes of one merge form one unit.

  2. Down-closed sets. Stage 2 returns one physical candidate per set of units in which everything below an ingestion-time unit is also at ingestion time. The all-query-time candidate comes first. Ids are P<n> for all query time and P<n>-m<k> otherwise; labels end in "· ingestion time: Kll ×5 panes". Above 16 sets, Stage 2 adds units greedily by Stage 3's cost and flags the selection as not guaranteed optimal.

  3. Cross-root phase split. split_shared_by_phase(&[roots], assignment) copies a node per phase when one consumer reads it at ingestion time and another at query time, across queries. It returns the assignment re-keyed to the copies.

  4. Selection. The tree DP's evaluate, enumeration and finish take the cheapest valid physical candidate of each logical candidate. DP-versus-exhaustive tests run with materialization on.

  5. Pricing panes. At ingestion time, a pane chain is one pane, built as rows arrive and kept. The newest pane pays the λ-rate build and the memory of lookback/width + 1 panes (S3: in memory only). Older panes, and the shifts and ranges that feed only them, cost 0.

  6. Latency check (S6). A candidate is rejected when a query's query-time work for one evaluation is above its latency_ms. The work counts every query-time node the query reaches, shared nodes included. New Stage3Calibration::latency_ms_per_cost_unit = 1 (one CPU-ms on one core). Example reason: q1: query-time work takes 310.0 ms per evaluation, over the 200 ms latency bound. RootDemand now carries latency_ms.

  7. Docs. stage3-cost-model.md covers pane retention, the latency check and the calibration field, and updates Example 1's worked example.

Before / After (built-in models, constants untuned)

Before (#600) After
Example 1 physical candidates 88 112: 24 also maintain Q2's 10-s sum_over_time panes
Example 1 selected P82, 4.620 cost/s P82, 4.620 (unchanged)
Example 1 cheapest maintained — P39-m1, 47.407: scan 0.387, shift + range 0.133, newest-pane build 0.067, memory 42.0 (7 panes × 1M sums = 336 MB), plus Q1 and the query-time merge, finalize and CMS
Example 1 latency not checked 40 candidates over Q2's 100 ms bound, every Count-Sketch + heap among them
Example 3B candidates 5 7: KLL and DDSketch panes at ingestion time
Example 3B selected P2 KLL, 2.083 P2 KLL, 2.083 (unchanged)
Example 3B tumbling at query time 5.167, valid rejected: 310 ms, over the 200 ms bound
Example 3B tumbling at ingestion time (B1) not generated P4-m1, 768.58: build 0.067, scan/shift/range 0.41, merge + estimate 0.10, memory 768.0 (6 panes × 1M series × 1 KiB KLL = 6.1 GB)
Example 3A / Example 4 Pattern A P365 unchanged. Run once ad hoc, or monthly without a phase and with windows longer than the interval, or at rest: nothing is eligible

Ingestion time does not win any example under the built-in models. With 1M series, memory for retained per-series state is much larger than the CPU it saves. In a unit test with 10 series at 100k rows/s, maintained panes win, and the DP selects them too.

Tests

  • timing.rs: a cross-root split keeps the assignment, and a node reached at one timing stays shared.
  • materialization.rs: panes go to ingestion time and the merge stays at query time. Arrival, ad hoc and one-off rules. A whole window needs a phase and must not overlap. Sets are down-closed: an exact sum plus a CMS gives 3 sets, and over panes only the panes count. Greedy above the cap.
  • plan-selection: the newest pane pays the build plus (N+1)× memory, and the older panes pay 0. The latency bound rejects slow candidates with a reason. Maintained panes win with few series, and the DP agrees with exhaustive selection.
  • Example 1: counts are 88 → 112. Only the 6 sum panes and their inputs run at ingestion time, and the scan is split from Q1's. New latency test. Ranking and sharing tests cover all-query-time candidates.
  • Example 3: query-time tumbling misses the latency bound, and the maintained form is valid. End to end: runtime_b_maintained_panes_match_the_whole_window compiles the B1 candidate once. It cuts the candidate at frontier_from_timing with cut_candidate, runs the precompute once per pane in that pane's Scope::Ingestion window, then runs the query over the 5 kept panes. It returns the whole-window rows (p99 19 and 119). Example 1's selected plan has nothing eligible, so there is no end-to-end case for it.
  • Example 1 fixture regenerated: 112 physical candidates, 12 MB (was 9.3 MB).

Gate: cargo fmt --all --check, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo test --workspace: 1,630 passed / 12 ignored (#600: 1,619 / 12). Viewer: 29 OK (6 skipped).

Not in this PR

  • A3 / Q44: "not materialized" for a sub-DAG with several consumers, generated by duplicating it per consumer. Follow-up.
  • B3: a pane built at query time and kept for later evaluations. The newest pane would need to be marked.
  • Sliding windows, storage tier and retention (S3), backfill (S5).
  • A maintained state does not record its retention in the IR yet. Pricing derives it from the merge.

Links: #509, #580, #594 (Stage 3 cost), #601 (panes), #600.

🤖 Generated with Claude Code

zzylol added a commit that referenced this pull request Oct 4, 2026
RootDemand gained latency_ms in #604; the Example 2 coverage test's
demand sets it to None (no latency bound).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zzylol added a commit that referenced this pull request Oct 4, 2026
#604 gave RootDemand a latency_ms and a logical candidate several
physical candidates. The Hydra count test sets no latency bound and checks
the all-query-time physical candidate, which comes first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzylol
zzylol force-pushed the stack/509-x8a-hydra-kernel branch from 09fa09e to f97037a Compare October 5, 2026 06:21
@zzylol
zzylol force-pushed the stack/509-x5-stage2-materialization branch from ec82a21 to 78cf83f Compare October 5, 2026 06:21
@zzylol
zzylol force-pushed the stack/509-x8a-hydra-kernel branch from f97037a to c6ff43d Compare October 8, 2026 16:47
@zzylol
zzylol force-pushed the stack/509-x5-stage2-materialization branch 2 times, most recently from 90f0195 to ed84c85 Compare October 10, 2026 14:32
zzylol and others added 2 commits October 11, 2026 16:22
…ummary

- Eligibility (S4): a SummaryAgg may run at ingestion time when the data
  is continuously ingesting or mixed, every root reaching it repeats and is
  predictable, and it is a tumbling pane or reads one fixed window per
  evaluation (FixedIntervalAt, window no longer than the interval). The
  panes of one merge are one unit.
- Stage 2 enumerates the down-closed sets of units (all query time first),
  each built with a workload-wide split_shared_by_phase that copies a node
  shared by an ingestion-time and a query-time consumer per phase and
  re-keys the assignment. Above 16 sets it searches greedily by Stage 3's
  cost and flags the selection as not guaranteed optimal.
- Stage 3 takes the cheapest valid physical candidate of each logical one,
  in the DP and in enumeration. Ingestion-time panes are one pane built as
  rows arrive: the newest pane pays the build and retains N + 1 panes; the
  older panes and their inputs cost nothing.
- Latency check (S6): a query whose query-time work per evaluation exceeds
  its latency_ms is rejected with the estimate and the bound
  (Stage3Calibration::latency_ms_per_cost_unit, 1 CPU-ms per ms).
- RootDemand carries latency_ms.

Example 1: 112 physical candidates (24 maintain Q2's sum panes), same
selection P82 at 4.620; maintained panes cost 47.4 (42.0 memory); 40
candidates over Q2's 100 ms bound. Example 3B: P2 KLL still selected at
2.083; tumbling panes at query time miss the 200 ms bound, maintained ones
cost 768.6 (768.0 memory). The executor runs Example 3B's maintained plan
per pane and returns the whole-window rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… 2 materialization

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
@zzylol
zzylol force-pushed the stack/509-x8a-hydra-kernel branch from 4e47e52 to 7babbbc Compare October 11, 2026 17:11
@zzylol
zzylol force-pushed the stack/509-x5-stage2-materialization branch from ed84c85 to 1f6dbd2 Compare October 11, 2026 17:11
zzylol added a commit that referenced this pull request Oct 13, 2026
…th its reason

A Stage 2 error no longer fails the whole candidate set: stage_pipeline lists
that candidate under stage2_physical_asap.pruned and plans the rest. Full
materialization enumeration is left to #604.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
zzylol added a commit that referenced this pull request Oct 13, 2026
…th its reason

A Stage 2 error no longer fails the whole candidate set: stage_pipeline lists
that candidate under stage2_physical_asap.pruned and plans the rest. Full
materialization enumeration is left to #604.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
zzylol added a commit that referenced this pull request Oct 13, 2026
…th its reason

A Stage 2 error no longer fails the whole candidate set: stage_pipeline lists
that candidate under stage2_physical_asap.pruned and plans the rest. Full
materialization enumeration is left to #604.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
zzylol added a commit that referenced this pull request Oct 13, 2026
The specs and tests from #590 run the current stages through the shared
planner_layering_common pipeline (Pass 1 and composition,
optimize_physical_asap, select_plan); tests are named after the stages.
Materialization is read from the physical DAG (#667); window forms and
retention stay pending adapters. Behavior that works passes (29 tests);
every expectation that needs a feature not in this stack is ignored with
the PR that delivers it (29 tests): Pass 2 sharing (#588, #595, #596),
window composition (#601, #628, #634), materialization enumeration and
MatAtQuery (#604, #625), UnivMon sizing and accuracy (#621), SQL
recognition and COUNT(*) composition (#598, #603) and plan selection row
estimates (#632). Each spec's "Today" column states the current output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
zzylol added a commit that referenced this pull request Oct 13, 2026
…r candidate logical ASAP DAGs (#576)

* feat(planner): #509 Stage 2 physical candidates and Stage 3 plan selection (MVP)

Stage 2 implements one logical candidate physically: exact Aggregate{[TopK]}
becomes Limit(Sort) per group, summaries stay build -> estimate, every node
runs at query time, and the timed roots export as one PhysicalASAPDAG.

Stage 3 is the only stage that computes cost. It rejects candidates whose
summary misses its query's accuracy target (accuracy model, analytical
guarantee) or uses Count-Min over weights not proven non-negative, prices
every valid candidate node by node with analytical_cost (illustrative
statistics), selects the cheapest and reports the rest as costlier.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat(devtools): stage_pipeline emits all four stages for Example 1

Add stage2_physical_asap (no cost) and stage3_selection (costs, selected,
every other candidate rejected as invalid or costlier) per the v2 contract.
PromQL rows carry the series identity from Stage 0, as runtime state needs.
Regenerate tools/dag-viewer/examples/planner-layering-example1.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(planner): read Operator<NodeId> payloads in Stage 2/3 after the export removal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* fix(planner): Stage 2/3 on #575's composed candidates, query roots and #667 materialization

Stage 2 takes query roots, scalar ones included (#542), times every sub-DAG
with Materialization::NotMaterialized (#667) and keeps the guarantee Stage 1
composed on every node it implements; a MaintainPopulation is no longer
rejected, since it now runs at query time when not materialized.

Stage 3 accepts a query's output when its root guarantee meets the target,
or when the deployment's accuracy model shows this candidate's output does
(AccuracyModel::output_guarantee, none by default). A certified estimate
inside the plan is not enough: a difference of two quantile estimates stays
listed as invalid, with a reason, under the built-in models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test(devtools): regenerate the four-stage Example 1 fixture on the new #575

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* docs(planner): name Stage 2/3 by the planner-layering stage terms

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* fix(devtools): prune a logical candidate Stage 2 cannot implement, with its reason

A Stage 2 error no longer fails the whole candidate set: stage_pipeline lists
that candidate under stage2_physical_asap.pruned and plans the rest. Full
materialization enumeration is left to #604.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* fix(planner): read empirical output accuracy from deployment evidence in Stage 3

The output-level hook moves from AccuracyModel to AccuracyEvidenceProvider:
AccuracyModel stays theoretical, Stage 1 composes root guarantees with the
built-in model, and deployment evidence enters only in Stage 3. A scalar
root that is exactly scalar(v) inherits v's guarantee; any other scalar
expression over an approximate operand has none until #669.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* refactor(planner): name Stage 2/3 code and pipeline keys after the stage names

physical_candidates -> physical_asap_optimization (stage2_physical ->
optimize_physical_asap, Stage2Error -> PhysicalASAPOptimizationError),
stage3_select -> select_plan, and the stage_pipeline keys
stage2_physical_asap -> physical_asap_optimization and stage3_selection ->
plan_selection. The fixture is regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test(planner): plan selection tests after Top-K estimates lost their bound

#575 gives Top-K and signed Count-Min estimates guarantee None, so the
CountSketch+heap candidate of the top-k fixture no longer carries an
analytical guarantee: plan selection rejects it for missing evidence rather
than for missing the target. The "misses target" case now uses a quantile
summary planned at a looser target, and the per-node cost test admits the
CountSketch+heap candidate through deployment evidence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* fix(planner): exact top-k sorts by the ranked measure in physical optimization

Rank a one-measure grouped child by its measure (the SQL heavy-hitter and
PromQL `topk(k, sum by ..)` shapes) and per-series rows by the sample
value, instead of looking up a `value` column. A node reading the top-k
gets a Project restoring the logical [keys.., topk_k] columns over the
rows. An Aggregate{[TopK]} with other measures, a filter or HAVING now
fails, so its candidate is pruned with the reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* fix(devtools): stage_pipeline emits plan_selection when selection fails

With no valid candidate the document lists the rejections with a null
`selected` (and the Stage 2 pruned list as before); any other selection
error is reported under `error`, instead of failing the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* docs(planner): plan selection checks Count-Min only under a target; note MVP costing limits

Reword the Count-Min test to the decided behavior and test that a query
without a target admits the Count-Min candidate. Document that a cost
error aborts selection (only from bad declared rates) and that binary,
join and concat nodes are priced from their first input only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* fix(planner): exact top-k ranks by the measure of a composed Stage 1 child

After Pass 1 composition a top-k reads its one-measure aggregate as
Project(FinalizeExactAccumulator(SummaryAgg)) or Project(SummaryEstimate(..)),
not as an Aggregate, so ranking fell back to the sample value: a key named
`value` was sorted on, and an integer or multi-column key pruned the
candidate. Look through renaming Projects, Filters, finalize and estimate to
the SummaryAgg or Aggregate; a grouped one ranks by its last column. The SQL
test now composes every Pass 1 choice under exact and approximate targets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* fix(planner): exact top-k roots output the logical [keys.., topk_k] columns

An exact top-k root returned its child's raw rows (Example 1's P1 leaked
`ts`, `value` and `$promql_series_identity`), while summary candidates and
the frontend give `[keys.., topk_k]`. The restoring Project now sits over
the Limit at a root too, so one implementation serves roots and consumers.
`topk_k` carries the ranked value's type and nullability, not the frontend's
Utf8 placeholder. Regenerate the Example 1 fixture: P1 gains the root
Project (node 12).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* fix(planner): charge a NotMaterialized shared node once per consuming query

Plan selection prices each node once per computation: a materialized node
once, a NotMaterialized node once per query (or materialized node) that
reaches it, not counting through a materialized ancestor. Per-node costs
carry the multiplier. Also list the per-entity case among the exact top-k
shapes Stage 2 cannot rewrite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* docs(planner): nodes below a materialized node are charged once for it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
zzylol added a commit that referenced this pull request Oct 13, 2026
The specs and tests from #590 run the current stages through the shared
planner_layering_common pipeline (Pass 1 and composition,
optimize_physical_asap, select_plan); tests are named after the stages.
Materialization is read from the physical DAG (#667); window forms and
retention stay pending adapters. Behavior that works passes (29 tests);
every expectation that needs a feature not in this stack is ignored with
the PR that delivers it (29 tests): Pass 2 sharing (#588, #595, #596),
window composition (#601, #628, #634), materialization enumeration and
MatAtQuery (#604, #625), UnivMon sizing and accuracy (#621), SQL
recognition and COUNT(*) composition (#598, #603) and plan selection row
estimates (#632). Each spec's "Today" column states the current output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW
zzylol added a commit that referenced this pull request Oct 13, 2026
…stages (#577)

* test: acceptance spec and pending tests for planner-layering Example 1

Define MVP acceptance for #509 Example 1 before the Phase C stage APIs
exist: 1 -> 6 -> 6 -> 1 candidates (Pass 1 x identical-expression
sharing; physical operator implementation only, no materialization).

- Spec with per-stage candidate tables, invariants and doc ambiguities.
- Integration tests against todo!() stage stubs, ignored until the
  stages land; workload and Stage 0 frontend-shape tests run now.
- Expected-only asap-stage-pipeline/v1 fixture for the DAG viewer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: run the Example 1 acceptance tests against the real stages

Replace the todo!() stubs with adapters over Stage 0-3, un-ignore the 11
tests that pass, and give each still-ignored test the precise difference
between the implementation and the spec. Add runtime capability checks:
the selected plan compiles in the physical planner; compiling every
candidate stays ignored with the two runtime gaps it finds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: read Example 1 logical stages as flat DAGs after the export removal

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: Example 1 acceptance on the composed stages (1 -> 3 -> 3 -> 1)

The tests run Pass 1 and composition, optimize_physical_asap and
select_plan through a shared tests/planner_layering_common pipeline, and
follow the decided behavior: three Pass 1 candidates (Q2 exact, CMS+heap,
CountSketch+heap), every sub-DAG NotMaterialized, P1 selected, CMS+heap
invalid (weights not proven non-negative) and CountSketch+heap invalid (a
Top-K output has no guarantee and no deployment evidence). Hydra (#605),
Pass 2 sharing (#588) and the two runtime gaps (#593, #579) stay ignored
with the PR that delivers them. Tests are named after the stages; the
compile check no longer uses the PromQL fallback. The spec lists where the
doc and the planner differ. The expected-only viewer fixture is removed:
the generated four-stage fixture replaces it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: port #590's Example 2-4 acceptance specs and tests

The specs and tests from #590 run the current stages through the shared
planner_layering_common pipeline (Pass 1 and composition,
optimize_physical_asap, select_plan); tests are named after the stages.
Materialization is read from the physical DAG (#667); window forms and
retention stay pending adapters. Behavior that works passes (29 tests);
every expectation that needs a feature not in this stack is ignored with
the PR that delivers it (29 tests): Pass 2 sharing (#588, #595, #596),
window composition (#601, #628, #634), materialization enumeration and
MatAtQuery (#604, #625), UnivMon sizing and accuracy (#621), SQL
recognition and COUNT(*) composition (#598, #603) and plan selection row
estimates (#632). Each spec's "Today" column states the current output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* feat(devtools): stage_pipeline examples for #509 Example 3

Ported from #590: --example planner-layering-3a (Pattern A, ad hoc batch of
five p99 reports) and planner-layering-3b (Pattern B, repeating 5-min p99),
the Example 3 acceptance tests' workloads. Example 1's output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: follow #576's per-consumer charging and exact top-k columns

Plan selection charges a NotMaterialized node once per consuming query,
so the charging helper checks NodeCost.multiplier and the Example 4 A3
ambiguity is recorded as decided. Example 1 checks that exact Q2 sorts by
the ranked value and returns [job, topk_10]. The stage viewer guide's
tab 1 row now describes the actual all-exact result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* refactor(devtools): one planning pipeline for stage_pipeline and the acceptance tests

run_planning_stages and the #509 example workloads move into the
asap-devtools library; stage_pipeline serializes the run and the
planner-layering tests adapt it. The shared data workload drops
ingestion_rate for data at rest, which validate() requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* fix(devtools): select over every candidate; --max-displayed limits only the document

stage_pipeline capped enumeration at 64, so Example 3a (243 candidates)
selected P41 instead of the cheapest P122 (KLL for all five queries).
The pipeline now enumerates, optimizes and prices every candidate; the
document shows the first --max-displayed (default 64) plus the selected
one, with `combinations` and `capped`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* docs: Example 2's SQL candidates compose; the SQL test waits only on #598

Running the ignored SQL test composes every candidate and fails only on
Q2's options (per-source counts until #598), so #603 is not a blocker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: name stages by number and name; say query-language frontends

The frontends' Run field, id and locals become stage0_query_language_frontends,
and test names carry stage0..stage3 with the stage name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: charging helper follows plan selection's per-consumer rule

With a materialized node the helper accepted any multiplier >= 1. It now
computes each node's computations as plan selection does (walks from
query roots and materialized nodes' inputs, stopping at materialized
nodes), checked on a hand-built candidate with a materialized node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: Example 1 picks Q2 candidates by (option, no shared input)

physical_with and the invalid-candidate check no longer assume one
candidate per Q2 option, so #588's shared-input variants need no change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* docs: Example 3 Pattern B charges each node once per consuming query

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* docs(stage-viewer): rows 2, 3a and 3b describe the planner's current output

Read from uncapped runs: Example 2's sketch plans are rejected for having
no (ε, δ) guarantee, 3a selects P122 (first of 108 tied cheapest plans,
nothing shared yet) and 3b selects query-time KLL; panes and the latency
check come with the window-summary PRs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* docs(stage-viewer): row 2 from the SQL run; 3a ties 32 plans, not 108

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test: Example 1 counts only unshared candidates; stage3_ charging-helper names

The 3-logical and 3-physical counts now hold when #588 adds shared-input
variants.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* refactor(devtools): PlanningStagesRun fields carry stage number and name

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test(devtools): unique temp file per stage_pipeline run

cargo test runs the tests as threads of one process, so two runs of the same
example shared a file name and one deleted the other's output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
zzylol added a commit that referenced this pull request Oct 13, 2026
…e MajorPass (#674)

* feat(planner): run the planning stages as the planner pipeline; retire MajorPass

plan_stages runs logical ASAP-aware optimization (Pass 1 and composition
of every combination, capped), physical ASAP-aware optimization and plan
selection over the frontends' roots, and returns every stage's output.
StagePipeline runs it behind OptimizationPass and is the facade default;
the stage_pipeline devtool uses it (its fixture is unchanged). The
combination count saturates instead of overflowing.

summary_sharing: sharing tests are ignored until Pass 2 (#580); the
UnivMon legacy-search test is deleted; scalar and combined-quantile tests
run on plan_stages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test(planner): logical and physical ASAP-aware optimization import no cost model

From #582: only plan selection prices plans, so the Pass 1 / composition
and physical ASAP-aware optimization modules may not import cost_model,
recurrence, analytical_cost, physical_operator_statistics or
plan_selection (paths or re-exported names) outside tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* fix(planner): compose a per-series avg over rows that carry the series identity

The per-series sum keeps the input's labels, so with
$promql_series_identity after the sample value its last column is the
identity, and composition rejected the only exact option ("non-Float64
per-series avg"). The planner pipeline then had no candidate for
avg_over_time. Read the summed value by its role instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test(executor): take plans and candidates from the planner pipeline

From #629/#633: executor tests take the plan plan_stages selects
(selected_dag) or its composed logical candidates (logical_candidates)
instead of the legacy search and global selection.

- deployment_computation, precompute_candidates, the candidates.rs
  fixture: ported.
- planspace_series_identity_heap: keeps the selection check; the four
  tests of the legacy whole-root proposals are deleted.
- weighted_topk_binding: ported to Pass 1 heap candidates (Count Sketch
  only over rates: no sign proof). The tests of legacy-only candidate
  generation are deleted. Ignored, with reasons: the grouped weighted
  binding (whole-expression heap, #589) and the two rate-heap executions
  (top-k output schema, #672).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test(frontend-promql): take plans and candidates from the planner pipeline

From #629/#633, on support helpers over plan_stages (plan_stages,
selected_dag, logical_candidates, logical_plan):

- count_planning: exact counts select a Count accumulator; count
  updates are read from the composed Count-Min / Count Sketch
  candidates. The Hydra test is ported and ignored: Pass 1 offers no
  Hydra for a grouped count yet (#605).
- univmon_candidates: the synthetic accuracy model is gone; UnivMon
  candidates come from Pass 1 (the shared count at an approximate
  target), the uncalibrated ones carry no guarantee and plan selection
  does not select them.
- promql_corpus, metrics_observability: totality over Pass 1 and
  composition (logical_plan) instead of the legacy strategies; the
  metrics corpus reports composition errors under
  METRICS_OBSERVABILITY_REPORT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test(frontend-sql): take corr's exact plan from the planner pipeline

From #633: the plan plan_stages selects replaces retain_exact.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test(planner): the batch SUM example reads one exact accumulator per query

Under the planner pipeline each query's SUM is replaced by its exact
accumulator state; sharing identical producers is Pass 2 (#580).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* refactor(planner): stage identifiers carry number and name; enumerate every candidate

User decisions (2026-10-13):
- stage modules stage2_physical_asap_optimization and
  stage3_plan_selection; tests stage1_logical_asap_optimization.rs and
  stage2_physical_asap_optimization_sql.rs; stage_pipeline keys
  stage0_query_language_frontends, stage1_logical_asap_optimization,
  stage2_physical_asap_optimization, stage3_plan_selection (fixture
  regenerated: only the keys change);
- enumeration and selection are never capped: plan_stages enumerates
  every combination; the devtool's --max-displayed (was
  --max-candidates) caps only the listing;
- code docs say "query-language frontends".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test(integration): take plans and candidates from the planner pipeline

From #629/#633, on asap_integration_tests::planning (plan_stages,
selected_dag, logical_candidates):

- sql_to_physical, operator_sharing, materialization_e2e,
  precompute_raw_samples, summary_coverage_e2e,
  promql_numeric_regressions: ported.
- cse.rs: deleted; it pinned the legacy search's memo groups (sharing
  identical sub-DAGs is Pass 2, #580).
- Ignored, with reasons: the UNION ALL summary test (plan selection picks
  the exact plan until materialization, #604), arithmetic over one
  selector (#580), the unit-weight heap over raw samples (#589).
- precompute_raw_samples no longer requires a Count Sketch heap over raw
  samples (#589); materialization_e2e takes the quantile's sketch
  candidate, since plan selection picks the exact plan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* refactor(devtools): sketch_coverage reports Pass 1's summary candidates

From #633: per lowered query, the summary candidates Pass 1 offers,
instead of the legacy explain_replacements. The CSE-shareable metric is
dropped (sharing is Pass 2). Over every corpus at epsilon 0.01 and a 1 s
ingestion interval: 145/2183 lowered queries get a summary candidate, and
Pass 1 rejects none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* test(frontend-promql): the Kubernetes mixin aggregates over topk compose (ignored, #672)

Both corpus queries that do not compose aggregate over a topk output,
which the frontend declares as [keys.., topk_k] with a Utf8 placeholder
and no value column; the outer sum's accumulator has no value to read.
They compose once the top-k output carries the ranked value (#672).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

* refactor(devtools): run_planning_stages runs the library's plan_stages

One pipeline implementation: the devtool's run_planning_stages (#577)
validates the frontends' roots and every composed candidate, and
otherwise is plan_stages with the built-in models. Its candidate types
are the library's. The Example 1 fixture is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W7qG9aFyPij5uWsyAJCxDW

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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