ExportXMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Trivial - P5
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      If I have an $or where one branch is an empty $in, the branch appears to be removed in the final plan since it will never produce results. However if this branch is a slightly more complicated predicate like "a < 5 && a>6", the branch is kept under the OR, with empty index bounds. The branch could be removed or made EOF.

      const coll = db.coll;
      coll.drop();
      
      assert.commandWorked(coll.insert([
          {_id: 0, a: 1, b: 1},
          {_id: 1, a: 2, b: 2},
          {_id: 2, a: 3, b: 3},
      ]));
      coll.createIndex({a: 1})
      
      printjson(coll.find({$or: [{a: 1}, {a: {$in: []}}]}).explain());
      // branch is removed
      
      printjson(coll.find({$or: [{a: 1}, {a: {$lt: 5, $gt: 6}}]}).explain());
      // branch is kept as an ixscan with empty bounds
      

      Marking this as trivial because as far as I can tell it doesn't affect planning efficiency or the performance of the final plan. This came up as an edge case when introducing plan shape counters in query stats.

            Assignee:
            Unassigned
            Reporter:
            Matt Boros
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: