-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
Take this $elemMatch predicate:
{a: {$elemMatch: {b: 2, c: 3}}}
It expands to this ABT:
| PathGet [a] | PathTraverse [1] | PathComposeM [] | | PathComposeA [] | | | PathArr [] | | PathObj [] | PathComposeM [] | | PathGet [c] PathTraverse [1] PathCompare [Eq] Const [3] | PathGet [b] PathTraverse [1] PathCompare [Eq] Const [2]
The last 3 lines correspond to b: 2, c: 3. This predicate can only be true when applied to an object. So the extra PathObj / PathArr checks are redundant: we can replace them with true / false respectively.
It's not enough to check for a PathGet however. A predicate like b: {$exists: false} can be true when applied to a non-object, because it uses PathDefault which can "catch" Nothing. Other nodes like this include PathConstant and PathLambda.
- is related to
-
SERVER-77499 [CQF] Add predicates to SargableNode about fields which are implied by existing predicates on dotted fields
- Open