Skip to content

Executor: a query-time chain over a TimeShift ignores the shift in its own window #1336

Open

Description

@zzylol

Problem, by example

Take a plan built at query time:

FinalizeExactAccumulator
  SummaryMerge
    TimeRange(5m)
      SummaryTumblingWindowChain(width 60 s, exact sum per job)
        TimeShift(30s)
          Scan(latency)

The data has two series, a and b, with one sample per minute over (0, 4h]; a is worth t minutes and b twice that. The query reads the shifted series' last 5 minutes, which is the raw window (T − 5m30s, T − 30s].

Evaluation time T Expected a (raw samples in (T − 5m30s, T − 30s]) Returned a
4 h 1185 (samples at T − 5m … T − 1m) 950 (samples at T − 4m … T − 1m)
4 h − 30 s 1185 1185

The numbers come from a throwaway test in crates/executor/tests/tumbling_window_chain.rs, modeled on a_chain_built_at_query_time_answers_queries_through_its_time_ranges with shift(30_000, None, scan()) as the chain's child.

Why it happens

  • The query-time chain's own window filter (physical_planner/mod.rs, the SummaryTumblingWindowChain arm) takes its end offset from the readers above the chain (window_read_above). It does not include the TimeShift below the chain, so it keeps rows in (T − 5m, T].
  • The Scan below reads the shifted range (T − 5m30s, T − 30s], because window_read_above of the scan walks up through the shift.
  • A TimeShift passes rows through without moving their times, so the two windows overlap only on (T − 5m, T − 30s]. At T = 4 h one sample is lost.
  • The window ends are stamped at T − k·60 s on the unshifted times.
  • At ingestion time the chain builds the window ending at the run's end, and the planner refreshes it at phase s mod w (RefreshWindow::computed_from), which is consistent.

Proposal

Include the shifts below a query-time chain (shift_back_ms_below of the chain) in its window filter's end offset. Stamp window ends so that a TimeRange above selects them as it selects the windows of a stored chain over the same shift. In Stage 3, a query-time chain over TimeShift(s) is stored at phase s mod w (PhysicalASAPMemoCandidates::stored_times), so the planner offers it only to readers at that phase.

Scope and acceptance

  • In scope: the executor's query-time chain over shifts.
  • Acceptance: the test above returns 1185 at T = 4 h and at T = 4 h − 30 s, equal to the direct sums over the shifted window, with samples placed so that a 30 s error changes the answer at both times.

Related

Activity

  1. added
    bugSomething isn't working
    windowWindow functions, frames, panes, or temporal semantics
    on Nov 15, 2026
  2. zzylol commented on Nov 15, 2026

    @zzylol
    ContributorAuthor

    The fix for #1338 (#1344) widens this bug. A tumbling-window chain placed at ingestion time but compiled with its view not bound (for example, a plan run from raw samples in one query run) is now built for its readers, through the same window code as a query-time chain. So it now has this bug too.

    Repro: the plan from the issue body, with the chain made an unbound ingestion-time view:

    Finalize(Merge(TimeRange(5m, Chain(1m, TimeShift(30s, Scan)))))
    

    It uses the same data (a is worth t minutes, one sample per minute) and runs in one query run with no view bound.

    T Expected a Before #1344 With #1344
    4 h 1185 {} 950
    4 h − 30 s 1185 1185

    The query-time form of the same DAG returns 950 on both builds. That is the bug this issue describes.

    The fix described here, adding shift_back_ms_below for the shifts under the chain to the chain's own window, covers both cases.

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

    bugSomething isn't workingwindowWindow 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