-
Type: Task
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Integration
The results of $search come out sorted by 'searchScore' (in cases where the sort argument is not specified as otherwise). If a $sort stage comes directly after $search, and the sort criteria is by the searchScore, the sort should be able to be removed, as it should pass the documents in and out it in the same order.
The $sort that follows the $search can come from being explicitly specified, or from desugaring of another stage that requires sorting like $setWindowFields. The optimizing code should not need to differentiate these cases, but both types should be tested for correctness.
Note: This optimization should only apply to single node environments, as $search pipelines that have subsequent $sort stages are broken apart as a $search on the shard nodes, with a $mergeCursors stage followed by the $sort on the merging (mongos) node. This part of the optimization will be handled separately, and is more generic as many pipelines (other than $search ones) in a sharded environment may have a $mergeCursors stage followed by a $sort.
Note: This optimization should only apply to pipelines where the $sort comes directly after the $search stage. This optimization should be generalizable to cases where stages that do not affect the sort order of the documents come in-between the $search 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
-
SERVER-96165 Generalize $sort after $search optimization beyond metadata
- Backlog
- is related to
-
SERVER-96415 Add $sort pushdown optimization to $_internalSearchIdLookup
- In Progress
-
SERVER-96148 Parse mongot query using the IDL
- Backlog
- related to
-
SERVER-96067 Properly set the ‘preserveOrderAndMetadata’ field for common aggregation states
- Open
-
SERVER-94628 Ensure we do not do a redundant $sort by search score during $rankFusion.
- Closed