$group returns different keys depending on presence of index

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

       

      Enterprise test> db.version()
      9.0.0-alpha0-6af02c94
      Enterprise test> db.c.drop()
      Enterprise test> db.c.insert([{c:1}, {c:1, a: null}, {c: 1, b: null}, 
      Enterprise test> db.c.find()
      [
        { _id: ObjectId("6a5f94165f5dc3a4d21d6f67"), c: 1 },
        { _id: ObjectId("6a5f94165f5dc3a4d21d6f68"), c: 1, a: null },
        { _id: ObjectId("6a5f94165f5dc3a4d21d6f69"), c: 1, b: null },
        { _id: ObjectId("6a5f94165f5dc3a4d21d6f6a"), c: 1, a: null, b: null }
      ]
      // Uses COLLSCAN + GROUP pushed down to SBE
      Enterprise test> db.c.aggregate([{$match: {c: 1}},{$group: {_id: {a: "$a", b: "$b"}}}])
      [
        { _id: { a: null } },
        { _id: {} },
        { _id: { b: null } },
        { _id: { a: null, b: null } }
      ]
      Enterprise test> db.c.createIndex({c: 1, a: 1, b: 1})
      // Uses covered IXSCAN + GROUP pushed down to SBE
      Enterprise test> db.c.aggregate([{$match: {c: 1}},{$group: {_id: {a: "$a", b: "$b"}}}])
      [ { _id: { a: null, b: null } } ] 
      
      // Problem occurs in classic engine as well
      Enterprise test> db.adminCommand({setParameter: 1, internalQueryFrameworkControl: 'forceClassicEngine'});
      { was: 'trySbeRestricted', ok: 1 }
      Enterprise test> db.c.aggregate([{$match: {c: 1}},{$group: {_id: {a: "$a", b: "$b"}}}])
      [ { _id: { a: null, b: null } } ]
      
      

      A user would expect that the presence of an index should not affect the result set, however this repro shows a case where that is not the case.

      This looks like another manifestation of SERVER-23229 where the current index format is unable to distinguish between null and missing values.

       

            Assignee:
            Unassigned
            Reporter:
            Ben Shteinfeld
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: