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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor - P4
    • Resolution: Gone away
    • 2.5.4
    • None
    • Querying
    • 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 }

    Description

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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: