[SERVER-60069] Refactor agg expressions to use children elements instead of storing child references Created: 19/Sep/21  Updated: 29/Oct/23  Resolved: 27/Jan/23

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

Type: Improvement Priority: Major - P3
Reporter: Anton Korshunov Assignee: Timour Katchaounov
Resolution: Fixed Votes: 0
Labels: quick-tech-debt
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: QO 2022-09-19, QO 2022-10-03, QE 2022-10-17
Participants:

 Description   

Originally the agg Expressions hierarchy was designed to hold references to named arguments within an individual expression class. For example. It was supposed to provide faster access to expression arguments. The trade off of a hypothetical performance improvement was an increased memory footprint for agg expression trees. In our recent discoveries it was revealed that the ref approach also doesn't play nicely alongside optional expression arguments, which may result in an awkward construct of boost::optional<boost::intrusive_ptr<Expression>&> when we use boost::optional to hold a reference to something that is optional itself.

Moreover, we already diverged from this pattern of storing refs to expression arguments and use direct array access (as in _children[0]).

As part of this ticket we should evaluate if there is any real benefit of storing refs or otherwise switch to a different approach when we use mutable accessors:
 

class ExpressionXyz {
public:
    ...
    intrusive_ptr<Expression>& foo() {
        return _children[0];
    }
    intrusive_ptr<Expression>& bar() {                                         
        tassert(_children.size() > 1); // bar is optional and should never be accessed when not present
        return _children[1];
    }
};

 



 Comments   
Comment by Githook User [ 27/Jan/23 ]

Author:

{'name': 'Timour Katchaounov', 'email': 'timour.katchaounov@mongodb.com', 'username': 'timourk'}

Message: SERVER-60069 Refactor agg expressions to use children elements instead of storing child references

Replace all intrusive_ptr<Expression>& class members with the underlying _children array element.
Each _children element is identified via a size_t constant for the corresponding index in the array.
Branch: master
https://github.com/mongodb/mongo/commit/2bb006157d03c272ab5a3e308cbb149bfc879ed5

Generated at Thu Feb 08 05:48:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.