[SERVER-12783] MergeSort stage should be limit-aware, rather than adding an explicit limit stage after the sort completes Created: 19/Feb/14  Updated: 11/Jul/16  Resolved: 19/Mar/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.5.5
Fix Version/s: 2.6.0-rc2

Type: Improvement Priority: Minor - P4
Reporter: David Storch Assignee: Benety Goh
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

The new query system does not implement the optimization described in SERVER-5063. We should reimplement it for the new query system.

For example, if you have an $in query and you specify a limit, then the limit can be applied to each element of the $in. Let's say that you have index {a: 1, b: 1}. The query

db.collection.find({a: {$in: [1, 2]}}).sort({b: 1}).limit(5)

can be executed by limiting the results from a==1 to 5 and the results from a==2 to 5, sorting on "b" with a merge sort, then reapplying a limit of 5. Currently this query is executed with a mergeSort, but the limits are not applied to the children of the mergeSort.


Generated at Thu Feb 08 03:29:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.