-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 4.4.19, 6.0.5, 6.3.0-rc1
-
Component/s: None
-
Query Optimization
-
Minor Change
-
ALL
-
v7.0, v6.0, v5.0, v4.4
-
QO 2023-05-15, QO 2023-05-29, QO 2023-06-12, QO 2023-06-26, QO 2023-07-10
-
(copied to CRM)
Sample data:
[ { c: 1, p: [ { id: 1 } ] }, { c: 2, p: [ { id: 1 } ] }, { c: 3, p: [ { id: 1 } ] }, { c: 4, p: [ { id: 1 } ] } ]
Index must be present to trigger the bug:
{ "p.id": 1, c: 1}
Query in question:
db.test.find( {$and:[ {$or:[{c:{$lt:2}},{c:{$gt:3}}]}, {p:{$elemMatch:{id:{$eq:1,$exists:true}}}} ]} )
Without the index, it matches two documents. With index but without (redundant) $exists:true inside $elemMatch it also returns two documents. But with index and with redundant exists it fails to return any documents.
- is related to
-
SERVER-78260 Contained $or rewrite optimization incorrectly lifts a negation predicate outside an $elemMatch leading to missing query results
- Closed
- related to
-
SERVER-78260 Contained $or rewrite optimization incorrectly lifts a negation predicate outside an $elemMatch leading to missing query results
- Closed