[SERVER-13764] debug mechanisms report incorrect nscanned / nscannedObjects for updates Created: 28/Apr/14  Updated: 11/Jul/16  Resolved: 10/Jul/14

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.6.0
Fix Version/s: 2.6.4, 2.7.4

Type: Bug Priority: Minor - P4
Reporter: Nathan Zamecnik Assignee: David Storch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Duplicate
is duplicated by SERVER-14171 nscanned and nscannedObjects misrepor... Closed
Related
related to SERVER-15106 Incorrect nscanned and nscannedObject... Closed
Tested
Operating System: ALL
Backport Completed:
Steps To Reproduce:

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()

Participants:

 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.



 Comments   
Comment by Githook User [ 17/Jul/14 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-13764 update system retrieves nscanned / nscannedObjects from runner
Branch: v2.6
https://github.com/mongodb/mongo/commit/32ae9aa4f46eb95b4d70b7f69a1e84bc95a1a5d1

Comment by Githook User [ 10/Jul/14 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-13764 update system retrieves nscanned / nscannedObjects from plan executor
Branch: master
https://github.com/mongodb/mongo/commit/7e90a89afa78e4ca5833149e4426c9193c107700

Generated at Thu Feb 08 03:32:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.