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

PlanEnumerator AndAssignment::choices ordering not stable and is relevant to set of plans generated

    • Fully Compatible
    • ALL
    • v4.2, v4.0, v3.6
    • Query 2019-07-15, Query 2019-07-29, Query 2019-08-12, Query 2019-08-26
    • 0

      The following diff includes a jstest that will shift between 2 sets of candidate plans depending on the run. We would expect the set of plans generated to remain constant across test executions.

      diff --git a/jstests/core/repro.js b/jstests/core/repro.js
      new file mode 100644
      index 0000000000..511d1819ef
      --- /dev/null
      +++ b/jstests/core/repro.js
      @@ -0,0 +1,27 @@
      +
      +db.coll.drop();
      +db.coll.insert({});
      +db.coll.createIndexes([
      +    {"obj.obj.obj.obj.str": 1, "obj.obj.obj.str": 1},
      +    {"obj.obj.obj.str": -1, "date": -1},
      +    {"obj.date": 1},
      +    {"obj.obj.obj.str": 1, "obj.obj.obj.obj.date": -1},
      +    {"obj.date": -1, "obj.obj.obj.str": 1},
      +    {"obj.date": 1, "obj.obj.num": 1},
      +    {"obj.obj.obj.str": 1, "obj.obj.obj.date": -1},
      +    {"obj.obj.obj.obj.str": 1, "obj.date": 1}
      +]);
      +var result =
      +    db.coll
      +        .aggregate([
      +            {
      +              $match: {
      +                  $and: [
      +                      {$or: [{'obj.obj.obj.str': {$not: {$in: []}}}, {'obj.date': {$nin: []}}]},
      +                      {'obj.obj.obj.obj.str': {$not: {$lte: ''}}}
      +                  ]
      +              }
      +            },
      +            {$project: {"obj.obj.obj.obj.str": 1, "_id": 0}}
      +        ])
      +        .toArray();
      diff --git a/src/mongo/db/query/query_planner.cpp b/src/mongo/db/query/query_planner.cpp
      index 9735dbade0..4145df3056 100644
      --- a/src/mongo/db/query/query_planner.cpp
      +++ b/src/mongo/db/query/query_planner.cpp
      @@ -828,7 +828,7 @@ StatusWith<std::vector<std::unique_ptr<QuerySolution>>> QueryPlanner::plan(
           // Don't leave tags on query tree.
           query.root()->resetTag();
       
      -    LOG(5) << "Planner: outputted " << out.size() << " indexed solutions.";
      +    LOG(0) << "Planner: outputted " << out.size() << " indexed solutions.";
       
           // Produce legible error message for failed OR planning with a TEXT child.
           // TODO: support collection scan for non-TEXT children of OR.
      

            Assignee:
            james.wahlin@mongodb.com James Wahlin
            Reporter:
            james.wahlin@mongodb.com James Wahlin
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: