ISSUE SUMMARY
A mechanism called "idhack" chooses a different code path and fast-tracks query execution if the query is on _id without any other fields. Due to a major rewrite of the query engine for 2.6, the special case of queries with a projection does not yet use the "idhack" path and instead uses the regular code path which can be slower.
Example:
db.coll.find({{_id: 123}, {first_name: 1, last_name: 1})
This query on _id has a projection on {first_name: 1, last_name: 1}). In 2.6 this query would not use the fast "idhack" code path and would go through regular query planning instead, which is slower.
USER IMPACT
Users may find that queries on _id field with a projection can be slower in 2.6 than they were in 2.4.
WORKAROUNDS
None.
AFFECTED VERSIONS
Versions 2.6.0 and 2.6.1 are affected by this issue.
FIX VERSION
The fix is included in the 2.6.2 production release.
RESOLUTION DETAILS
The "idhack" runner now additionally supports queries with projections. This restores the behavior of version 2.4.
Original description
Re-enable using IDCursor runner for queries with projections.
> db.collection.find({_id: ObjectId("532b16caee361edb67169d7a")}, {_id:1}).explain() { "cursor" : "IDCursor", "n" : 1, "nscannedObjects" : 0, "nscanned" : 1, "indexOnly" : true, "millis" : 0, "indexBounds" : { "_id" : [ [ ObjectId("532b16caee361edb67169d7a"), ObjectId("532b16caee361edb67169d7a") ] ] }, "server" : "crucible-2.local:27017" } > db.collection.find({_id: ObjectId("532b16caee361edb67169d7a")}, {x:1}).explain() { "cursor" : "BtreeCursor _id_", "isMultiKey" : false, "n" : 1, "nscannedObjects" : 1, "nscanned" : 1, "nscannedObjectsAllPlans" : 1, "nscannedAllPlans" : 1, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "indexBounds" : { "_id" : [ [ ObjectId("532b16caee361edb67169d7a"), ObjectId("532b16caee361edb67169d7a") ] ] }, "server" : "crucible-2.local:27017", "filterSet" : false }
- is depended on by
-
SERVER-13663 Perf regression for workload that updates 1 row with 1 or many clients
- Closed
- is related to
-
SERVER-14302 Equality queries on _id with projection may return no results on sharded collections
- Closed
- related to
-
SERVER-13685 refactor fast-path for _id queries to not create a CanonicalQuery
- Closed
-
SERVER-13842 Optimize non-simple projections
- Backlog