Skip to content

Pass 2: shared window grids (group-wide panes and long-window segments) #731

Open

Description

@zzylol

Problem, by example

Three PromQL panels over the same metric, all exact sums:

Query Repeats every
sum_over_time(m[5m]) 1 min
sum_over_time(m[1h]) 5 min
sum_over_time(m[365d]) 1 day

Today: the window-composition rule in Pass 2 (pane_candidates / window_composition_pass2_candidates) offers each query its own tumbling-pane chain, with pane width = its own repeat interval. That gives 5 × 1-min panes, 12 × 5-min panes and 365 × 1-day panes. These are three separate builds over the same rows, and every arriving row updates all three.

Expected: Pass 2 also offers shared window grids, and Stage 3 picks the cheapest:

  • Group-wide panes: one grid at the greatest common divisor of the group's pane widths (here 1 min), which the 5m and 1h windows both merge from.
  • Long-window segments: for long windows, coarse equal-width segments (e.g. 1-day or 1-year panes) that the year-long window merges from, instead of 365 or more fine panes.

Each query's per-query panes stay as candidates too.

Cause

Only per-query panes exist. A grid shared across queries, and segments for long windows, are not implemented.

Proposal (approved 2026-10-14)

  • Equal-width grids only. There is no end mask: an uneven segment such as 2y is stored as two 1y panes. PaneChain stays { pane_width, pane_count }.
  • The group-wide pane width is an extra Pass 2 candidate beside the per-query panes, and Stage 3 picks.
  • One "shared window grid" rule covers per-query panes, group-wide panes and long-window segments, with one coverage proof.
  • Grid candidates are limited to the deduplicated set {per-query, group gcd, segment grid}.

Earlier work is in draft PRs #628 (shared year-aligned segments), #632 (TimeShift/TimeRange pricing) and #634 (the planner chooses the segment grid). They predate the current stage code, so they should be reused for ideas rather than merged.

Scope / acceptance

  • For the example above, Pass 2 lists the group-wide 1-min grid and a segment grid in addition to the three per-query chains. The coverage proof accepts them, and Stage 3 prices them.
  • With one query per metric, Examples 1–4 select the same plans at the same costs as today.

Status / related

Deferred on 2026-10-16. Sliding windows and the Exponential Histogram are tracked separately in #522. Related draft PRs (left open): #628, #632, #634.

Activity

  1. added
    enhancementNew feature or request
    optimizerWorkload optimization and plan selection
    windowWindow functions, frames, panes, or temporal semantics
    on Oct 16, 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

    CSEenhancementNew feature or requestoptimizerWorkload optimization and plan selectionwindowWindow 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