Skip to content

fix(engine): bind all files when a SQL panel windows off the footer clock - #489

Merged
vishr merged 1 commit into
mainfrom
fix/sqlpanel-window-prune
Nov 16, 2026
Merged

vishr merged 1 commit into
mainfrom
fix/sqlpanel-window-prune

Conversation

@vishr

@vishr vishr commented Nov 15, 2026

Copy link
Copy Markdown
Member

The bug (#478)

SQL panels file-prune every telemetry relation in a statement to the panel's event-time window, using each signal's own event-time footer bounds — regardless of which column the statement actually windows on. A statement that windows on a non-default column ($__window(end_time), $__window(observed_time)), or that joins a windowed rollup to an unwindowed raw relation (spans/logs/metrics), silently dropped rows that fell outside the default prune window. This violated the read-window contract in internal/queryrows/window.go.

Root cause: bindSnapshot selected each signal's files with overlapping(b, signal, w), which tests the signal's clock (footer-sorted event-time) column against the window — even when the statement never bounds that column.

The fix

A raw signal is event-time pruned by the panel window only when the statement actually bounds that signal's own clock column with the window. Otherwise the signal binds every captured file (the allTime behaviour), so no row is dropped.

The windowed columns are captured at macro expansion (expandMacros), where each $__window(col) argument is unambiguous and already validated by the macro regex, and threaded to the engine via a dedicated context value (WithWindowColumns, mirroring the existing WithInventoryWindow). The engine prunes signal S only when a windowed column equals S.Clock() (bare) or names S's own relation (S.<clock>); an alias qualifier it cannot resolve stays unbounded (binds all files — correct, if slower).

Because the columns ride a separate context key rather than a new Window field, Window stays a comparable struct and every == allTime / != allTime site is unchanged. When no windowed columns are present (all non-SQL-panel internal readers), every signal keeps its existing clock-based pruning, so there is no behaviour change off the SQL-panel path. The metric-name prune now keys off the per-signal selected window, so it applies only when the metrics signal is genuinely window-bounded.

Tests

  • TestSQLPanelBindsAllFilesWhenWindowColumnIsNotTheFooterClock — reproduces the row loss: a span whose start_time is before the window but whose end_time is inside it is returned when the statement windows on end_time (failed before the fix: count=1 want 2).
  • TestSQLPanelPrunesFilesWhenWindowColumnIsTheFooterClock — proves the common case (bare $__window(start_time) on spans) still prunes to only the overlapping batch file, so there is no perf regression.
  • TestExpandMacros extended to assert the returned windowed columns.

gofmt -l internal/ empty, just vet clean, internal/engine and internal/query packages green, behavioral test-name check passes.

Known residual (follow-up, not a regression)

When one statement references the same signal both windowed and unwindowed, file selection is still per-signal (one pinned snapshot relation per signal), so the unwindowed reference shares the windowed selection. This case was equally pruned before this change; fixing it needs per-reference relations and is out of scope here.

Closes #478

…lock

SQL panels file-pruned every telemetry relation to the panel's event-time
window using each signal's own footer bounds, regardless of which column the
statement actually windowed on. A statement that windowed on a non-clock
column (e.g. $__window(end_time) or $__window(observed_time)), or that joined a
windowed rollup to an unwindowed raw relation, silently dropped rows that fell
outside the default prune window, violating the read-window contract.

A raw signal (spans/logs/metrics) is now event-time pruned only when the
statement bounds that signal's own event-time clock. The windowed columns are
captured at macro expansion, where each column is unambiguous, threaded through
the panel plan, and carried to bindSnapshot via a separate context value
(WithWindowColumns) so Window stays a comparable struct and allTime detection
is unchanged. When no windowed column resolves to a signal's clock -- bare clock
match, or a qualified reference to the signal's own relation -- that signal
binds every captured file instead of dropping rows; alias qualifiers that
cannot be confidently resolved stay unbounded, correct if slower. Metric-name
pruning now applies only when the metrics signal is genuinely window-bounded.

Non-SQL-panel reads set no windowed columns and keep their default clock-based
pruning, so the common dashboard panels (spans on start_time, logs on time,
metrics on time, rollups on bucket) prune exactly as before.

Closes #478
@vishr
vishr enabled auto-merge November 15, 2026 15:57
@vishr
vishr added this pull request to the merge queue Nov 15, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 15, 2026
@vishr
vishr added this pull request to the merge queue Nov 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 16, 2026
@vishr
vishr added this pull request to the merge queue Nov 16, 2026
Merged via the queue into main with commit 7a42d32 Nov 16, 2026
31 checks passed
@vishr
vishr deleted the fix/sqlpanel-window-prune branch November 16, 2026 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: SQL panels file-prune regardless of which relation carries $__window

1 participant