[fix] Preceding/following axes miss nodes when predicates add context tracking#6076
Open
joewiz wants to merge 1 commit intoeXist-db:developfrom
Open
[fix] Preceding/following axes miss nodes when predicates add context tracking#6076joewiz wants to merge 1 commit intoeXist-db:developfrom
joewiz wants to merge 1 commit intoeXist-db:developfrom
Conversation
Closed
3 tasks
4d294f1 to
c48b87a
Compare
duncdrum
approved these changes
Mar 3, 2026
…ext tracking Closes eXist-db#4109. When a context-dependent predicate like [exists(.)] is applied to the input expression of a FLWOR for clause or simple map operator, the self axis evaluation inside the predicate adds context tracking entries to each NodeProxy. These context entries then leak into the cached result nodes of subsequent selectPreceding/selectFollowing calls via copyContext(), causing a false-positive match in the context ID deduplication check. This makes the axis skip valid result nodes after the first match per group. The fix adds a NO_CONTEXT_ID guard to the context deduplication check in both selectFollowing and selectPreceding of NewArrayNodeSet. When contextId is NO_CONTEXT_ID, the step is not inside a predicate context tracking scope, so the deduplication check should not be applied. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
c48b87a to
a388cf8
Compare
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.
Closes #4109.
Problem
The
preceding::andfollowing::axes skip nodes when the input node set was produced by an expression with a context-dependent predicate. For example:The predicate
[exists(.)]is a no-op logically, but it triggers context tracking: theself::axis evaluation inside the predicate attaches a context entry to eachNodeProxyin the result set. When these nodes are later used as input topreceding::orfollowing::, the context entries leak throughcopyContext()into the axis result nodes. The context ID deduplication check inNewArrayNodeSet.selectPreceding()/selectFollowing()then sees a matching context ID and incorrectly skips valid result nodes, treating them as duplicates.Approach
The fix adds a
NO_CONTEXT_IDguard to the existingIGNORE_CONTEXTcheck in bothselectFollowing()andselectPreceding()ofNewArrayNodeSet. WhencontextIdisNO_CONTEXT_ID(meaning the axis step is not inside a predicate context tracking scope), the context-based deduplication check is skipped — the same behavior asIGNORE_CONTEXT.The change is two lines (one per method), following the same pattern already used elsewhere in the codebase where
IGNORE_CONTEXTandNO_CONTEXT_IDare treated as equivalent for dedup purposes.XQTS results
prod-AxisStepprod-AxisStep.followingprod-AxisStep.precedingNo regressions introduced.
Test plan
axes-persistent-nodes.xqmcovering bothpreceding::andfollowing::axes with context predicates, in both FLWOR and simple map formsprod-AxisStep,prod-AxisStep.following,prod-AxisStep.preceding: no regressions🤖 Generated with Claude Code