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

Plan ranking tie breaker is computed incorrectly

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.11, 3.0.5, 3.1.6
    • Affects Version/s: 2.6.10, 3.0.4
    • Component/s: Querying
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Quint Iteration 3.1.2, Quint Iteration 6

      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.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: