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

debug mechanisms report incorrect nscanned / nscannedObjects for updates

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 2.6.0
    • Fix Version/s: 2.6.4, 2.7.4
    • Component/s: Write Ops
    • Labels:
      None
    • Operating System:
      ALL
    • Backport Completed:
    • Steps To Reproduce:
      Hide

      use test
       
      db.t.drop()
       
      db.t.insert( { x : 1 } )
      db.t.insert( { x : 2 } )
      db.t.insert( { x : 3 } )
      db.t.insert( { x : 4 } )
      db.t.insert( { x : 5 } )
       
      db.setProfilingLevel(2)
       
      db.t.update( { x : { $lt : 3 } }, { $set : { "changed" : true } } , { multi: true } )
       
      db.system.profile.find().pretty()

      Show
      use test   db.t.drop()   db.t.insert( { x : 1 } ) db.t.insert( { x : 2 } ) db.t.insert( { x : 3 } ) db.t.insert( { x : 4 } ) db.t.insert( { x : 5 } ) db.setProfilingLevel(2) db.t.update( { x : { $lt : 3 } }, { $set : { "changed" : true } } , { multi: true } )   db.system.profile.find().pretty()

      Description

      Issue Status as of Jul 22, 2014

      ISSUE SUMMARY
      The update system sets nscanned and nscannedObjects simply by incrementing counters. This is at odds with the query system's definition of nscanned as "the number of keys examined" and nscannedObjects as "the number of documents examined".

      These values are collected and made available through the profiler and slow query log.

      USER IMPACT
      The profiler and the slow query log may show incorrect values for nscanned and nscannedObjects for update operations. These values should be larger than reported.

      WORKAROUNDS
      N/A

      AFFECTED VERSIONS
      MongoDB 2.6 production releases up to 2.6.3 are affected by this issue.

      FIX VERSION
      The fix is included in the 2.6.4 production release.

      RESOLUTION DETAILS
      Retrieve the correct values for nscanned and nscannedObjects from underlying query runner.

      Original description

      The nscanned value for multi updates is not correct for collection scans (no index present). nscanned seems to be the number of matched documents instead of the number of scanned documents (= all existing documents in the collection).

      Set up a sample dataset as described under "Steps to reproduce". Then run the multi update and look at the system.profile output:

      db.t.update( { x : { $lt : 3 } }, { $set : { "changed" : true } } , { multi: true } )
      db.system.profile.find().pretty()

      The expectation is that the profile shows nscanned: 5 (all documents in the collection), but it only shows 2.

      db.system.profile.find().pretty()
      {
          "op" : "update",
          "ns" : "test.t",
          "query" : {
              "x" : {
                  "$lt" : 3
              }
          },
          "updateobj" : {
              "$set" : {
                  "changed" : true
              }
          },
          "nscanned" : 2,
          "nscannedObjects" : 2,
          "nMatched" : 2,
          "nModified" : 2,
          "keyUpdates" : 0,
          "numYield" : 0,
          "lockStats" : {
              "timeLockedMicros" : {
                  "r" : NumberLong(0),
                  "w" : NumberLong(154)
              },
              "timeAcquiringMicros" : {
                  "r" : NumberLong(0),
                  "w" : NumberLong(5)
              }
          },
          "millis" : 0,
          "execStats" : {
       
          },
          "ts" : ISODate("2014-04-29T18:24:23.452Z"),
          "client" : "127.0.0.1",
          "allUsers" : [ ],
          "user" : ""
      }

      This was working in 2.4.10 and is a regression.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                10 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: