-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: 7.0.13, 6.0.17, 8.0.0-rc17
-
Component/s: None
-
Query Execution
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
See the following repro:
> db.adminCommand({setParameter: 1, internalQueryFrameworkControl: "forceClassicEngine"});
> db.ds.insert({x: [{a: 1, b: 2}, {a: 2, b: 3}]});
> # $sort + $group w/ $first
> let pipeline1 = [{$sort: {"x.a": 1, "x.b": 1}}, {$group: {_id: "$x.a", o: {$first: "$x.b"}}}];
> # $group w/ $top is supposed to return the same result
> let pipeline2 = [{$group: {_id: "$x.a", o: {$top: {sortBy: {"x.a": 1, "x.b": 1}, output: "$x.b"}}}}];
> db.ds.aggregate(pipeline1);
{ "_id" : [ 1, 2 ], "o" : [ 2, 3 ] }
> db.ds.aggregate(pipeline2);
uncaught exception: Error: command failed: {
"ok" : 0,
"errmsg" : "PlanExecutor error during aggregation :: caused by :: cannot sort with keys that are parallel arrays",
"code" : 2,
"codeName" : "BadValue"
}
Even though "$x.a" & "$x.b" from {x: [{a: 1, b: 2}, {a: 2, b: 3}]} are not truly parallel arrays, we refuse to generate sort key, saying "cannot sort with keys that are parallel arrays". One example of true parallel arrays is {x: {a: [1, 2], b: [0, -1]}}. For parallel arrays, ordering by one array may not agree with order by the other array.
Interestingly enough, in SBE, both pipelines succeed but 6.0 & 7.0 show the same behavior as the above: pipeline1 succeeds and pipeline2 fails with the same error.
This issue occurs in the 8.0 classic pipeline and 6.0 and 7.0 for $group w/ $top. The same issue would occur for $bottom/$topN/$bottomN.
- is caused by
-
SERVER-82368 Match top/bottom N accumulators in SBE and Classic
-
- Closed
-