Skip to content

feat: list current-series TopK heap alternatives in PlanSpace - #477

Open
zzylol wants to merge 5 commits into
split/462-f-physical-plannerfrom
feat/physical-alternatives-in-planspace
Open

zzylol wants to merge 5 commits into
split/462-f-physical-plannerfrom
feat/physical-alternatives-in-planspace

Conversation

@zzylol

@zzylol zzylol commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #475 (the #462 split: #472 merged, then #473 → #474 → #475).

Why

PlanSpace decides what to compute. It does not decide placement. The summary
maintenance lifecycle sets each node's timing (precompute or query), and the
physical compiler reads that timing. An instant-vector TopK has heap
realizations (CMS/CountSketch with heap) that rank rows carrying the complete
PromQL series identity. These are real logical alternatives, but PlanSpace did
not list them, so the backend built them outside Planner.

What

  • ReplacementStrategy::propose_for_root (new, default: none): whole-query
    logical alternatives for a targeted workload root. search_workload_with_targets
    asks it once per distinct root. It exists because these candidates need input
    rows (the series identity) that the logical root does not expose, so the
    per-subtree propose cannot produce them.
  • SketchAlgorithmStrategy implements it for current-series TopK only. It
    resolves identity-carrying rows with with_promql_series_identity (moved into
    asap-types so Planner can call it), then finalizes and deduplicates the
    candidates.
  • ReplacementProvenance::RootPhysicalRealization marks these candidates so that
    global_selection never commits them. Deployment validates and prices them.
  • Fixed-window and query-time Rate aggregation are placement variants, so they
    are not listed. fixed_window_rate_candidates and
    query_time_rate_aggregation_candidates stay public for the backend's
    current direct callers. Lifecycle-assigned timing replaces them in a later PR.

Before this PR

enumerate_candidate_dags_for_root for topk by(job)(1, m) lists only
logical-root candidates. To see the current-series heap, the backend applies the
series-identity pass and calls current_series_topk_candidates itself.

After this PR

The same call also lists finalized current-series heap readouts, each
bindable with promql_rows::compile_current_series_readout. The inventory for
sum by(job)(rate(m[1m])), topk by(job)(2, rate(m[1m])), rate(m[1m]) and
unrelated queries is unchanged, and so is default selection.

Validation

  • crates/asap-physical-operators/tests/planspace_series_identity_heap.rs:
    current-series heaps are listed and bindable. Rate placement variants are not
    listed (this test fails on the earlier feat: list current-series TopK heap alternatives in PlanSpace #477 head). Unrelated inventories are
    unchanged. Global selection never commits a heap. Repeated roots are proposed
    once.
  • cargo fmt --check, cargo clippy --workspace --all-targets -D warnings,
    cargo test --workspace --no-fail-fast. The only failure is the existing
    devtools dag_export::workload_node_ids_make_smaller_topk_reuse_explicit.

🤖 Generated with Claude Code

zzylol and others added 5 commits September 30, 2026 02:05
Planner search needs the physical row representation to propose whole-root
physical alternatives, and asap-aware-mapping cannot depend on the physical
runtime crate. promql_rows::with_series_identity keeps its signature and
delegates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The backend built one workload forest per per-query physical alternative by
calling SketchAlgorithmStrategy's proposal methods outside PlanSpace. Planner
now owns them: search_workload_with_targets asks each strategy's new
ReplacementStrategy::propose_for_root once per targeted root.
SketchAlgorithmStrategy resolves the series identity and proposes
current-series TopK, fixed-window and query-time Rate aggregation, and
realizations over per-series Rate state, finalized and deduplicated.

The candidates carry ReplacementProvenance::RootPhysicalRealization: DAG
assembly uses them verbatim, and global selection never commits them.
Existing candidates and their order are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PlanSpace decides what to compute; the summary maintenance lifecycle decides
node timing and the physical compiler reads it. The fixed-window and
query-time Rate aggregation candidates only rewrote a finalization node's
timing, so they are placement variants and no longer go through
propose_for_root. The backend still calls those methods directly.

SketchAlgorithmStrategy::propose_for_root now proposes only current-series
TopK heaps, which rank identity-carrying rows the logical root lacks. The
per-series Rate filter and the verbatim-assembly branch are removed: the
latter is unnecessary because non-Aggregate roots are already assembled
verbatim. RootPhysicalRealization stays so global selection never commits
an unvalidated identity-carrying readout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzylol zzylol changed the title feat: list PromQL physical alternatives in PlanSpace feat: list current-series TopK heap alternatives in PlanSpace Sep 30, 2026
@zzylol
zzylol force-pushed the feat/physical-alternatives-in-planspace branch from 94a6962 to 0d3b601 Compare September 30, 2026 02:07
@zzylol
zzylol changed the base branch from feat/shared-physical-operators to split/462-f-physical-planner September 30, 2026 02:07
zzylol added a commit that referenced this pull request Sep 30, 2026
#477 moved series-identity resolution into asap-types; #486 and #487 extended
the physical-layer copy. Port the extended rules into asap-types and keep
promql_rows delegating.

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