|
Currently, streaming $group is only enabled when the user provides a $sort stage on the _id field of the $group. Most accumulators do not have different outputs depending on the order of the input documents.
When the $group doesn't depend on the ordering of input documents and the group stage groups on time, we can insert a $sort stage to reorder documents and enable streaming $group.
As part of this ticket,
1. Investigate which accumulators do depend on document ordering (at least $firstN and $lastN)
2. Add code to DocumentSourceInternalUnpackBucket::doOptimizeAt() directly before the call to enableStreamingGroupIfPossible() that will insert a $sort stage on the timeField before the new streaming group stage.
|