Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
None
Description
There are number of reasons that the ordering of results with the same sort key might not be stable:
- The query execution stages for performing blocking sort operations in find/aggregation do not use a stable sort algorithm.
- Unpredictability of network latency and getMore ordering for queries on sharded clusters may result in different orders. This is similar to the behavior described in
SERVER-27716, which was closed as Works as Designed. - Changes to the underlying storage. For example, document moves on the MMAPv1 storage engine can result in repeated COLLSCANs returning the data in different orders. Therefore, even if the blocking sort query execution algorithm was stable, this still wouldn't be sufficient to guarantee consistent ordering of equal-keyed results.
Therefore, we should clarify that users who require a stable sort order across queries (eg pagination) add a unique field to their sort.
Attachments
Issue Links
- documents
-
SERVER-28195 $skip followed by $limit in aggregation resort & lost records when $sort by equal values
-
- Closed
-
- related to
-
SERVER-51498 Sorting on duplicate values causes repeated results with limit and skip
-
- Closed
-
-
SERVER-81571 Reconsider stable sort in sorter.cpp
-
- Blocked
-