Skip to content

Implement IntersectsBbox to translate PostGIS && operator - #3484

Merged
roji merged 25 commits into
npgsql:mainfrom
bjornharrtell:intersects-bbox
Feb 2, 2026
Merged

roji merged 25 commits into
npgsql:mainfrom
bjornharrtell:intersects-bbox

Conversation

@bjornharrtell

@bjornharrtell bjornharrtell commented Mar 1, 2025 •

Copy link
Copy Markdown
Contributor

Implement a DbFunction to translate into PostGIS && operator.

Closes #3485

roji and others added 19 commits November 18, 2024 16:30
(cherry picked from commit 773a330)
To better handling reordering scenarios.

Fixes npgsql#3424

(cherry picked from commit c2b3de4)
(cherry picked from commit 3cbdba4)
@bjornharrtell

bjornharrtell commented Mar 1, 2025 •

Copy link
Copy Markdown
Contributor Author

I'm getting test failure:

Npgsql.EntityFrameworkCore.PostgreSQL.Query.SpatialQueryNpgsqlGeometryTest.IntersectsBbox(async: False) (24ms): Error Message: System.InvalidOperationException : The 'IntersectsBbox' method is not supported because the query has switched to client-evaluation. This usually happens when the arguments to the method cannot be
translated to server. Rewrite the query to avoid client evaluation of arguments so that method can be translated to server.

But at the same time I see:

SQL sent to the database:
       @__polygon_1='POLYGON ((0 0, 1 0, 0 1, 0 0))' (DbType = Object)
       
       SELECT p."Id", p."Polygon" && @__polygon_1 AS "IntersectsBbox"
       FROM "PolygonEntity" AS p

The generated SQL looks fine... so I'm quite confused about why the test is failing with what looks like something that should block SQL generation!?

@bjornharrtell

Copy link
Copy Markdown
Contributor Author

I understand now, in the case of DbFunction extensions I need to emulate a client side query in the test case. Should be foxed now.

@bjornharrtell
bjornharrtell marked this pull request as ready for review March 1, 2025 15:28
@bjornharrtell bjornharrtell changed the title Attempt to implement IntersectsBbox Implement IntersectsBbox to translate PostGIS && operator Mar 1, 2025
@bjornharrtell
bjornharrtell changed the base branch from hotfix/9.0.5 to main January 31, 2026 23:56
@bjornharrtell
bjornharrtell changed the base branch from main to hotfix/9.0.5 January 31, 2026 23:56
@bjornharrtell
bjornharrtell changed the base branch from hotfix/9.0.5 to main February 1, 2026 16:38
Copilot AI review requested due to automatic review settings February 1, 2026 16:41

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.

Pull request overview

This PR adds support for PostGIS's bounding box intersection operator (&&) by implementing an IntersectsBbox DbFunction. The implementation includes the function definition, query translation logic, and comprehensive test coverage.

Changes:

  • Added IntersectsBbox extension method to DbFunctions for checking bounding box intersections
  • Implemented translation to PostGIS && operator in the method call translator
  • Added test case validating the function behavior and SQL generation

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/EFCore.PG.NTS/Extensions/NpgsqlNetTopologySuiteDbFunctionsExtensions.cs Adds the IntersectsBbox DbFunction extension method
src/EFCore.PG.NTS/Query/ExpressionTranslators/Internal/NpgsqlNetTopologySuiteMethodCallTranslatorPlugin.cs Implements translation of IntersectsBbox to PostGIS && operator
test/EFCore.PG.FunctionalTests/Query/SpatialQueryNpgsqlGeometryTest.cs Adds test coverage for the new IntersectsBbox function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@roji roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@roji
roji enabled auto-merge (squash) February 1, 2026 20:29
@roji

roji commented Feb 1, 2026

Copy link
Copy Markdown
Member

@bjornharrtell note test failures, looks like you need to adjust the SQL assertion which changed since your wrote this.

Copilot AI review requested due to automatic review settings February 1, 2026 22:03
auto-merge was automatically disabled February 1, 2026 22:03

Head branch was pushed to by a user without write access

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.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bjornharrtell

Copy link
Copy Markdown
Contributor Author

@roji sorry, should be fixed now.

@roji
roji enabled auto-merge (squash) February 2, 2026 07:59
@roji
roji merged commit 98d0671 into npgsql:main Feb 2, 2026
10 checks passed
@roji

roji commented Feb 2, 2026

Copy link
Copy Markdown
Member

Thanks for your contribution!

@bjornharrtell
bjornharrtell deleted the intersects-bbox branch February 2, 2026 11:09
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.

Translation for PostGIS && operator

5 participants