[SERVER-59202] Construction of min/max bounds leads to invalid KeyStrings built in SBE Created: 09/Aug/21  Updated: 29/Oct/23  Resolved: 02/Sep/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 5.1.0-rc0

Type: Task Priority: Major - P3
Reporter: Ian Boros Assignee: Ian Boros
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: QE 2021-09-06
Participants:

 Description   

When running a find query with the 'min' or 'max' parameters, the planner has logic to provide a default 'min' or 'max' value if none was provided. For example,

coll.find().hint({a: 1}).min({a: "foo"}) // 'max' will be defaulted to MaxKey.
coll.find().hint({b: -1}).min({b: "foo"}) // 'max' will defaulted to MinKey.

The relevant logic is here where we create a 'minObj' if none was provided. This object always has one key, regardless of how many components the index scan has. For example:

coll.find().hint({a: 1, b: 1}).min({a: "foo", b: "bar"}) // max key will only have one field.

Unfortunately, since the 'minObj' may not have the same number of fields as the index has components, converting this object to KeyString may give us an invalid result. That is, it may produce a KeyString which cannot be round-tripped back to BSON.

Fortunately, this problem is not (yet) observable since no attempt is made to roundtrip these invalid KeyStrings, and the KeyStrings appear to sort correctly. However, if any effort were made to convert these KeyStrings back to BSON (for logging purposes, for assertions, or for any other reason), the server would crash. This problem is a "bomb" waiting to cause issues, and the author spent nearly a full day stuck on this issue while working on other tasks.

We should change the query planner to create the correct number of elements in 'minObj' and 'maxObj'.



 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by Githook User [ 31/Aug/21 ]

Author:

{'name': 'Ian Boros', 'email': 'ian.boros@mongodb.com', 'username': 'borosaurus'}

Message: SERVER-59202 Create bounds for min/max queries on compound indexes correctly
Branch: master
https://github.com/mongodb/mongo/commit/a88433c2c78516e30b1356404df5cf977fe37c31

Generated at Thu Feb 08 05:46:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.