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

Refactor bounded sort optimization logic for timeseries query

    • Query Integration
    • Fully Compatible

      I would like to refactor two things for the bounded sort optimization logic:

      1. While working on SERVER-90833, I noticed that we use dynamic_cast repeatedly inside a for loop to do bounded sort optimization here. If a DocumentSource is a $project / $addFields / $replaceRoot, it will go through checking if it's a sort, then $match and then $unpack and then $project. AFAIK, dynamic_cast requires rtti and inheritance-hierarchy traversal. It may affect short-running query's performances which may spend more optimization time than running time. It would be better to introduce a new getType() method to DocumentSource and we can do switch (source->getType()). Same comment on other places to use dynamic_cast for DocumentSource concrete types. Especially this place. A POC for this can be found here. We should do perf profiling for this change.
      1. The bounded sort optimization logic is a really big chunk of PipelineD::buildInnerQueryExecutorGeneric() and it spans a lot of lines and it makes PipelineD::buildInnerQueryExecutorGeneric() harder to understand. It would be cleaner to define a separate class or function for the bounded sort optimization to separate concerns.

            Assignee:
            erin.liang@mongodb.com Erin Liang
            Reporter:
            yoonsoo.kim@mongodb.com Yoon Soo Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: