Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-68110 Investigate apparent regression in classic engine IDHACK
  3. SERVER-73912

avoid copying values in MatchExpression and isQuerySbeCompatible()

    • Type: Icon: Sub-task Sub-task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • QE 2023-05-15

      MatchExpression::parameterize() returns a vector of MatchExpression pointers by value. But its return value is not eligible for NRVO because it is a field of a local variable, not the local variable itself:

      std::vector<const MatchExpression*> MatchExpression::parameterize(MatchExpression* tree) {
          MatchExpressionParameterizationVisitorContext context{};
          MatchExpressionParameterizationVisitor visitor{&context};
          MatchExpressionParameterizationWalker walker{&visitor};
          tree_walker::walk<false, MatchExpression>(tree, &walker);
          return context.inputParamIdToExpressionMap;
      }
      

      a std::move() on the return value will avoid a copy.

      see src/mongo/db/matcher/expression.cpp

      Likewise, nss() makes a copy with every call, which is unnecessary. Since isQuerySbeCompatible() is in the hot path, let's avoid copying when we can.

      see src/mongo/db/query/query_utils.cpp

            Assignee:
            colin.stolley@mongodb.com Colin Stolley
            Reporter:
            colin.stolley@mongodb.com Colin Stolley
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: