Details
-
Improvement
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
None
-
Minor Change
-
v4.7, v4.4
-
Query 2020-06-29, Query 2020-07-13, Query 2020-07-27
-
(copied to CRM)
-
16
Description
If there is an extra $sort that's identical to one before it, and there's a $limit after it, it causes an unfortunate full $sort of every document before the second sort which absorbed $limit is executed.
db.c.explain().aggregate([ {$sort: {a: 1}},{$sort:{a:1}},{$limit:5}]);
|
{
|
"stages" : [
|
{
|
"$cursor" : {
|
"query" : {
|
|
},
|
"sort" : {
|
"a" : 1
|
},
|
"queryPlanner" : {
|
"plannerVersion" : 1,
|
"namespace" : "test.c",
|
"indexFilterSet" : false,
|
"parsedQuery" : {
|
|
},
|
"winningPlan" : {
|
"stage" : "EOF"
|
},
|
"rejectedPlans" : [ ]
|
}
|
}
|
},
|
{
|
"$sort" : {
|
"sortKey" : {
|
"a" : 1
|
},
|
"limit" : NumberLong(5)
|
}
|
}
|
],
|
"ok" : 1
|
}
|
Attachments
Issue Links
- causes
-
SERVER-50897 Fix Sort/Limit/Sort Optimization
-
- Closed
-