Avoid redundant path lookup in expression optimizer

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Minor - P4
    • 8.3.0-rc0
    • Affects Version/s: None
    • Component/s: Query Planning
    • None
    • Query Execution
    • Fully Compatible
    • QE 2025-11-10
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The optimizer for $or expressions currently computes the field path for every child $eq or $regex using the following code:

                  auto key = std::string{childExpression->path()};
                  if (!pathToExprsMap.contains(key)) {
                      std::vector<std::unique_ptr<MatchExpression>> exprs;
                      exprs.push_back(std::move(childExpression));
                      pathToExprsMap.insert({key, std::move(exprs)});
                  } else {
                      auto& childrenIndexList = pathToExprsMap.find(key)->second;
                      childrenIndexList.push_back(std::move(childExpression));
                  }
      

      This code first converts the field path into an std::string and then looks it up in the pathToExprsMap map. In case the path is not found, it is inserted. In case the path is already in the map, the else branch looks up the path in the map again.

      This can be improved by looking up the path only once. Also, by using the StringMap container, we can avoid the conversion to std::string for the lookup in the map, as StringMap also supports heterogeneous lookups using StringData keys.

            Assignee:
            Jan Steemann
            Reporter:
            Jan Steemann
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: