-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
-
Query Execution
Currently when evaluating something like {$size: '$a.b'} on a document like {a: [{b:1},{b:2}, ...]} we will first evaluate the ExpressionFieldPath which will produce an array of the values of b, then we ask for the size of that array. This is wasteful, and is even more wasteful if you consider '$a.b.c.d' where each level is an array of object since only the size of the a array matters in that case. (I'm not arguing that these semantics are good, but that is what we do today). Instead we should have an ExpressionSizeOfFieldPath that just returns the size of the top-level array that ExpressionFieldPath would create, but without making any new arrays.
I have a profile where over 20% of the time is spent in the unnecessary ExpressionFieldPath for the simple '$a.b' case. I assume it would be even worse for '$a.b.c.d.