[SERVER-16380] Index scans on unique indexes check to see if they should advance Created: 02/Dec/14  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: 2.8.0-rc1
Fix Version/s: None

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

Issue Links:
Related
related to SERVER-16891 Special handling of "idhack" queries ... Backlog
Assigned Teams:
Query Execution
Participants:

 Description   

Currently, when scanning any index for a number of given ranges (unique or not) we check after each found value to confirm if there is a match or we should advance the range.

If we are using a unique index (or a field which can be confirmed to be unique by the presence of another unique index) we don't need to perform this extra check, as there can only be one matching value.

Simple reproducer

 
for(i=0;i<101;i++){db.t2.insert({x:i})} 
db.t2.ensureIndex({x:1}, {unique:true}) 
db.t2.find({x:{$in:[3,50,74,100]}}).explain(true) 

 
.... "keysExamined" : 7, 


Generated at Thu Feb 08 03:40:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.