Skip to main content

subquery_window

Function subquery_window 

Source
fn subquery_window(
    context: &Context<'_>,
    name: &str,
    function: RangeFunction,
    subquery: &SubqueryExpr,
) -> Result<NativeNode>
Expand description

Binds function over subquery, whose inner expression is evaluated on a grid of its own.

A range function folds a matrix, and PromQL writes a matrix two ways. A range selector reads raw samples from the scan; a subquery builds one by evaluating an expression. That is why this node declares input_grid: rate(x[5m:1m]) samples x at one-minute steps over the five-minute lookback, and the window folds those points rather than raw samples. The inner expression is compiled against the subquery’s grid for the same reason — a selector inside it has to land where the window will read it.

An @ anchor makes the subquery step-invariant: every output point reads the same interval, (anchor - offset - range, anchor - offset]. The child grid is built for that interval, while the output grid remains the statement’s grid; the anchor, range and offset are bound together in the window.