-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 4.0.10, 4.2.0-rc6
-
Component/s: Index Maintenance, Querying
-
None
-
ALL
-
I have this index on my collection:
db.getCollection('companies').createIndex({"financial.gross": -1}, {partialFilterExpression: {"state": "open", "financial.gross": {$exists: true}}, name: "company-open-gross"});
Then I want to count the documents in the index:
db.getCollection('companies').explain("executionStats").count({"financial.gross": {$exists: true}, state: "open"})
It does use the index created, but there is still a filter stage where both financial.gross and state are tested, as seen in the execution stats (attached). It shouldn't filter at all, since those conditions are the exact same as the partialFilterExpression.
Ironically, doing something like:
db.getCollection('companies').explain("executionStats").count({"financial.gross": {$gte: 0}, state: "open"})
is faster since then it only filters on state.
- duplicates
-
SERVER-28889 Partial index shouldn't do fetch on conditions that are true by the definition of the index
- Closed