[SERVER-65470] Use const& instead of const pointer for collectExecutionStatsSummary() Created: 11/Apr/22  Updated: 29/Oct/23  Resolved: 03/May/22

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

Type: Improvement Priority: Minor - P4
Reporter: Yoon Soo Kim Assignee: Yoon Soo Kim
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: QE 2022-05-02, QE 2022-05-16
Participants:

 Description   

This ticket comes from a discussion at https://github.com/10gen/mongo/pull/4443#discussion_r846667018

collectExecutionStatsSummary() function is given a non-const pointer as follows.

PlanSummaryStats collectExecutionStatsSummary(const PlanStageStats* root) {
    invariant(root);
    ...
} 

And it checks whether the root parameter is not null with invariant.

PlanStageStats object(s) come from various getStats() method including HashLookupStage::getStats() and LoopJoinStage::getStats(). we allocate stats object using make_unique() function which uses new operator which may throw bad_alloc exception or any exception that PlanStageStats ctor throws. If the make_unique() function throws an exception, we would not reach collectExecutionStatsSummary() function at all.

If root could ever be nullptr, we can check whether it's null before calling this function. It would be a bad pattern to pass around nullptr until the last point, which would make it hard to debug if it happened.

The suggestion here is that we should take const& parameter instead of const pointer at collectExecutionStatsSummary() and related functions to express it must not be a null instead of checking invariant().



 Comments   
Comment by Githook User [ 03/May/22 ]

Author:

{'name': 'Yoonsoo Kim', 'email': 'yoonsoo.kim@mongodb.com', 'username': 'yun-soo'}

Message: SERVER-65470 Use `const&` instead of `const*` to express always non-null argument
Branch: master
https://github.com/mongodb/mongo/commit/f808d90990b18f34e5fd32534087d0b96ea7df1e

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