-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Index Maintenance
-
Query Optimization
-
(copied to CRM)
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Setup:
> db.users.save({first_name:"Foo", ext_id :{ id:"6708526",type:2}});
> db.users.ensureIndex({'ext_id.id':1,'ext_id.type':1})
Using the dot-notation, the explain plan shows that the index is used:
> db.users.find({"ext_id.id":"6708526", "ext_id.type":2}).explain()
{
"cursor" : "BtreeCursor ext_id.id_1_ext_id.type_1",
"nscanned" : 1,
"nscannedObjects" : 1,
"n" : 1,
"millis" : 0,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"ext_id.id" : [
[
"6708526",
"6708526"
]
],
"ext_id.type" : [
[
2,
2
]
]
}
}
However, expressing the query with a document results in the index not being used:
> db.users.find({'ext_id':{'id':"6708526", 'type':2}}).explain()
{
"cursor" : "BasicCursor",
"nscanned" : 1,
"nscannedObjects" : 1,
"n" : 1,
"millis" : 0,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
}
}
If there are indexed fields representing any of embedded fields in the query, in dot-notation, they should be used. This can be done to filter out the documents needed before the exact embedded document matching is done for the actual query criteria.
- is duplicated by
-
SERVER-5904 embedded doc matches could use dotted field indexes
-
- Closed
-
-
SERVER-88831 Consider ixscan plan for comparisons to object literals
-
- Closed
-
- is related to
-
SERVER-5904 embedded doc matches could use dotted field indexes
-
- Closed
-