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

Plan ranking tie breaker is computed incorrectly

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.6.10, 3.0.4
    • Fix Version/s: 2.6.11, 3.0.5, 3.1.6
    • Component/s: Querying
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Backport Completed:
    • Sprint:
      Quint Iteration 3.1.2, Quint Iteration 6

      Description

      The epsilon value used to break a tie is computed as 1 over the query knob constant for the max number of works to perform during plan ranking:

      https://github.com/mongodb/mongo/blob/r3.1.0/src/mongo/db/query/plan_ranker.cpp#L209-L211

      // Just enough to break a tie.
      static const double epsilon = 1.0 /
           static_cast<double>(internalQueryPlanEvaluationWorks);
      

      During plan ranking, however, the actual number of works is the max of internalQueryPlanEvaluationWorks and some fixed fraction of the collection size:

      https://github.com/mongodb/mongo/blob/r3.1.0/src/mongo/db/exec/multi_plan.cpp#L199-L200

      numWorks = std::max(size_t(internalQueryPlanEvaluationWorks),
             size_t(fraction * _collection->numRecords(_txn)));
      

      The consequence is that the tie breaker can be too large. Instead of breaking a tie, it can cause an inferior plan's score to exceed a superior plan's score.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: