$or followed by always false $elemMatch can fail pipeline optimization

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • ALL
    • Hide
      const coll = db.coll;
      coll.drop();
      assert.commandWorked(coll.insert({}));
      const query = [
          {$addFields: {t: 0}},
          {$match: {$or: [{t: 0, b: 0}],
                    t: {$elemMatch: {$not: {$in: []}}}}}
      ];
      coll.aggregate(query).toArray();
      
      Show
      const coll = db.coll; coll.drop(); assert .commandWorked(coll.insert({})); const query = [ {$addFields: {t: 0}}, {$match: {$or: [{t: 0, b: 0}], t: {$elemMatch: {$not: {$in: []}}}}} ]; coll.aggregate(query).toArray();
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      The following repro leads to the error "Failed to optimize pipeline :: caused by :: unknown operator: $alwaysFalse", despite being a valid agg pipeline.

      I've noticed a $project/$addFields is required to repro, followed by an $or predicate and an always false $elemMatch predicate

            Assignee:
            Timour Katchaounov
            Reporter:
            Matt Boros
            Votes:
            0 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated: