-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.0.6
-
Component/s: Querying
-
None
-
Environment:all
-
ALL
The execution plan generated for certain $or queries is amendable:
> db.domain.ensureIndex(
{ key: 1 } )
> db.domain.find( { $or: [
{ key:
}, { key:
{ $gte: 722156333548, $lt: 722156349325 }}, { key:
{ $gte: 722156416434, $lt: 722156433211 } },
{ key:
}
] } ).explain();
===>
{ clauses: [
{ cursor: "BtreeCursor key_1", ..., indexBounds:
},
{ cursor: "BtreeCursor key_1", ..., indexBounds:
},
{ cursor: "BtreeCursor key_1", ..., indexBounds:
},
{ cursor: "BtreeCursor key_1 multi", ..., indexBounds:
} ],
...
}
This is according to the docs but slow, nonetheless. I would expect the following plan
{ cursor: "BtreeCursor key_1 multi", ..., indexBounds:
{ key: [ [ -922337203685477, -922337203685477 ], [ -230584300921369, -230584300921369 ], [ -154023107256070, -154023107256070 ], [ 722156315770, 722156332548 ], [ 722156333548, 722156349325 ], [ 722156416434, 722156433211 ], [ 115292150460684, 115292150460684 ], [ 153726349067734, 153726349067734 ], [ 461172215037663, 461172215037663 ] ] }}
Which would almost halve the execution time (measured against a modified mongod where I patched the optimizer).
Instead of modifying the optimizer, an alternative could also be to extend $in to accept ranges as well.
- duplicates
-
SERVER-8743 add the ability for a query to match multiple arbitrary ranges within a single index
- Closed