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

Distinct - nscanned for $in and $or greater than nscannedObjects

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.5.4
    • Component/s: Querying
    • Labels:
    • Fully Compatible
    • ALL
    • Hide

      The following queries generates an anomaly with nscanned:

      t = db.distinct_index1
      t.drop();
      
      for ( i=0; i < 100; ++i ) {
            t.insert( {a: i%10} );
      }
      t.ensureIndex({a:1});
      t.runCommand( "distinct" , { key : 'a' , query : { a : { $in : [2, 4, 6, 8] } } } );
      
      {
      	"values" : [
      		2,
      		4,
      		6,
      		8
      	],
      	"stats" : {
      		"n" : 40,
      		"nscanned" : 43,
      		"nscannedObjects" : 40,
      		"timems" : 12,
      		"cursor" : "BtreeCursor a_1"
      	},
      	"ok" : 1
      }
      
      t.runCommand( "distinct" , { key : 'a' , query :{ $or: [{a:3}, {a:5}] } } );
      
      {
      	"values" : [
      		3,
      		5
      	],
      	"stats" : {
      		"n" : 20,
      		"nscanned" : 21,
      		"nscannedObjects" : 20,
      		"timems" : 0,
      		"cursor" : "BtreeCursor a_1"
      	},
      	"ok" : 1
      }
      
      Show
      The following queries generates an anomaly with nscanned: t = db.distinct_index1 t.drop(); for ( i=0; i < 100; ++i ) { t.insert( {a: i%10} ); } t.ensureIndex({a:1}); t.runCommand( "distinct" , { key : 'a' , query : { a : { $in : [2, 4, 6, 8] } } } ); { "values" : [ 2, 4, 6, 8 ], "stats" : { "n" : 40, "nscanned" : 43, "nscannedObjects" : 40, "timems" : 12, "cursor" : "BtreeCursor a_1" }, "ok" : 1 } t.runCommand( "distinct" , { key : 'a' , query :{ $or: [{a:3}, {a:5}] } } ); { "values" : [ 3, 5 ], "stats" : { "n" : 20, "nscanned" : 21, "nscannedObjects" : 20, "timems" : 0, "cursor" : "BtreeCursor a_1" }, "ok" : 1 }

      nscanned for certain indexed queries ($or & $in) returns a different result than nscannedObjects. This is not an issue when using $gt, $lt, $and, etc.

            Assignee:
            benety.goh@mongodb.com Benety Goh
            Reporter:
            jonathan.abrahams Jonathan Abrahams
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: