-
Type: Bug
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Execution
-
ALL
-
SBE supports nested loop join (NLJ) plans for executing $lookup queries. Such plans will perform a collection scan of the inner collection for every document read from the $lookup's outer side. Following my example from the attached repro script, imagine a $lookup from an "outer" collection to an "inner" collection on the "key" field, where each collection contains the following documents:
// Contents of "outer" {key: 41} {key: 42} {key: 43} {key: 44} // Contents of "inner" {key: 42}
There are 4 documents on the outer side. Therefore, an NLJ plan would scan the inner collection 4 times.
We report the number of collection scans executed over a collection as part of the queryExecStats field of the $collStats output. However, for an SBE NLJ plan such as the one I described above, the number of collection scans will get incremented just once for the entire query rather than once for each scan of the inner side that is actually performed at runtime.
It's unclear whether this was intentional or not, but it seems more useful from the diagnostic perspective to know the total number of scans of the data performed rather than the number of queries that may perform one or more collection scans.