Optimize away unused 'output' fields in $setWindowFields

XMLWordPrintableJSON

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

      In a $setWindowFields stage, if one of the 'output' fields ends up not being used, we could rewrite the query to avoid computing that field:

      {$setWindowFields: {
          output: {
              total: {$sum: "$x"},
              avg: {$avg: "$x"},
          }
      }},
      {$unset: 'avg'}
      

      would optimize to:

      {$setWindowFields: {
          output: {
              total: {$sum: "$x"},
          }
      }},
      {$unset: 'avg'}
      

      It might make sense to do this for unused $project fields first: SERVER-55886

              Assignee:
              [DO NOT USE] Backlog - Query Optimization
              Reporter:
              David Percy (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: