Optimize away empty $addFields

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      {$addFields: {}} is a valid aggregation stage, probably mostly used in generated queries. Currently we do not optimize away empty addFields. Removing it could reduce unnecessary stages in our execution plans. It can also allow more plans to use SBE:

      jsTestLog(coll.explain().aggregate([{$group: {_id: null}}, {$group: {_id: null}}]))
      // Both $groups use SBE
      jsTestLog(coll.explain().aggregate([{$group: {_id: null}}, {$addFields: {}}, {$group: {_id: null}}]))
      // First $group uses SBE, then $addFields and $group execute in document sources
      

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

              Created:
              Updated:
              Resolved: