This is very similar to SERVER-50246, however in that case there was no document source rewrite taking place per se but simply executing the sub-pipeline as part of explain was losing stages in the sub-pipeline that were eligible to push into the find layer. For instance, SERVER-50246 would fix an issue like this:
[{$unionWith: {coll: "test", pipeline: [{$match: {_id: 1}}]}}]
However, there was an oversight with the implementation whereby the inner $match can actually come from a rewrite for a pipeline like this:
[{$unionWith: "test"}, {$match: {_id: 1}}]
which gets optimized to:
[{$match: {_id: 1}}, {$unionWith: {coll: "test", pipeline: [{$match: {_id: 1}}]}}]
The current explain output for the second example does not include the $match pushdown, and subsequently may not show the correct access plan (e.g. IXSCAN on _id).
- is caused by
-
SERVER-50246 $unionWith explain loses information from any stages in sub-pipeline which get absorbed into cursor stage
- Closed
- is related to
-
SERVER-50597 Explain against a pipeline containing $unionWith does not accurately count executionStats from sub-pipeline
- Backlog