Skip to content

Fix chained array subscripts and nullable intersections - #4135

Merged
roji merged 1 commit into
mainfrom
roji-array-translation-fixes
Nov 17, 2026
Merged

roji merged 1 commit into
mainfrom
roji-array-translation-fixes

Conversation

@roji

@roji roji commented Nov 17, 2026

Copy link
Copy Markdown
Member

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 retains EXISTS (... 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

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>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 15:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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
roji enabled auto-merge (squash) November 17, 2026 15:22
@roji
roji disabled auto-merge November 17, 2026 15:28
@roji
roji merged commit f3b7ded into main Nov 17, 2026
16 checks passed
@roji
roji deleted the roji-array-translation-fixes branch November 17, 2026 15:28
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.

Array translations: chained Skip/Take return an empty array, int.MaxValue bounds overflow, and Intersect().Any() ignores NULL elements

2 participants