Skip to content

fix(processor): scan an external rel table only after the first bound batch - #1529

Open
zahariash wants to merge 1 commit into
LadybugDB:mainfrom
zahariash:fix/arrow-pk-seed-first-scan
Open

zahariash wants to merge 1 commit into
LadybugDB:mainfrom
zahariash:fix/arrow-pk-seed-first-scan

Conversation

@zahariash

Copy link
Copy Markdown
Contributor

This work was produced with the help of language models.

Fixes #1527. Depends on #1528.

Over an Arrow rel table with p1→x1..x4 and p2→x3, MATCH (p:P {id: 2})-[:p_x]->(x:X) RETURN x.id returned 1, 2, 3, 3, 4 instead of 3, and {id: 3}, which has no rels, counted 4. A primary-key seed returned the rels of the node table's first node on top of its own, in either direction and in both the flat and CSR layouts, since 0.19.0.

Fix. ScanRelTable initialised non-native rel tables before pulling any child tuple, because its first scan() ran before the first pull. A primary-key seed's chunk already holds one row at that point, with offset 0 in its vector. The scan now waits until a bound batch is in place and initScanState has run for it, so the early init, which only made that first scan safe, is gone.

Tests. PrimaryKeySeedScansOnlyItsRels runs the issue's queries, a backward seed (1, 1, 2 for 1, 2) and a prepared $id re-executed with different values. PrimaryKeySeedOverNativeNodes does the same for the CSR layout (3 rows for 1), and ForkOverArrowRelTablesKeepsCrossProduct now also seeds a fork by primary key (48 for 24). All three fail on #1528's commit. The guard itself matters only for foreign and extension tables, which set up their scan in initScanState, and this repo has no tests for those. Full ctest: 3406/3406.

Cost. One branch per scan call, and one fewer initScanState per thread and execution. Alternating test builds on a graph of 2M nodes with 5 edges each, single-threaded instructions change by +1.30% on a filtered two-hop, inside its 4.7% run-to-run spread, and stay within 0.34% on the other queries.

This branch is on top of #1528, so its diff shows #1528's commit until that merges.

… batch

ScanRelTable initialised non-native rel tables before pulling any child
tuple, and its first scan() ran then too. A primary-key seed's chunk already
has one row at that point, with offset 0 in its vector, so the scan returned
that node's rels ahead of the real ones: over an Arrow rel table,
MATCH (p:P {id: 2})-[:p_x]->(x:X) returned x 1, 2, 3, 3, 4 instead of 3.

The scan now waits until a bound batch is in place and initScanState has run
for it, which also makes the early init unnecessary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@adsharma
adsharma force-pushed the fix/arrow-pk-seed-first-scan branch from b04e7f5 to e3d19a7 Compare November 11, 2026 01:15

This branch has not been deployed

No deployments
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: primary-key match over an Arrow rel table also returns the first node's rels

1 participant