-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
-
None
-
3
-
TBD
-
None
-
None
-
None
-
None
-
None
-
None
-
None
$and/$or should have identical behaviour in $expr land as in match land. Currently, when we have an expression like
{$expr: {$and/$or ... <expr-subtree>}}
we try to convert the whole subtree into a match expression, then rewrite this to
{$and/$or: [{$expr: {$and/$or ... <expr-subtree>}}, {<match-version-of-expr-subtree>}] }
however, if we fail for any subexpression in the subtree, we fail to do this for the entire thing. This means that if we had one sargable predicate in the subtree that could be rewritten, but another non-sargable predicate, we won't extract either, and hence won't be able to leverage an index scan on the sargable predicate.
We should look into doing the following rewrite generally instead:
{$and/$or: [{$expr: {$and/$or: <expr-subtree>}}, ... subtrees that could be converted to $match]}
(Note: $and probably is fine, $or may be trickier. Would need to investigate).
- related to
-
SERVER-107804 Investigate feasibility of using indexes for indexed fields in nested aggregate expressions
-
- Closed
-