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

Optimize away unused 'output' fields in $setWindowFields

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

      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:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            david.percy@mongodb.com David Percy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: