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

nscannedObjects is not calculated properly for covered index queries

    • ALL


      The 'nscannedObjects' field in the explain output for a query describes the number of documents that would be read from the data store to perform a query. (This count does not include cases where an index key is read but the document that index key comes from is not read.) The 'nscannedObjects' field is reported on a per query basis and also on a per query plan basis (in the allPlans section of the explain output).

      Reporting nscannedObjects is not implemented by checking directly if the data layer has read a document, but by determining if the document would have been read at different stages of query handling on a case by case basis. Per this ticket, nscannedObjects is now reported as follows:

      • for a query, the nscannedObjects count includes cases where a document is read to perform query matching, a document is read to determine if it belongs to a valid chunk, or a document would be read to return a result (including all documents used to perform an in memory sort, but not covered index projections that aren't sorted in memory).


      Expected nscannedObjects to be 0 for a covered index query but it is 1.

      for (var i = 1; i < 11; i++) {





      > db.cindextest.find(




      "cursor" : "BtreeCursor foo_1",
      "nscanned" : 1,
      "nscannedObjects" : 1, <------------- expected this to be 0
      "n" : 1,
      "millis" : 0,
      "nYields" : 0,
      "nChunkSkips" : 0,
      "isMultiKey" : false,
      "indexOnly" : true,
      "indexBounds" :

      { "foo" : [ [ 1, 1 ] ] }


            aaron Aaron Staple
            sridhar Sridhar Nanjundeswaran
            1 Vote for this issue
            5 Start watching this issue