[SERVER-73242] Partial index with $geoWithin filter crashes when querying a big polygon document Created: 24/Jan/23  Updated: 08/Aug/23

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ivan Fefer Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File geo_big_polygon_index.js    
Issue Links:
Problem/Incident
is caused by SERVER-58359 More flexible query containment for $... Closed
Related
is related to SERVER-57763 Allow partial filter expression to us... Closed
is related to SERVER-73235 Replace invariant with uassert in geo... Closed
Assigned Teams:
Query Execution
Operating System: ALL
Sprint: QE 2023-02-06, QE 2023-02-20, QE 2023-03-06, QE 2023-03-20, QE 2023-04-03, QE 2023-04-17, QE 2023-05-01
Participants:
Linked BF Score: 127

 Description   

jstest to reproduce the issue is attached.

Imagine we create an index with partial filter expression {location: $geoWithin: <polygonA>}.
And query the collection with filter {location: $getWithin: <polygonB>}.

During planning, isSubsetOf(index filter expression, query expression) will be called to determine if index can be used.

It will check if polygonB is inside polygonA: https://github.com/mongodb/mongo/blob/04299d14a33a89023b6bc69d8d59a618aa603e5d/src/mongo/db/matcher/expression_algo.cpp#L750

GeoMatchExpression::matchesGeoContainer has an explicit check to never match big polygon, which fails for some reason
https://github.com/mongodb/mongo/blob/04299d14a33a89023b6bc69d8d59a618aa603e5d/src/mongo/db/matcher/expression_geo.cpp#L415

And GeometryContainer::contains is called that fails if the other container is a big polygon:
https://github.com/mongodb/mongo/blob/04299d14a33a89023b6bc69d8d59a618aa603e5d/src/mongo/db/geo/geometry_container.cpp#L322

It looks like the bug can be triggered easier by just inserting a document with big polygon and querying if it is within another geometry, but for some reason, the only way this actually breaks in partial index filter.



 Comments   
Comment by Ivan Fefer [ 26/Jan/23 ]

I suspect that the bug hides somewhere here when we unconditionally convert big polygon to regular polygon. https://github.com/mongodb/mongo/blob/cc0dc721042c7ffa2d00a0f414d65c650f646918/src/mongo/db/geo/shapes.cpp#L879

 

Generated at Thu Feb 08 06:24:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.