[SERVER-64403] Find queries with SORT_MERGE collation-encode the missing sort attribute Created: 10/Mar/22  Updated: 29/Oct/23  Resolved: 11/Mar/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.3.2, 6.0.0-rc0, 5.0.7, 4.4.16, 4.2.22, 5.2.2

Type: Bug Priority: Major - P3
Reporter: Denis Grebennicov Assignee: Denis Grebennicov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.3, v5.2, v5.0, v4.4, v4.2
Sprint: QE 2022-03-21
Participants:
Case:

 Description   

`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.



 Comments   
Comment by Githook User [ 27/Jul/22 ]

Author:

{'name': 'Denis Grebennicov', 'email': 'denis.grebennicov@mongodb.com', 'username': 'denis631'}

Message: SERVER-64403 Encode the sort key from a document with collation only if value is present when comparing a sort key from index with one from the document in SORT_MERGE stage.
Branch: v4.2
https://github.com/mongodb/mongo/commit/ceb58e6cce4483f73ec38b7c827c2e3f6d7636fa

Comment by Githook User [ 27/Jul/22 ]

Author:

{'name': 'Denis Grebennicov', 'email': 'denis.grebennicov@mongodb.com', 'username': 'denis631'}

Message: SERVER-64403 Encode the sort key from a document with collation only if value is present when comparing a sort key from index with one from the document in SORT_MERGE stage.
Branch: v4.4
https://github.com/mongodb/mongo/commit/8155c5fa863de0fd5ea59a8c4ada2e59447006e0

Comment by Githook User [ 06/Apr/22 ]

Author:

{'name': 'Denis Grebennicov', 'email': 'denis.grebennicov@mongodb.com', 'username': 'denis631'}

Message: SERVER-64403 Encode the sort key from a document with collation only if value is present when comparing a sort key from index with one from the document in SORT_MERGE stage.
Branch: v5.3
https://github.com/mongodb/mongo/commit/0e529d053e0275df760955b3215b90353bde560c

Comment by Githook User [ 11/Mar/22 ]

Author:

{'name': 'Denis Grebennicov', 'email': 'denis.grebennicov@mongodb.com', 'username': 'denis631'}

Message: SERVER-64403 Encode the sort key from a document with collation only if value is present when comparing a sort key from index with one from the document in SORT_MERGE stage.
Branch: v5.2
https://github.com/mongodb/mongo/commit/c26d169cfe6d0d369b422e7de0c54b68ec8b8ec5

Comment by Githook User [ 11/Mar/22 ]

Author:

{'name': 'Denis Grebennicov', 'email': 'denis.grebennicov@mongodb.com', 'username': 'denis631'}

Message: SERVER-64403 Encode the sort key from a document with collation only if value is present when comparing a sort key from index with one from the document in SORT_MERGE stage.
Branch: v5.0
https://github.com/mongodb/mongo/commit/daeb6fe7116f3835c2e04603536e18e8fc06facd

Comment by Githook User [ 11/Mar/22 ]

Author:

{'name': 'Denis Grebennicov', 'email': 'denis.grebennicov@mongodb.com', 'username': 'denis631'}

Message: SERVER-64403 Encode the sort key from a document with collation only if value is present when comparing a sort key from index with one from the document in SORT_MERGE stage.
Branch: master
https://github.com/mongodb/mongo/commit/915208b32bc1acc2789fb5d1932d0a8902a9b6cf

Generated at Thu Feb 08 06:00:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.