[SERVER-26413] Hinting an incompatible partial index can return incomplete results Created: 30/Sep/16  Updated: 13/Dec/23

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

Type: Bug Priority: Major - P3
Reporter: Chris Harris Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 3
Labels: query-44-grooming, quick-wins-candidates, tech-debt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-62362 Hints are allowed on special indexes ... Open
related to SERVER-18449 Hinting sparse index without sparse-c... Backlog
related to SERVER-32540 Make partial index subset analysis co... Backlog
is related to SERVER-1599 support ability to pass hint to update Closed
Assigned Teams:
Query Execution
Operating System: ALL
Steps To Reproduce:

> c = db.col
test.col
> c.drop()
false
> c.insert({x:100})
WriteResult({ "nInserted" : 1 })
> c.createIndex({x:1},{partialFilterExpression:{y:{$exists:true}}})
{
	"createdCollectionAutomatically" : false,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> 
> 
> c.find({x:100})
{ "_id" : ObjectId("57ee96b1d2002c23be038661"), "x" : 100 }
>
> c.find({x:100}).hint({x:1})
> 

Participants:
Case:

 Description   

The database currently allows for partial indexes to be hinted regardless of the filters applied to the query. When these filters do not align with the partialFilterExpression for an index, there may be documents that match the query but are not included in the index. Forcing index usage via a hint in such a scenario will lead to the database returning incomplete results (a silent logical failure).

Returning an error is probably the most correct thing to do. Alternatively, the hint could be rejected and the standard plan generation process could be observed.



 Comments   
Comment by Ralf Strobel [ 26/Jul/23 ]

Just for the record, this is still present in MongoDB 6.0 and just took two of our developers over a day to figure out what was happening. Would it really be so difficult to return an error when an inappropriate index is being forced accidentally?

Generated at Thu Feb 08 04:12:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.