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

$elemMatch may attempt to erroneously use an index for comparison with arrays

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • ALL
    • Hide
      // Requires single-solution plan caching
      
      let coll = db.elem_match_index_diff_types;
      coll.drop();
      
      coll.insert({a:99});
      
      coll.createIndexes([{a:1}, {a:-1}]);
      
      // Set the activated plan cache entry
      coll.find({a:{$elemMatch:{$not:{$lte:1}}}}).sort({a:1}).toArray();
      coll.find({a:{$elemMatch:{$not:{$lte:2}}}}).sort({a:1}).toArray();
      
      // This causes a tassert
      coll.find({a:{$elemMatch:{$not:{$lte:[]}}}}).sort({a:1}).toArray();
      
      Show
      // Requires single-solution plan caching let coll = db.elem_match_index_diff_types; coll.drop(); coll.insert({a:99}); coll.createIndexes([{a:1}, {a:-1}]); // Set the activated plan cache entry coll.find({a:{$elemMatch:{$not:{$lte:1}}}}).sort({a:1}).toArray(); coll.find({a:{$elemMatch:{$not:{$lte:2}}}}).sort({a:1}).toArray(); // This causes a tassert coll.find({a:{$elemMatch:{$not:{$lte:[]}}}}).sort({a:1}).toArray();
    • QO 2024-08-19
    • 200

      After adding the discriminators for $elemMatch in SERVER-92806, we may use an index for a predicate which is not compatible. This logic is handled properly for non-$elemMatch cases but needs to be fixed with $elemMatch.

            Assignee:
            hana.pearlman@mongodb.com Hana Pearlman
            Reporter:
            jess.balint@mongodb.com Jess Balint
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: