Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-96065

Optimize away $sort directly after sorted $mergeCursors for sharded environments

    • Type: Icon: Task Task
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 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.

            Assignee:
            joseph.shalabi@mongodb.com Joe Shalabi
            Reporter:
            joseph.shalabi@mongodb.com Joe Shalabi
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: