[SERVER-79599] Geospatial Query Error on MongoDB Version 6.3.2 Created: 02/Aug/23  Updated: 29/Oct/23  Resolved: 10/Aug/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 6.3.2
Fix Version/s: 7.1.0-rc0, 7.0.2

Type: Bug Priority: Major - P3
Reporter: APURV VINUBHAI BRAHMBHATT Assignee: Irina Yatsenko (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File test_query.js    
Issue Links:
Backports
backported by SERVER-63349 Modify QueryPlanner and IndexBoundsBu... Closed
Assigned Teams:
Query Integration
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v7.0
Steps To Reproduce:

Use sample_geospatial.shipwrecks collection and perform attach query operation on the sample data.  

Sprint: QI 2023-08-07, QI 2023-08-21
Participants:

 Description   

We have encountered an issue while executing geospatial queries on MongoDB version 6.3.2. The error message "Union requires two index intervals" is being thrown, and this seems to be specific to instances running MongoDB 6.3.2 with a 2D sphere index created. It's important to note that this error does not occur when the query performs a COLLSCAN operation.

Furthermore, we have identified that the issue arises when the query involves a compound operation of geospatial and other equality operations. However, if we remove the non-geospatial condition from the query, it executes successfully without any errors.

The problem is observed on both Atlas serverless and dedicated instances running MongoDB version 6.3.2. Notably, we have verified that this error is not present in MongoDB versions 6.0.8 and 5.0.19.



 Comments   
Comment by Githook User [ 31/Aug/23 ]

Author:

{'name': 'Irina Yatsenko', 'email': 'irina.yatsenko@mongodb.com', 'username': 'IrinaYatsenko'}

Message: SERVER-79599 don't auto-parameterize queries executed in classic engine

(cherry picked from commit 27232edfa918dc843b4f46991a98623e7d4aece7)
Branch: v7.0
https://github.com/mongodb/mongo/commit/d29f6dc673dd9653f8d8b64904e781b7f77822ce

Comment by Githook User [ 10/Aug/23 ]

Author:

{'name': 'Irina Yatsenko', 'email': 'irina.yatsenko@mongodb.com', 'username': 'IrinaYatsenko'}

Message: SERVER-79599 don't auto-parameterize queries executed in classic engine
Branch: master
https://github.com/mongodb/mongo/commit/27232edfa918dc843b4f46991a98623e7d4aece7

Comment by Irina Yatsenko (Inactive) [ 09/Aug/23 ]

Note: the same assert would fire for a query that has a top-level $or with 2+ geo expressions and any "parameterizable" expression such as $eq.
Due to the presence of the parameterizable expression the query as a whole is considered to be parameterized which triggers creation of interval builders, but the geo expressions aren't integrated with the interval builders.

db.geo.explain().find({$and: [
	{$or : [
		{loc: {$geoWithin: {$geometry: {type: "Polygon", coordinates: [[[-71, 42], [-80, 30], [-60, 37], [-71, 42]]]}}}}, 
		{loc: {$geoWithin: {$geometry: {type: "Polygon", coordinates: [[[-81, 42], [-70, 30], [-65, 37], [-81, 42]]]}}}}
	]},
	{val: 42}
]})
 
The assert happens in this stack:
#0  mongo::QueryPlannerAccess::processIndexScans  src/mongo/db/query/planner_access.cpp:1313
	root is the full $and expression
	scanState.ietBuilders is empty on entry
#1  mongo::QueryPlannerAccess::buildIndexedAnd  src/mongo/db/query/planner_access.cpp:1603
#2  mongo::QueryPlannerAccess::_buildIndexedDataAccess  src/mongo/db/query/planner_access.cpp:1876
#3  mongo::QueryPlannerAccess::buildIndexedDataAccess  src/mongo/db/query/planner_access.cpp:1863
#4  mongo::QueryPlanner::plan  src/mongo/db/query/query_planner.cpp:1444
#5  mongo::_anon_::PrepareExecutionHelper<...> at src/mongo/db/query/get_executor.cpp:873
#6  mongo::_anon_::getClassicExecutor  src/mongo/db/query/get_executor.cpp:1312
#7  mongo::getExecutor src/mongo/db/query/get_executor.cpp:1674
#8  mongo::getExecutor src/mongo/db/query/get_executor.cpp:1615
#9  mongo::getExecutorFind
 
Then recurse into the expression:
#0  mongo::QueryPlannerAccess::processIndexScans  src/mongo/db/query/planner_access.cpp:1315
	root: "{ $or: [ { loc: { $geoWithin: { $geometry: { type: \"Polygon\", coordinates: [ [ [ -71.0, 42.0 ],…
	scanState.ietBuilders are still empty on entry
	Processing the first term/child of the $or, calls scanState.resetForNextScan(scanState.ixtag, query.isParameterized());
       and query.isParameterized() is true, so it creates interval builder but because this is a GEO expr it doesn't set the intervals.
#1  mongo::QueryPlannerAccess::buildIndexedOr  src/mongo/db/query/planner_access.cpp:1736
#2  mongo::QueryPlannerAccess::_buildIndexedDataAccess  src/mongo/db/query/planner_access.cpp:1879
#3  mongo::QueryPlannerAccess::processIndexScansSubnode  src/mongo/db/query/planner_access.cpp:1580
#4  mongo::QueryPlannerAccess::processIndexScans  src/mongo/db/query/planner_access.cpp:1338
	at this point: the root arg is "{ $and: [ { val: { $eq: 42.0 } } ] }"
#5  mongo::QueryPlannerAccess::buildIndexedAnd  src/mongo/db/query/planner_access.cpp:1603
#6  mongo::QueryPlannerAccess::_buildIndexedDataAccess  src/mongo/db/query/planner_access.cpp:1876
#7  mongo::QueryPlannerAccess::buildIndexedDataAccess  src/mongo/db/query/planner_access.cpp:1863
#8  mongo::QueryPlanner::plan  src/mongo/db/query/query_planner.cpp:1444
#9  mongo::_anon_::PrepareExecutionHelper<...>  at src/mongo/db/query/get_executor.cpp:873
#10 mongo::_anon_::getClassicExecutor  src/mongo/db/query/get_executor.cpp:1312
#11 mongo::getExecutor src/mongo/db/query/get_executor.cpp:1674
#12 mongo::getExecutor src/mongo/db/query/get_executor.cpp:1615
#13 mongo::getExecutorFind
 
The query is set to be parameterized in the following stack due to the non-geo term:
#0  mongo::MatchExpressionParameterizationVisitorContext::nextInputParamId  src/mongo/db/matcher/expression_parameterization.h:78
#1  mongo::MatchExpressionParameterizationVisitorContext::nextReusableInputParamId  src/mongo/db/matcher/expression_parameterization.h:70
#2  mongo::MatchExpressionParameterizationVisitor::visitComparisonMatchExpression  src/mongo/db/matcher/expression_parameterization.cpp:129
#3  mongo::MatchExpressionParameterizationVisitor::visit  src/mongo/db/matcher/expression_parameterization.cpp:62
#4  mongo::EqualityMatchExpression::acceptVisitor  src/mongo/db/matcher/expression_leaf.h:319
	processing "{ val: { $eq: 42.0 } }"
#5  mongo::MatchExpressionParameterizationWalker::preVisit  src/mongo/db/matcher/expression_parameterization.h:204
#6  mongo::tree_walker::walk<false, mongo::MatchExpression, mongo::MatchExpressionParameterizationWalker>  src/mongo/db/query/tree_walker.h:61
#7  mongo::tree_walker::walk<false, mongo::MatchExpression, mongo::MatchExpressionParameterizationWalker>  src/mongo/db/query/tree_walker.h:69
#8  mongo::MatchExpression::parameterize at src/mongo/db/matcher/expression.cpp:130
	tree: "{ $and: [ { $or: [ { loc: { $geoWithin: { $geometry: { type: \"Polygon\", coordinates: [ [ [ -71.0,…
#9  mongo::CanonicalQuery::init

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