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

Only pull looked-up fields into DocumentStorage

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.3.2
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Fully Compatible
    • Query 2019-11-18
    • 0

      During query execution, when we need to lookup a Value inside a Document, there are two possible code paths:

      1. The Value already resides in DocumentStorage.
      2. We need to create the Value by reading the backing BSON object.

      The second case requires a linear scan of the BSON in order to find a BSONElement with the correct field name. During this scan, we currently eagerly convert all of the BSONElements we encounter into Values which reside inside the DocumentSource cache. This is done to ensure that only one forwards scan of the BSON object is necessary, avoiding potential quadratic performance required to look up n fields in a Document. However, our performance tests show that this eager conversion of BSONElement to Value is costly. In many cases, it is likely wasted work, since we might never need to read the field again later on. In order to improve performance, we should only pull the fields that the caller actually looked up into DocumentStorage.

      In the future, if we find that repeated scans of the backing BSON are expensive, we can implement query analysis in order to compute a set of fields that are likely to be looked up later, and then pull these only these fields into the document's cache.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: