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

Optimize away unused 'output' fields in $setWindowFields

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • Query Optimization

    Description

      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

      Attachments

        Activity

          People

            backlog-query-optimization Backlog - Query Optimization
            david.percy@mongodb.com David Percy
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: