Skip to content

[future work] Stage 1: window candidates with properties — tumbling window, sliding window with merge, sliding window with subtraction #1206

Open

Description

@zzylol

Future work. Not scheduled. It depends on #1160 (state groups) and #1203 (candidate properties).

Example

sum_over_time(http_requests_total[5m]), exact, every 1 min. Three window summaries can answer it (planner-layering.md, Appendix: Windows and window summaries):

Window summary How an evaluation is answered Needs
tumbling windows, width 1 min merge the newest 5 tumbling windows mergeable state
sliding window, length 5 min, slide 1 min read the one window that just completed; each sample updates 5 active windows nothing (works for non-mergeable summaries)
running sum with subtraction keep one running state; add the newest 1 min and subtract the 1 min that left the window invertible state (sum, count, Count-Min; not KLL, not max)
  • Today: only the first exists. The window-composition rule (extend_local_window_composition) and Pass 2's TumblingWindows rule build SummaryMerge ← SummaryTumblingWindowChain.
  • Sliding windows: no operator.
  • Subtraction: SummarySubtract is declared in the IR but reserved and unimplemented (crates/types/src/ir/operator/asap.rs:110).
  • Properties: the tumbling-window width and count are operator arguments, not properties a reader can require.

Representation, rules, enumeration

Formulation

A window state group $G^{W}$ is the state of an aggregate over the query's window $W$ (e.g. 5 min, aligned to the evaluation grid). Its candidates are window summaries, each $v = (e_v, p_v)$, where $p^{\log}_v$ extends $\theta_v$ with a window layout $\omega_v$:

Candidate $e_v$ $\omega_v$ Valid when
tumbling, merge SummaryMerge(newest n) ← SummaryTumblingWindowChain(w × N) (Tumbling, $w$) $w \mid W$ and $w \mid$ evaluation interval; mergeable
sliding, merge SummaryMerge ← SlidingWindowChain(L, s) (Sliding, $L$, $s$) $L \mid W$, $s \mid L$, $s \mid$ evaluation interval; mergeable if $L < W$
sliding, subtraction SummarySubtract(running, expired) over a tumbling chain of width $s$ (Subtractive, $s$) $s \mid$ evaluation interval; invertible state

Data structures and interfaces per stage

IR (crates/types/src/ir/operator/asap.rs):

  • SummarySlidingWindowChain { child, family, …, window_length_ms, slide_ms }, new;
  • SummarySubtract { left, right }, implemented: executor support and cost;
  • each node's guarantees and costs from formulas, like SummaryTumblingWindowChain.

Properties (#1203):

pub enum WindowLayout {
    Tumbling { width_ms: u64 },
    Sliding { length_ms: u64, slide_ms: u64 },
    Subtractive { slide_ms: u64 },
}
// `LogicalProperties.window_layout` (#1203, a dimension of p^log) gains the
// Sliding and Subtractive variants; `LogicalRequirement.window` (the reader's
// window and evaluation grid) already exists. No new flat enum of combinations.

Stage 1:

Stage 2: timing and lifetime per window candidate (#1200), like today's chains.

Cost (asap-cost):

  • sliding: ingestion work × active windows, and memory per window;
  • subtraction: two updates per slide and one running state.

Executor: sliding chains and SummarySubtract.

Current vs proposed

What Today Proposed
tumbling windows SummaryTumblingWindowChain + SummaryMerge(newest_tumbling_windows); rule TumblingWindows; candidates copied into the reader's group (#1160 moves them to the state group) candidates of $G^W$ with $\omega$ = Tumbling
sliding windows none SummarySlidingWindowChain, candidates with $\omega$ = Sliding
subtraction SummarySubtract reserved, unimplemented implemented; candidates with $\omega$ = Subtractive for invertible families
window layout operator arguments (tumbling_window_width_ms, tumbling_window_count) also $\omega_v$ in $p^{\log}$, which readers can require
reader's window need implied by the rule that built the candidate $r^{\log}$ = (window, grid)
invertibility not modeled capability per summary family

Scope and acceptance

Now: the design-doc section in planner-layering.md (windows appendix and Pass 2 rules) with the table above.

Later:

  • the IR nodes, rules, cost and executor support, one layout per PR;
  • acceptance: for the example, $G^W$ lists all three layouts, and Stage 3 picks the cheapest under the cost model.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestoptimizerWorkload optimization and plan selectionresearchResearch evaluation, ADR, or experimental designwindowWindow functions, frames, panes, or temporal semantics

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions