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

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

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

      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:
            ruoxin.xu@mongodb.com Ruoxin Xu
            Reporter:
            matt.boros@mongodb.com Matt Boros
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: