Skip to content

[Bug] topk over rate/increase plans but fails installation: aggregate output names differ from measures #1303

Open

Description

@zzylol

Example

On main 9ad2c54, this one-query workload plans but cannot be installed:

{"query_workload": {"language": "promql", "repeating_queries": [{
  "query": "topk by (region) (4, increase(data_total[5m]))",
  "demand": {"fixed_interval_at": {"interval": 5000, "evaluation_phase": 0}},
  "requirements": {"accuracy": {"max_error": 0.05, "failure_probability": 0.3, "accuracy_scope": "whole_result"}},
  "predictability": {"predictable": {"known_at": null}}}]},
 "data_workload": {"arrival": {"ingesting": {"rows_per_second": 200000.0}},
  "sources": {"data_total": {"series_count": 10000, "metric_type": "counter", "sample_interval": 100}}}}

plan_installable returns:

Installable(QueryRunNotExecutable { reason: "invalid DAG: node 5: invalid DAG: aggregate output names differ from measures" })

The rate form, topk by (region) (4, rate(data_total[20m])), fails the same way. The error is the same with the default DeploymentCapabilities and with {"raw_data_retained": false}. Expected: an installable plan that returns the 4 series with the largest increase per region.

The selected DAG is:

0 Scan data_total
1 SummaryTumblingWindowChain ExactAggregate(Increase), PerEntity, 5 s windows
2 TimeRange 300 s
3 SummaryMerge
4 FinalizeExactAccumulator
5 Aggregate { reduction: Reduce([region]), measures: [TopK { k: 4 }], output_names: [] }

Current behavior

Planning succeeds and installation fails. Stage 3 does not compile candidates; plan_installable compiles only the selected plan, so no executable alternative is tried.

#1302 exposed this. Two sketch-plan workloads, random-mixed-seed-862-w02-q2-q7-mvp and random-mixed-seed-862-w01-q3-q8-mvp, were "selection MILP infeasible" on main because of their avg(quantile_over_time(...)) query. With #1302 that query plans, and the workloads now fail with this error from their second query, topk by (region) (4, increase(data_total[5m])) and topk by (region) (4, rate(data_total[20m])) respectively. Planned alone on main, before #1302, those topk queries already fail the same way.

Cause

Traced from the lowered IR and the selected DAG. There are two layers:

  1. Empty output_names (high confidence). The PromQL frontend builds the counter-ranking TopK aggregate with output_names: vec![] (crates/frontend-promql/src/promql.rs:1103, the Outer::TopK arm of the windowed path, about lines 1055–1109). The lowered root already shows output_names: []; resolve keeps it (crates/frontend-common/src/resolve.rs:430). The executor requires one name per measure: crates/executor/src/physical_planner/mod.rs:1075-1076 rejects with "aggregate output names differ from measures". Other builders use one empty name per measure, e.g. outer_aggregate at crates/frontend-promql/src/promql.rs:1641 (vec![String::new()]). The SQL/PromQL ranking promotion crates/frontend-common/src/canonicalize.rs:283 also builds TopK with output_names: Vec::new() and likely hits the same check (not run).
  2. No exact TopK aggregate in the executor (high confidence from reading the code, not run). Past the name check, compile's Aggregate arm maps only Count, Cardinality, FrequencyL2/Entropy, Sum, Avg, Min, Max and Quantile to a native reduction. AggIntent::TopK falls into _ => "aggregate intent has no native implementation" (crates/executor/src/physical_planner/mod.rs:1164-1167). So filling in the names alone would most likely turn this error into that one. The sketch-plan workload topk-rate-guarantees-ignored-mvp already fails with that message on main (node 7), which supports this.

Expected behavior and invariant

An Aggregate{[TopK{k}]} that Stage 3 can select is executable: it has one output name per measure, and the executor ranks the rows of each group by value and keeps the top k.

Proposal

  • Make the TopK builders emit one (empty) name per measure, like outer_aggregate. Alternatively, make the executor accept an empty list as "default names"; the planner-side schema code already treats a missing name as the intent-keyed default (aggregate_schema.rs, topk_output_name).
  • Add an exact TopK reduction to the executor's Aggregate compile (rank each group's rows by the sample value, keep k, keep the series' labels). This follows extending the executor rather than restricting the plan.

Minimal reproduction

plan_installable on the workload above (default PlanningModels::builtin()), on main 9ad2c54. The asap_planner CLI cannot show it today because it stops at todo!("#1207 PR 9 ...").

Impact

Every PromQL topk(k, rate|increase|irate(...)) with an exact plan fails at installation. A multi-query workload that contains one fails as a whole.

Regression test

A planner test that runs plan_installable on the workload above (and the rate form) and expects Ok. It fails today with QueryRunNotExecutable. An executor unit test compiles Aggregate{Reduce([region]), [TopK{k: 4}]} over a finalized increase and checks the 4 largest per region.

End-to-end verification

Re-plan random-mixed-seed-862-w02-q2-q7-mvp and random-mixed-seed-862-w01-q3-q8-mvp (with #1302) and regenerate their sketch-plan snapshots once asap_planner runs again.

Related: #1302 (exposed it), #1207.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpromqlPromQL front-end lowering (L1→L2)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions