-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Index Maintenance
-
None
-
Fully Compatible
-
Query 2017-01-23
-
(copied to CRM)
In this example, I want to get a list of user names for a particular event.
> db.col2.insert({name: "ag", event: ["open", "tourney"]}) > db.col2.insert({name: "joe", event: ["match", "event"]}) > db.col2.insert({name: "bill", event: ["open", "event"]}) > db.col2.ensureIndex({event: 1, name: 1}) > db.col2.find({event: "open"}, {name: 1, _id: 0}) { "name" : "ag" } { "name" : "bill" } > db.col2.find({event: "open"}, {name: 1, _id: 0}).explain() { "cursor" : "BtreeCursor event_1_name_1", "nscanned" : 2, "nscannedObjects" : 2, "n" : 2, "millis" : 0, "nYields" : 0, "nChunkSkips" : 0, "isMultiKey" : true, "indexOnly" : false, "indexBounds" : { "event" : [ [ "open", "open" ] ], "name" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ] } }
See that multikey is true even though the requested field (name) is not multikey.
Since we already track duplicate doc location, it should be easy to use covered index to return just name info.
That could speed up a lot certain queries.
We could move multiKey flag at the field level, and decide based on what is returned.
An alternative would be to add a hint flag to force covered index.
In this case output would be same.
In case of a true multikey, the array could be incomplete or with wrong order, but that would be expected.
- is duplicated by
-
SERVER-7595 indexOnly is never true when isMultiKey is true
- Closed
-
SERVER-4463 Allow covered index use for non-array fields in multi-key index
- Closed
- is related to
-
SERVER-8454 Multi-key index prevents bounds being used for non-multi-key part
- Closed
-
SERVER-29550 Leverage multiKeyPath information to prevent filtering in FETCH with negation operator
- Backlog
- related to
-
SERVER-7959 Potentially unexpected scans with compound indexes when some fields are multikey
- Closed
-
SERVER-15086 Allow for efficient range queries over non-array fields in multikey indices
- Closed