[SERVER-2057] $or with sort Created: 03/Nov/10  Updated: 18/May/12  Resolved: 03/Nov/10

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

Type: Question Priority: Major - P3
Reporter: Kyle Banker Assignee: Aaron Staple
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-1205 $or sort does not use index ranges ex... Closed
Participants:

 Description   

From the mailing list:
db.test.insert(

{ parts : ["part1", "part2", "part3", "part4"], priority : 2 }

);
db.test.insert(

{ parts : ["part4", "part5", "part6"], priority : 5 }

);
db.test.ensureIndex(

{ parts : 1, priority : -1 }

)

// Uses an index
db.test.find({$or : [{ parts :

{ $all : ["part1", "part2"] }

},

{ parts : "part4" }

]}).explain()

// Does not use an index
db.test.find({$or : [{ parts :

{ $all : ["part1", "part2"] }

},

{ parts : "part4" }

]}).sort(

{ priority : -1 }

).explain()

// Uses the index, but doesn't produce expected explain output
db.test.find({$or : [{ parts :

{ $all : ["part1", "part2"] }

},

{ parts : "part4" }

]}).sort(

{ priority : -1 }

).hint(

{parts: 1, priority: -1}

).explain()

// Here's the output (it's NOT in the form of the typical $or-like explain plan)
{
"cursor" : "BtreeCursor parts_1_priority_-1",
"nscanned" : 7,
"nscannedObjects" : 7,
"n" : 2,
"scanAndOrder" : true,
"millis" : 0,
"indexBounds" : {
"parts" : [
[

{ "$minElement" : 1 }

,

{ "$maxElement" : 1 }

]
],
"priority" : [
[

{ "$maxElement" : 1 }

,

{ "$minElement" : 1 }

]
]
}
}



 Comments   
Comment by Aaron Staple [ 03/Nov/10 ]

We already have SERVER-1205

Generated at Thu Feb 08 02:58:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.