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

Construction of min/max bounds leads to invalid KeyStrings built in SBE

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • QE 2021-09-06

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

            Assignee:
            ian.boros@mongodb.com Ian Boros
            Reporter:
            ian.boros@mongodb.com Ian Boros
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: