Skip to content

Fix GIN index detection for views#3879

Merged
roji merged 2 commits into
mainfrom
roji-fix-view-indexes
Jul 10, 2026
Merged

Fix GIN index detection for views#3879
roji merged 2 commits into
mainfrom
roji-fix-view-indexes

Conversation

@roji

@roji roji commented Jul 10, 2026

Copy link
Copy Markdown
Member

ToView mappings use view columns rather than table columns, so the index-aware array Contains translation did not find a modeled GIN index and fell back to ANY.

Inspect indexes through the column property's model metadata, which supports both table and view mappings while retaining the existing first-indexed-property and GIN-method requirements. Adds a focused ToView translation regression test.

Fixes #3829

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 10, 2026 08:14
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes PostgreSQL array Contains translation to detect modeled GIN indexes even when the entity is mapped via ToView(), by looking up indexes from the mapped CLR property’s model metadata rather than from table-only metadata. This ensures view-mapped queries can still translate to the @> containment operator (which can leverage the underlying index) instead of falling back to ANY.

Changes:

  • Update GIN index detection for array-column Contains translation to work for both table and view mappings by inspecting indexes via the column’s mapped property metadata.
  • Add a focused regression test asserting that ToView() mappings still translate Contains to @> when a GIN index is configured.
Show a summary per file
File Description
test/EFCore.PG.FunctionalTests/Query/PrimitiveCollectionsQueryNpgsqlTest.cs Adds a regression test covering ToView() + GIN index detection for array Contains translation.
src/EFCore.PG/Query/Internal/NpgsqlQueryableMethodTranslatingExpressionVisitor.cs Adjusts GIN index detection logic to use property-based index metadata (works for views) instead of table index metadata.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Low

Copilot AI review requested due to automatic review settings July 10, 2026 08:18
@roji roji enabled auto-merge (squash) July 10, 2026 08:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Low

@roji roji merged commit affe2c7 into main Jul 10, 2026
16 checks passed
@roji roji deleted the roji-fix-view-indexes branch July 10, 2026 08:32
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.

Views with underyling indicies are not used in translation

2 participants