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

Find queries with SORT_MERGE collation-encode the missing sort attribute

    • Fully Compatible
    • ALL
    • v5.3, v5.2, v5.0, v4.4, v4.2
    • QE 2022-03-21

      `SORT_MERGE` stage merges multiple sorted streams.
      When the collection has collation enabled, the comparison function has three different cases:

      • If for both left-hand-side and right-hand-side the sort attribute are present in the index key, then a regular BSONObj comparison is enough, as both index-keys are collation-encoded
      • If none of them have sort attribute as part of the index key, perform the comparison with the help of the collator
      • If only of the sides has sort attribute as part of the index key, then perform the collation-encoding of the other side and then perform the regular BSONObj comparison with both sides being collation-encoded

      The issue arises in the third case, when we are trying to perform the collation-encoding of a document with a missing sort attribute. In this case an invariant is violated and mongod crashes.

      The solution would be to perform the collation-encoding only in the case, when the sort attribute is present.

            denis.grebennicov@mongodb.com Denis Grebennicov
            denis.grebennicov@mongodb.com Denis Grebennicov
            0 Vote for this issue
            6 Start watching this issue