-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Optimization
-
ALL
-
-
8
The following aggregation pipeline produces incorrect result when run with disabled optimization:
db.xxx.aggregate([ {$match: {a: {$ne: 2}}}, {$match: {b: {$exists: false}}}, {"$count" : "a"} ]);
The incorrect result is observed both with classic and sbe engines.
If we remove the $count stage, the pipeline produces correct result.
The pipeline works correctly with optimization and with a collection scan if the index does not exist.
The execution stats on the second $match expression `{$match: {b: {$exists: false}}}` shows 1 returned result in the pipeline without $count, and 0 nReturned in the other case. See the full explain in the attachments.
// no $count: {"$match" : { "b" : { "$not" : { "$exists" : true } } }, "nReturned" : NumberLong(1), "executionTimeMillisEstimate" : NumberLong(1) }, ... // with $count {"$match" : { "b" : { "$not" : { "$exists" : true } } }, "nReturned" : NumberLong(0), "executionTimeMillisEstimate" : NumberLong(1) }, ...
- duplicates
-
SERVER-23229 Projection incorrectly returns null value instead of missing field to user if projection is covered
- Backlog