Skip to content

Sliding window execution: support multi-window merge/subtract in query engine #554

Description

@milindsrivastava1997

Problem

Sliding windows in the query engine today are not "tumbling with
configurable overlap" — they're a fundamentally narrower serving model. Per
asap_types::capability_matching::window_compatible
(capability_matching.rs:63-77):

match config.window_type {
    WindowType::Sliding => data_range_ms == window_ms,
    WindowType::Tumbling => data_range_ms.is_multiple_of(window_ms),
}

A sliding-window aggregation can only serve a query whose requested time
range matches the window's width exactly — no merge, no subtract, across
multiple stored overlapping windows. This is enforced live, on every query,
via find_compatible_aggregation() (called from both
simple_engine/promql.rs:1062 and simple_engine/sql.rs:503). Tumbling
windows have had multi-bucket merge support all along
(simple_engine/mod.rs's do_merge path); sliding never got the equivalent.

Concretely: rate(http_requests_total[5m]) refreshed every 60s has
data_range_ms = 300,000 but window_size_ms = 60,000 (derived from
t_repeat_ms, unrelated to the query's own range). Under sliding this is
rejected outright — not wrong data, just "no compatible aggregation," always.
The only naturally-compatible case today is a spatial-only query with no
range literal at all, which is also the least interesting case to slide.

This blocks #555 (a manual config override to choose tumbling vs.
sliding per experiment) from being safely shippable — enabling it today
would produce plans that fail at query time for almost any real workload
query.

Relationship to #405

#405 ("Optimization-based sketch/streaming config selection") already
documents Sliding: W < range_a → Infeasible as a deliberate v1 modeling
assumption
in its own feasibility table and cost formulas — not an
unimplemented case. This issue is effectively a proposal to extend that
formulation (and the corresponding query-engine implementation) to support
W < range_a for sliding windows via merge/subtract, the same way tumbling
already works. #405 remains the design/tracking issue for automatic
optimizer-driven selection generally; this issue is scoped specifically to
making sliding-window execution correct, independent of who chooses to use
one (the optimizer, or the manual override in #555).

What's already correct (not part of this issue)

The ingestion side already works and is tested:
precompute_engine/window_manager.rs's WindowManager correctly produces a
dense, Unix-epoch-aligned grid of overlapping window buckets, one every
slide_interval_ms, forever (closed_windows(), panes_for_window()).
The gap is entirely on the query-serving side.

Scope

Split into two sub-issues (linked below):

  1. Generating different sliding window candidates.
  2. Supporting sliding window candidates in the query engine (execution).

Also in scope, surfaced during design but not yet resolved:

  • planner/cleanup.rs's WindowType::Sliding branch (cleanup.rs:31-38)
    hardcodes a single-window read assumption (read_count_threshold = 1) and
    needs to become window-count-aware once multi-window sliding queries
    exist. It also skips the CleanupPolicy::NoCleanup check the Tumbling
    branch has — worth fixing alongside.
  • An unverified epoch/phase-alignment dependency for exact-match lookups:
    simple_engine/mod.rs:419-423 looks up a bucket at
    [end_timestamp - window_size_ms, end_timestamp] exactly, but
    align_end_timestamp_promql() (promql.rs:44-56) only aligns
    end_timestamp to the scrape interval, not to the aggregation's
    slide_interval_ms. Needs resolving as part of this work (either
    per-aggregation alignment, or changing exact-match to "nearest available
    window").

Definition of done

  • Sliding-window queries where data_range_ms is a multiple of
    window_size_ms (mirroring tumbling's existing rule) return correct data,
    via merge (mergeable sketch types) or subtract (subtractable types) across
    multiple stored buckets.
  • End-to-end correctness test: plan → run → query a sliding-window
    aggregation → assert correct results. (This is the test Manual windowing override (tumbling/sliding) in config.yaml #555
    explicitly defers to this issue.)

Related

Full technical trace (code locations, worked example, alignment analysis)
attached as a comment on this issue.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions