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

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

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 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

      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:
            yoonsoo.kim@mongodb.com Yoon Soo Kim (Inactive)
            Reporter:
            yoonsoo.kim@mongodb.com Yoon Soo Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: