A $match stage with a top $and with only one $or fails to be pushed down together with $group

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 5.2.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • Hide

      db.t.aggregate([{$match: {$and: [{$or: [{"n": {$gt: 1000}}, {"n": {$lt: -1000}}]}]}}, {$group: {_id: null, max: {$max: "$n"}}}])

      Show
      db.t.aggregate([{$match: {$and: [{$or: [{"n": {$gt: 1000}}, {"n": {$lt: -1000}}] }]}}, {$group: {_id: null, max: {$max: "$n"}}}])
    • QE 2021-12-13
    • 45
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The issue here is related to subplanning for $or condition of $match stage. The $and in the repro has only one $or element and I expect that $and would be optimized away and $or would be the top expression but the following code can not detect that.

      https://github.com/mongodb/mongo/blob/master/src/mongo/db/pipeline/pipeline_d.cpp#L121-L125

              Assignee:
              Yoon Soo Kim (Inactive)
              Reporter:
              Yoon Soo Kim (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: