Skip to content

[Bug] Stage 3 selects plans over a query's latency bound and plans whose evaluation outlasts the repeat interval #1432

Open

Description

@milindsrivastava1997

Related: #859 (the check this restores), #1316 (latency as an objective), #1314 (latency estimates 13–900× low).

Example

tools/dag-viewer/workloads/planner-layering/example3b.json:
quantile_over_time(0.99, latency_ms[5m]) every 60 s, rank ε = 0.01,
max_latency_ms: 200, 1,000,000 series at 15 s, raw data retained.

  • Today: Stage 3 selects the exact plan Scan → TimeRange 300s → Aggregate quantile, all at query time. The cost model's own estimate for
    the Aggregate is 6780 ms per evaluation ("hash aggregate 20000000 rows into
    1000000 groups … holds 192000000 bytes for 6780.000 ms"), 34× the bound.
  • Expected: Stage 3 rejects that plan with LatencyBoundExceeded and
    selects a plan within 200 ms, or selects no plan and says why.

A second case, with no latency bound: random-mixed seed-862 workload-01
(raw data not retained, AWS Fargate cost model), query every 1 s. Its plan
has two query-time SummaryMerges at about 2.5 s per evaluation, so
evaluations cannot keep up. This should be rejected with
LatencyOverRepeatInterval, which #859 added.

Current behavior

RejectionCause::LatencyBoundExceeded and LatencyOverRepeatInterval
(crates/stage3-plan-selection/src/report.rs:70) are declared but never
constructed. The checks that produced them were removed in #1226 (#1207
PR 0) and not reinstated in the MILP selection (#1236). max_latency_ms is
validated on input (crates/types/src/workload/query.rs:559) and otherwise
ignored.

Of 15 small workloads planned (3 examples, 7 memo examples, random-mixed
01–05), 8 select a plan with a query-time node slower than its query's
repeat interval.

Expected behavior and invariant

For every selected plan and every query q:

  • if q has max_latency_ms, predicted latency(q) ≤ max_latency_ms;
  • if q repeats at interval I, predicted latency per evaluation ≤ I.

"Predicted" is the cost model's QueryLatency (crates/cost/src/plan/cost.rs).
Its known underestimate is #1314; this issue is only about using it.

Minimal reproduction

asap_planner --workload tools/dag-viewer/workloads/planner-layering/example3b.json \
  --run-until stage3 --format json --out 3b.json
# stage3_plan_selection.cost.per_node["2"].detail: "... for 6780.000 ms"

Impact

Plans that a deployment cannot run within its SLO, or cannot keep up with,
are reported as selected. It also changes which plan wins: the
user guide's claim that a KLL plan wins example 3b relies on this check.

Regression test

Stage 3 over example 3b: the selected plan's predicted latency for q1 is
≤ 200 ms (fails today). And a repeating query whose only plan is slower than
its interval selects no plan, with LatencyOverRepeatInterval (fails today).

Open question

Should the check be MILP constraints (a latency row per query) or a filter
on candidates before the MILP? The latency of a query depends on the whole
selected subgraph it reaches, so a per-candidate filter may be insufficient.

End-to-end verification

Re-plan the examples and random-mixed 01–05; no selected plan breaks either
invariant. Corpus snapshots that change are listed with why.

Activity

  1. added
    bug
    optimizer
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugoptimizer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions