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

Do common sub expression elimination in PlanExplainerImpl::getSummaryStats

    • Query Optimization
    • Fully Compatible
    • QO 2024-03-18

      Currently PlanExplainerImpl::getSummaryStats makes repeated calls to stageType() which is a virtual function. Since this is a virtual function, the compiler cannot inline the call and also must repeat the call each time it is called as written in the code. A savings of a few instructions and a few function calls can be done by storing the result of this function call in a local variable.

      Current Code

      if (STAGE_IXSCAN == stages[i]->stageType()) {
      ...
      } else if(STAGE_COUNT_SCAN == stages[i]->stageType()) {
      ...
      

      Suggested Improvement

      auto stageType = stages[i]->stageType();
      if (STAGE_IXSCAN == stageType) {
      ...
      } else if(STAGE_COUNT_SCAN == stageType) {
      ...
      

      POC: https://github.com/10gen/mongo/commit/3c3d7ae8ec93db1ebbb3da3f97f57235c71f5f1e#diff-86a236f1dd8112311222323d8951b5d46eda648735fca2d28a50e1eb9d0bd30e

            Assignee:
            ben.shteinfeld@mongodb.com Ben Shteinfeld
            Reporter:
            mark.benvenuto@mongodb.com Mark Benvenuto
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: