-
Type: New Feature
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
SERVER-56420 handles coalescing setWindowFields stages where the sortBy arguments are identical, but it may be possible to coalesce without identical sortBy arguments if one of the window functions is order independent and the fields that are being sorted on match (even if the ascending/descending don't match).
For example $integral/$sum/$derivative are order independent so the following stages could be merged:
{$setWindowFields: {
sortBy: {a: 1},
output: {rank: {$rank: {}}},
}}
{$setWindowFields: {
sortBy: {a: -1}
output: {integral: {$integral: "$b"}}
}}
into one expression:
{$setWindowFields: {
sortBy: {a: 1},
output: {rank: {$rank: {}}, integral: {$integral: "$b"}},
}}
because $integral is order independent.
Care will have to be taken to ensure that the bounds are re-expressed in equivalent terms and the limitation on descending range-based sort isn't infringed.
Similarly to 56420, we will need to ensure that:
- The second stage does not read from any 'output' field of the first.
- The two stages don't have any 'output' field name in common.
- The two stages have identical partitionBy arguments.
- is related to
-
SERVER-56581 Flip window-function sortBy and bounds to save space
- Backlog
- related to
-
SERVER-56420 Coalesce $setWindowFields stages
- Backlog