Repository navigation
Description
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, theSummaryTumblingWindowChainarm) takes its end offset from the readers above the chain (window_read_above). It does not include theTimeShiftbelow the chain, so it keeps rows in(T − 5m, T]. - The
Scanbelow reads the shifted range(T − 5m30s, T − 30s], becausewindow_read_aboveof the scan walks up through the shift. - A
TimeShiftpasses 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 son 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
- refactor(stage3): select over execution contexts: x_{κ,v}, y_{κ,u,c,i}, h_v and constraint (R) (#1207 PR 7) #1237: Stage 3's
stored_timesfor a query-time chain over a shift. - Tracking: implement the optimization formulation (memo candidates, properties, edges y_{u,c,i}, MILP) as named code per stage #1207: the refactor it belongs to.
Activity
zzylol commentedon Nov 15, 2026
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:
It uses the same data (
ais worthtminutes, one sample per minute) and runs in one query run with no view bound.a{}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_belowfor the shifts under the chain to the chain's own window, covers both cases.