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

count() examines docs on covered query with $in

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • ALL
    • Hide
      db.keys_examined.createIndex({x: 1, y: 1})
      db.keys_examined.insertMany([{'x': "A", 'y': 1}, {'x': "B", 'y': 1}, {'x': "A", 'y': 2}])
      db.keys_examined.explain('executionStats').count({x: "A", y: {$in: [1, 2]}})
      
      Show
      db.keys_examined.createIndex({x: 1, y: 1}) db.keys_examined.insertMany([{ 'x' : "A" , 'y' : 1}, { 'x' : "B" , 'y' : 1}, { 'x' : "A" , 'y' : 2}]) db.keys_examined.explain( 'executionStats' ).count({x: "A" , y: {$in: [1, 2]}})

      The executionStats for count() shows that totalDocsExamined is not 0 when a covered query contains an $in with multiple values in the array, but the equivalent find() has 0 totalDocsExamined.

      db.keys_examined.explain('executionStats').find({x: "A", y: {$in: [1, 2]}}, {_id: 0, y: 1})
      

      Returns the expected executionStats
      "nReturned" : NumberInt(2),
      "totalKeysExamined" : NumberInt(3),
      "totalDocsExamined" : NumberInt(0)

      db.keys_examined.explain('executionStats').count({x: "A", y: {$in: [1]}})
      

      Returns the expected executionStats
      "nReturned" : NumberInt(0),
      "totalKeysExamined" : NumberInt(2),
      "totalDocsExamined" : NumberInt(0)

      db.keys_examined.explain('executionStats').count({x: "A", y: {$in: [1, 2]}})
      

      I would expect that totalDocsExamined would still be 0, but executionStats returns
      "nReturned" : NumberInt(0),
      "totalKeysExamined" : NumberInt(3),
      "totalDocsExamined" : NumberInt(2)

            Assignee:
            Unassigned Unassigned
            Reporter:
            axom Brian Riley
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: