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

Incorrect query results in SBE if $group spills in presence of collation

    • Query Execution
    • Fully Compatible
    • ALL
    • v7.2, v7.0, v6.0
    • Hide
      1. set internalQuerySlotBasedExecutionHashAggForceIncreasedSpilling to true
      2. db.createCollection("lp", {collation: {locale: 'en_US', strength: 2}}) // case-insensitive collation
      3. db.lp.insertMany([{"_id":0, key:"A"},{"_id":1, key:"A"},{"_id":2, key:"B"},{"_id":3, key:"B"},{"_id":4, key:"a"},{"_id":5, key:"a"}])
      4. db.lp.aggregate({$group: {_id: "$key"}})
      
      The results contain groups for "A" and "a" even though these should compare equal.
      { "_id" : "A" }
      { "_id" : "B" }
      { "_id" : "a" }
      
      Show
      1. set internalQuerySlotBasedExecutionHashAggForceIncreasedSpilling to true 2. db.createCollection( "lp" , {collation: {locale: 'en_US' , strength: 2}}) // case -insensitive collation 3. db.lp.insertMany([{ "_id" :0, key: "A" },{ "_id" :1, key: "A" },{ "_id" :2, key: "B" },{ "_id" :3, key: "B" },{ "_id" :4, key: "a" },{ "_id" :5, key: "a" }]) 4. db.lp.aggregate({$group: {_id: "$key" }}) The results contain groups for "A" and "a" even though these should compare equal. { "_id" : "A" } { "_id" : "B" } { "_id" : "a" }
    • 35

      When processing the inputs from the child in HashAggStage, it's possible that equivalent per the collation but not identical keys would come in separated by another key (like "A" and "a" in the repro are separated by "B"). As a result, the recordStore with spilled records might not have "a" and "A" next to each other, but HashAggStage::getNextSpilled() assumes they are...

      This bug causes SERVER-80374 and BF-30120 due to how tests in timeseries_lastpoint_top.js checks the results against a non-timeseries collection.

            Assignee:
            foteini.alvanaki@mongodb.com Foteini Alvanaki
            Reporter:
            irina.yatsenko@mongodb.com Irina Yatsenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: