-
Type: Sub-task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Fully Compatible
-
QO 2023-05-15, QO 2023-05-29, QO 2023-06-12, QO 2023-06-26, QO 2023-07-10, QO 2023-07-24, QO 2023-08-07, QO 2023-08-21, QO 2023-09-04, QO 2023-09-18, QO 2023-10-02, QO 2023-10-16, QO 2023-10-30
Consider a filter expression such as Get "a" Arr. If "a" is never multikey this expression can never be true.
The task is to extend the logical rewrite which transforms a filter expression to do the above.
Specifically:
Given a collection coll with {id, x}{} where x is a scalar field (i.e., no arrays) and an index on field {}x{_}.
query:
db.coll.find({x : { $elemMatch: {$eq: 5 } } })
successfully recognizes that x is a scalar field and simplifies the expression to return nothing without scanning the collection.
On the other hand,
query:
db.coll.find({x : { $elemMatch:{y: 5}} })
which assumes a subfield y in x despite x being scalar and not having a y subfield, the query actually scans the whole collection. We observe the same behavior even when we have an index on x.y.
The ticket aims to alleviate this behavior and allow recognizing this opportunity for optimization.