Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-13337

Re-enable fast path for _id equality queries with projection

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.2, 2.7.0
    • Affects Version/s: 2.6.0-rc0
    • Component/s: Querying
    • None
    • Fully Compatible

      Issue Status as of Jun 09, 2014

      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
      }
      

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            dan@mongodb.com Daniel Pasette (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: