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

Count command does not respect hint if query predicate is empty

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.2
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
    • Major Change
    • ALL
    • Query 10 (02/22/16)

      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.
      >
      

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

              Created:
              Updated:
              Resolved: