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

Plan ranking tie breaker is computed incorrectly

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 2.6.10, 3.0.4
    • 2.6.11, 3.0.5, 3.1.6
    • Querying
    • None
    • Fully Compatible
    • ALL
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: