Repository navigation
fix(or): seed an or branch whose expression reads an outer variable (#620) - #622
Merged
Merged
Conversation
…620) apply_or_clauses evaluated plain or / or-join branches from an empty binding and joined the union back onto the incoming rows. A branch whose expression reads a variable only the outer row binds -- [(> ?v 1)] after [?e :n ?v] -- saw it unbound and matched nothing, so the or dropped rows silently, in queries and in rule bodies. branch_outer_reads names the variables a branch's expressions (its own and its nested branches') read but the branch does not bind by a pattern, rule invocation or expression output. A branch with any now takes the seeded path: each incoming row seeds a plain or's branches, and an or-join's join variables seed its branches per row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
adityamukho
added a commit
that referenced
this pull request
Oct 18, 2026
…620) (#623) Backport of the v3 fix (#622). apply_or_clauses evaluated plain or / or-join branches from an empty binding and joined the union back onto the incoming rows. A branch whose expression reads a variable only the outer row binds -- [(> ?v 1)] after [?e :n ?v] -- saw it unbound and matched nothing, so the or dropped rows silently, in queries and in rule bodies. branch_outer_reads names the variables a branch's expressions (its own and its nested branches') read but the branch does not bind by a pattern, rule invocation or expression output. A branch with any now takes a seeded path: each incoming row seeds a plain or's branches, and an or-join's join variables seed its branches per row (a new per-row path on v2, the one v3 uses for metadata reads). Claude-Session: https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #620: an
or/or-joinbranch whose expression reads a variable only the outer row binds never matched, so theorsilently dropped rows, in queries and in rule bodies.Cause
apply_or_clausesevaluated each branch on its own, starting with nothing bound, and joined the union back onto the incoming rows. A branch's expression saw the outer variable unbound and dropped every row.or-joinwas affected the same way, though the issue only namesor.Fix
branch_outer_reads(executor.rs) finds the variables a branch's expressions, including those in nested branches, read but that the branch never binds through a pattern, a rule invocation or an expression output. A branch with any of these now takes the existing seeded path:or, each incoming row seeds the branches, as for branches withnot/not-join;or-join, each row's join variables seed the branches, as for branches that read metadata (Pseudo-attribute metadata depends on plan order #594).Rule bodies go through the same function, so they are fixed too.
Tests
tests/plan_independence_test.rsgains 5 tests: the issue's queries, a branch that binds a new variable from an outer one, nestedor,or-join, and rule bodies. Each runs throughexecuteand a cursor with reordering on and off. All 5 failed before the fix.test_branch_outer_reads.cargo test --features test-oracle: 1566 passed, 0 failed.cargo clippy -- -D warningsis clean.The v2.x backport to
mainfollows as a separate PR. #620 is a data-integrity issue, so this PR carries no closing keyword.🤖 Generated with Claude Code
https://claude.ai/code/session_01PtCdzbJMSS1V8qEPaJ4jXz