-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Background
We allowed $match pushdown past $replaceRoot when the new root unnests a path in SERVER-88220:
{$replaceWith: "$subDocument"}, {$match: {x: 2}}
| | |
v v v
{$match: {"subDocument.x": 2}}, {$replaceWith: "$subDocument"}
This is implemented as a special case, where we observe that $replaceRoot is followed by a $match and we construct a GetModifiedPaths specially for the paths referred to by the $match. In this case renames {subDocument.x => x}. This allows us to use the splitMatchByModifiedFields code to rewrite the $match.
Proposal
To implement a more general solution, which allows the RBR rules to "look past" a $replaceRoot in general.
For example, we should be able to rewrite $sort on "x" after $replaceRoot in the above example to $sort on "subDocument.x" before the $replaceRoot.
Note that there is a complication arising from the fact that $replaceRoot validates that the path is an object, and fails if not. This means we need to somehow preserve this behaviour during such rewrites. This is not a problem for $sort, but it could be in other cases.
- is related to
-
SERVER-88220 Enable match pushdown for replaceRoot
-
- Closed
-