-
Type: Task
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Integration
The $mergeCursors stage, used on mongos to stitch together results from multiple shards, can optionally produce its results in sorted order if the stages on the shards output in sorted order. This means that if there is a $sort stage directly after $mergeCursors, the $sort can be removed, if the sorted output of $mergeCursors is on the same sort criteria as the $sort.
We need this optimization specifically for $rankFusion, where we know we will be doing a sort on the search score metadata, but this optimization should apply in general. Testing should be done in $search/$vectorSearch cases, but also in more general cases.
Note: This optimization should only apply to pipelines where the $sort comes directly after the $mergeCursors stage. This optimization should be generalizable to cases where stages that do not affect the sort order of the documents come in-between the $mergeCursors and $sort, however there are some pre-requisites to tackle before we can implement this generalization, which will be handled in subsequent tickets.
- is depended on by
-
SERVER-95168 Implement $setWindowFields version of desugaring for $rankFusion
- Open
-
SERVER-96068 Generalize the $sort removal optimizations after $search/$vectorSearch/$mergeCursors
- Open
- is related to
-
SERVER-94628 Ensure we do not do a redundant $sort by search score during $rankFusion.
- Closed
- related to
-
SERVER-96067 Properly set the ‘preserveOrderAndMetadata’ field for common aggregation states
- Open