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

Exists query with a sparse index should have nscannedObjects = 0

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Environment:
      2.4.0-rc0 on OS X
    • ALL
    • Hide

      testDB = db.getSiblingDB("qa293")
      var coll = testDB.getCollection("simple.3")
      coll.drop()
      for (i=0;i<10;i++) {
      coll.insert(

      {foo:i}

      )
      }
      for (i=0;i<5;i++) {
      coll.insert(

      {bar:i}

      )
      }
      coll.insert(

      {foo:"1"}

      )
      coll.insert({foo:{bar:1}})
      coll.insert(

      {foo:null}

      )
      coll.ensureIndex(

      {foo:1}

      ,

      {sparse:true, unique:true}

      )

      // Test exists query
      var plan = coll.find({foo:{$exists:true}},

      {foo:1, _id:0}

      ).hint(

      {foo:1}

      ).explain()
      assert.eq(true, plan.indexOnly, "simple.3.7 - indexOnly should be true on covered query")
      assert.eq(0, plan.nscannedObjects, "simple.3.7 - nscannedObjects should be 0 for covered query")

      Show
      testDB = db.getSiblingDB("qa293") var coll = testDB.getCollection("simple.3") coll.drop() for (i=0;i<10;i++) { coll.insert( {foo:i} ) } for (i=0;i<5;i++) { coll.insert( {bar:i} ) } coll.insert( {foo:"1"} ) coll.insert({foo:{bar:1}}) coll.insert( {foo:null} ) coll.ensureIndex( {foo:1} , {sparse:true, unique:true} ) // Test exists query var plan = coll.find({foo:{$exists:true}}, {foo:1, _id:0} ).hint( {foo:1} ).explain() assert.eq(true, plan.indexOnly, "simple.3.7 - indexOnly should be true on covered query") assert.eq(0, plan.nscannedObjects, "simple.3.7 - nscannedObjects should be 0 for covered query")

      An exists query on a sparse index field has indexOnly true but nscannedObjects > 0
      The test case below asserts
      assert: [0] != [13] are not equal : simple.3.7 - nscannedObjects should be 0 for covered query

            Assignee:
            Unassigned Unassigned
            Reporter:
            sridhar Sridhar Nanjundeswaran
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: