Repository navigation
Description
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:
- Empty
output_names(high confidence). The PromQL frontend builds the counter-rankingTopKaggregate withoutput_names: vec. The lowered root already showsoutput_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-1076rejects with"aggregate output names differ from measures". Other builders use one empty name per measure, e.g.outer_aggregateatcrates/frontend-promql/src/promql.rs:1641(vec![String::new()]). The SQL/PromQL ranking promotioncrates/frontend-common/src/canonicalize.rs:283also buildsTopKwithoutput_names: Vec::new()and likely hits the same check (not run). - No exact
TopKaggregate in the executor (high confidence from reading the code, not run). Past the name check,compile'sAggregatearm maps only Count, Cardinality, FrequencyL2/Entropy, Sum, Avg, Min, Max and Quantile to a native reduction.AggIntent::TopKfalls 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 workloadtopk-rate-guarantees-ignored-mvpalready 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
TopKbuilders emit one (empty) name per measure, likeouter_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
TopKreduction to the executor'sAggregatecompile (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.
Activity
fix(accuracy): relative error through sum and avg of values of one si…
fix(types): document one output name per measure; name both counts in…
fix(frontend): name every aggregate measure and validate names match …