Investigate apparent regression in classic engine IDHACK (SERVER-68110)

[SERVER-73912] avoid copying values in MatchExpression and isQuerySbeCompatible() Created: 10/Feb/23  Updated: 29/Oct/23  Resolved: 02/Mar/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.0.0-rc0

Type: Sub-task Priority: Major - P3
Reporter: Colin Stolley Assignee: Colin Stolley
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: QE 2023-05-15
Participants:

 Description   

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



 Comments   
Comment by Githook User [ 28/Feb/23 ]

Author:

{'name': 'Colin Stolley', 'email': 'colin.stolley@mongodb.com', 'username': 'ccstolley'}

Message: SERVER-73912: avoid copies in MatchExpression and isQuerySbeCompatible()
Branch: master
https://github.com/mongodb/mongo/commit/532c0679ef4fc8313a9e00a1334ca18e04ff6914

Generated at Thu Feb 08 06:25:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.