-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
Query Optimization
When a large array has format
a: [{b: 1}, {b: 2}, ...]
and aggregation does something like
{$slice: ["$a.b", 1, 2]}
then as array "a" gets larger, materializing it into "$a.b" becomes more expensive - and just taking $slice (or $arrayElemAt) and then extracting "a.b" can be significantly faster.
Discovered when working with very large arrays (over 10,000) and doing $slice and two $arrayElemAt operations in the same stage and having it perform 100x worse than explicitly taking slice first and then extracting b out of smaller result.