Repository navigation
Fix chained array subscripts and nullable intersections - #4135
Merged
Merged
Conversation
Parenthesize slices before further indexing or slicing, and preserve INTERSECT null semantics when both inputs have nullable elements. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the array-query translation changes.
No open issues 🎉
What changed in this PR
Fixes two array-query translation issues in the PostgreSQL EF Core provider: chained subscripts and nullable Intersect().Any() results. Overflow handling remains unchanged, as agreed for #4098.
Changes:
- Parenthesizes inner array slices so subsequent slicing or indexing operates on their results.
- Preserves
EXISTS (... INTERSECT ...)when both inputs may contain null elements, while retaining the overlap optimization otherwise. - Adds regression tests with result checks and exact SQL assertions.
| File | Description |
|---|---|
| test/EFCore.PG.FunctionalTests/Query/PrimitiveCollectionsQueryNpgsqlTest.cs | Tests chained slicing, indexing after slicing, and nullable intersections. |
| src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs | Adds parentheses around slices used by subsequent subscripts. |
| src/EFCore.PG/Query/Internal/NpgsqlQueryableMethodTranslatingExpressionVisitor.cs | Guards the array-overlap optimization using element nullability. |
Review effort: Balanced
roji
enabled auto-merge (squash)
November 17, 2026 15:22
roji
disabled auto-merge
November 17, 2026 15:28
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.
Chained array slicing/indexing can return empty arrays or arrays where scalars are expected because PostgreSQL interprets consecutive subscripts as multidimensional access. Parenthesize the inner slice so subsequent subscripts operate on its result.
Intersect().Any()now retainsEXISTS (... INTERSECT ...)when both inputs can contain null elements, since array overlap (&&) does not match nulls. The&&optimization remains when either input has non-nullable elements. Adds focused regression coverage for both fixes.Overflow handling is deliberately unchanged, including constant bounds, as agreed on the issue.
Fixes #4098