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

Remove unnecessary BSON allocations in computeSortsForScan() during plan construction

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0, 8.0.0-rc3
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Optimization
    • Fully Compatible
    • v8.0

      Found when analyzing the flamegraphs for the benchmarks introduced in SERVER-85814

      As part of QueryPlannerAnalysis::analyzeDataAccess(), we perform sort and covering analysis to optimize plans. This is invoked during regular query planning as well when recovering plans from the classic plan cache.

      Here, when we remove equality from sort objects, it appears that we invoke removeFields on a BSONObj, which performs an allocation to copy non-removed fields over. Then we immediately pass that object to QueryPlannerAnalysis::getSortPattern which performs another BSONObj allocation to construct the sort pattern.

      We should be able to avoid the intermediate allocation and do this in a single pass.

            Assignee:
            hana.pearlman@mongodb.com Hana Pearlman
            Reporter:
            ben.shteinfeld@mongodb.com Ben Shteinfeld
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: