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

Planner can attempt to use invalid index when using plan cache due to plan cache key / MatchExpression sorting inconsistency

    XMLWordPrintable

    Details

    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Backport Completed:
    • Steps To Reproduce:
      Hide

      (function() {
          "use strict";
       
          db.c.drop();
          db.c.createIndex({a: "2dsphere", b: 1});
          db.c.createIndex({b: 1});
       
          db.c.insert({a: {type: "Point", coordinates: [-79.88635540008511, 32.76497530165182]}, b: 10});
          db.c.insert({a: [-79.88635540008511, 32.76497530165182], b: 12});
       
          var geoPredicate = {
              $and: [
                  {b: {$gte: 6}},
                  {
                    a: {
                        $within: {
                            $polygon: [
                                [-79.97488975524868, 32.76497530165182],
                                [-79.88635540008511, 32.76497530165182],
                                [-79.88635540008511, 32.72617288558777],
                                [-79.97488975524868, 32.72617288558777]
                            ]
                        }
                    }
                  },
                  {
                    a: {
                        $within: {
                            $centerSphere:
                                [[-79.86978928637699, 32.75469246872076], 0.000757002271006813]
                        }
                    }
                  }
              ]
          };
       
         // First invocation should succeed and generate a plan cache entry.
         assert.eq(2, db.c.find(geoPredicate).itcount());
       
         // Second invocation is pulled from the cache and trips the verify()!
         assert.eq(2, db.c.find(geoPredicate).itcount());
      })();
      

      Show
      (function() { "use strict";   db.c.drop(); db.c.createIndex({a: "2dsphere", b: 1}); db.c.createIndex({b: 1});   db.c.insert({a: {type: "Point", coordinates: [-79.88635540008511, 32.76497530165182]}, b: 10}); db.c.insert({a: [-79.88635540008511, 32.76497530165182], b: 12});   var geoPredicate = { $and: [ {b: {$gte: 6}}, { a: { $within: { $polygon: [ [-79.97488975524868, 32.76497530165182], [-79.88635540008511, 32.76497530165182], [-79.88635540008511, 32.72617288558777], [-79.97488975524868, 32.72617288558777] ] } } }, { a: { $within: { $centerSphere: [[-79.86978928637699, 32.75469246872076], 0.000757002271006813] } } } ] };   // First invocation should succeed and generate a plan cache entry. assert.eq(2, db.c.find(geoPredicate).itcount());   // Second invocation is pulled from the cache and trips the verify()! assert.eq(2, db.c.find(geoPredicate).itcount()); })();
    • Sprint:
      Query 16 (06/24/16)

      Description

      The 2dsphere geo query in the repro steps trips the following verify():

      https://github.com/mongodb/mongo/blob/r3.3.6/src/mongo/db/query/index_bounds_builder.cpp#L596

      This affects the 3.2 branch as well as 3.3.x development versions. 3.0.x versions are not affected.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: