Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-65470

Use const& instead of const pointer for collectExecutionStatsSummary()

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 6.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • QE 2022-05-02, QE 2022-05-16

      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().

            Assignee:
            yoonsoo.kim@mongodb.com Yoon Soo Kim
            Reporter:
            yoonsoo.kim@mongodb.com Yoon Soo Kim
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: