ExportXMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • ALL
    • QE 2026-11-09, QE 2026-11-23
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Problem

      When an SBE $group with a non-simple collation spills to disk, serializeValueIntoKeyString in src/mongo/db/exec/sbe/values/row.cpp applies the collation to string keys but writes BSON Symbol keys raw. The spilled record ids of Symbol keys that are equal under the collation then differ and need not be adjacent, so HashAggStage::getNextSpilled emits one logical group as several rows with partial results.

      The in-memory path hashes and compares Symbols with the collation, so results change depending on whether the stage spills.

      Repro

      // k holds Symbol values a, A, B, A, a, B
      db.c.aggregate([{$group: {_id: "$k", n: {$sum: 1}}}],
                     {allowDiskUse: true, collation: {locale: "en", strength: 2}})
      // with internalQuerySlotBasedExecutionHashAggIncreasedSpilling: "always"
      // returns three groups (a:2, B:2, a:2) instead of two (a:4, B:2)
      

      Fix

      Encode Symbols with the collation transform when a collator is present, as is done for strings.

      Note

      The classic engine's Value::compare and Value::hash_combine ignore the collator for Symbols, so the merging $group in sharded clusters splits such groups regardless of spilling. That discrepancy is out of scope here.

            Assignee:
            Evan Bergeron
            Reporter:
            Evan Bergeron
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: