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

Count command does not respect hint if query predicate is empty

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 3.3.2
    • Querying
    • Major Change
    • ALL
    • Query 10 (02/22/16)

    Description

      The count command does not respect the user-specified hint, if an empty query predicate is specified.

      This is due to a bug in CountStage::work(), which fails to check for a non-empty hint before deciding to apply the "trivial count" optimization.

      Reproduce as follows:

      > db.foo.drop()
      true
      > db.foo.ensureIndex({a: 1}, {sparse: true})
      {
      	"createdCollectionAutomatically" : true,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      > db.foo.insert({})
      WriteResult({ "nInserted" : 1 })
      > db.foo.find().hint({a: 1}).itcount()
      0
      > db.foo.find().hint({a: 1}).count()
      1  // Unexpected: should return 0 instead.
      >
      

      Attachments

        Activity

          People

            charlie.swanson@mongodb.com Charlie Swanson
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: