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

nscannedObjects is not calculated properly for covered index queries

    • ALL

      Overview:

      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.insert(

      {foo:i,bar:i*10}

      )
      }
      db.cindextest.ensureIndex(

      {foo:1}

      )

      > db.cindextest.find(

      {foo:1}

      ,

      {foo:1,_id:0}

      ).explain()
      {
      "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 ] ] }

      }

            Assignee:
            aaron Aaron Staple
            Reporter:
            sridhar Sridhar Nanjundeswaran
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: