Projected live-view slaves can lose unflushed rows in window joins

perfloop-oss/questdb · Uncatalogued Mechanism

https://perfloop.ai/t/oss/case_bq0e5mexar

Verdict

VERIFIED · settled 2026-11-21 · pull request opened as questdb/questdb#8523

What happened: The check fails before this change and passes with it.

Hypothesis

A parallel window join can omit live-view rows that exist only in memory when its slave has a retained column-projection wrapper. Those unflushed rows are called the lead. The wrapper reports that it has no lead frames, preventing cache construction from adding them. This is a source-predicted row-loss mechanism, not an observed production incident.

At revision 954db6918113fdecb29eddf180449a5702b3a819, LiveViewRecordCursorFactory.java:80-84 and 508-526 explicitly support reading the lead through parallel WINDOW JOIN shared state. Its page-frame path returns a routed LiveViewPageFrameCursor when the tier is available, the projected columns are supported, and the slot and disk transaction fence agrees. LiveViewPageFrameCursor.hasLeadFrames returns true for a nonempty lead band at lines 355-360; toLeadFrames selects the lead-only walk at lines 590-594.

SelectedRecordCursorFactory.getPageFrameCursor wraps a table-backed base when needsProjection is true. Its private SelectedTablePageFrameCursor, lines 671-712, forwards the table reader, interval-filter flag, and partition positioning, but not hasLeadFrames or toLeadFrames. It therefore inherits TablePageFrameCursor.hasLeadFrames's false default. ConcurrentTimeFrameState.of calls addLeadFrames at line 262, but that helper returns immediately on this false flag. The metadata-based branch models disk partitions only. The eager interval branch also cannot rescue the rows: buildFrameCacheEagerly skips frames whose partition index is outside the disk reader's partition count before the same lead helper runs. On a successful build with the retained wrapper, the lead is absent from the shared model.

The scope is a retained physical-column projection over a routed live-view slave with a nonempty lead, not every projection or every live-view read. A simple reorder can be folded into the scan, as LiveViewInMemReadTest.java:980-989 explains. A duplicate alias supplies a concrete eligibility check: WINDOW JOIN (SELECT ts, x, x AS x0 FROM lv) l, with both sum(l.x) and sum(l.x0) requested. buildQueryMetadata builds physical-name scan metadata at SqlCodeGenerator.java:2071-2162, the live-view layer wraps that scan at lines 12245-12254, and generateSelectChoose preserves differing logical output through SelectedRecordCursorFactory at lines 9933-10117. Its needsProjection test retains duplicate cross-index mappings. WindowJoinTest.java:5129-5143 already uses the analogous duplicate-price slave projection to exercise SelectedConcurrentTimeFrameCursor. A page-frame master, parallel-enabled context, and parallel-capable sums satisfy the join's gate at lines 6906-6909.

The Case check is LiveViewInMemReadTest.testProjectedWindowJoinSlaveSeesUnflushedLead, extending the existing buildFlushedPlusLead fixture and testWindowJoinSlaveSeesTheUnflushedLead. That fixture has disk values 1, 2, 3 and unflushed lead values 4, 5. Keep its probe and ten-second window, add the duplicate-alias slave projection, and assert a retained SelectedRecordCursorFactory above LiveViewRecordCursorFactory with a routed, nonempty lead. Both sums must be 15; the predicted omission gives 6. Preserve the direct-live-view result as a regression control, and exercise the eager interval branch separately to guard the same forwarding contract. If the projection is eliminated, that query does not exercise this mechanism; if the retained wrapper exposes the lead correctly and the sums remain complete, the prediction is rejected.

The existing direct-live-view bridge and its tests do not cover the separate projection dispatch that hides its capability. README.md:125-136 documents live views and WINDOW JOIN as current engine features. The requested repair forwards already-existing internal cursor methods, with no new consumer-visible configuration or protocol. Target-specific retirement plans remain unestablished.

Change to test: Forward the existing lead-frame capability and lead-only positioning through SelectedTablePageFrameCursor while retaining its column remapping. This lets shared time-frame cache construction include the pinned live-view rows without adding a SQL operation or cursor API.

Where it lives

perfloop-oss/questdb · core/src/main/java/io/questdb/griffin/engine/join/AsyncWindowJoinRecordCursor.java

Evidence

The check fails before this change and passes with it: `For the flushed-prefix-plus-lead fixture, a parallel WINDOW JOIN over a retained duplicate-alias live-view slave with an aligned slot/disk fence, a routed nonempty lead, and a ten-second window covering all five rows must return exactly columns ts, agg, and agg0 with the single row ts=2026-05-12T00:00:03.000000Z, agg=15, agg0=15 on both cursor reads.`

The check fails before this change and passes with it: `For the flushed-prefix-plus-lead live-view fixture, a constant-false WINDOW JOIN null-column projection must expose exactly the two unflushed lead rows through its table page-frame cursor lead-only walk.`

Checks: 1 of 1 passed. Verification: no defect found.

Timeline