[SERVER-56417] Optimize away unused 'output' fields in $setWindowFields Created: 27/Apr/21  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: David Percy Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-55886 Optimize away unused computed fields Backlog
Related
Assigned Teams:
Query Optimization
Participants:

 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


Generated at Thu Feb 08 05:39:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.