-
Type:
Bug
-
Resolution: Duplicate
-
Priority:
Major - P3
-
None
-
Affects Version/s: 3.4.4
-
Component/s: Querying
-
None
-
Query
-
ALL
-
(copied to CRM)
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Performing a count on a collection with a partial index leads to IXSCAN/FETCH/COUNT, rather than the more efficient COUNT_SCAN. By contrast, a count on a regular index does lead to a COUNT_SCAN.
For example:
db.coll.createIndex({"value":1}, {"partialFilterExpression":{"flag":true}})
db.coll.explain(true).count({"flag":true,"value":10})
...
"winningPlan" : {
"stage" : "COUNT",
"inputStage" : {
"stage" : "FETCH",
"filter" : {
"flag" : {
"$eq" : true
}
},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"value" : 1
},
"indexName" : "value_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"value" : [ ]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : true,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"value" : [
"[10.0, 10.0]"
]
}
}
}
},
...
Here is the same example with a compound index on (flag, value):
db.coll.createIndex({"flag":1, "value":1})
db.coll.explain(true).count({"flag":true,"value":10})
...
"winningPlan" : {
"stage" : "COUNT",
"inputStage" : {
"stage" : "COUNT_SCAN",
"keyPattern" : {
"flag" : 1,
"value" : 1
},
"indexName" : "flag_1_value_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"flag" : [ ],
"value" : [ ]
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"indexBounds" : {
"startKey" : {
"flag" : true,
"value" : 10
},
"startKeyInclusive" : true,
"endKey" : {
"flag" : true,
"value" : 10
},
"endKeyInclusive" : true
}
}
},
This issue is related to, but distinct from, other cases where partial indexes are not utilized to the full extent, such as SERVER-23808, SERVER-28889.
- duplicates
-
SERVER-28889 Partial index shouldn't do fetch on conditions that are true by the definition of the index
-
- Closed
-
- is related to
-
SERVER-23808 Implement Index Choice based on Partial Filter Expression
-
- Backlog
-
-
SERVER-28889 Partial index shouldn't do fetch on conditions that are true by the definition of the index
-
- Closed
-