Details
-
Bug
-
Status: Closed
-
Major - P3
-
Resolution: Duplicate
-
3.4.4
-
None
-
None
-
Query
-
ALL
Description
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.
Attachments
Issue Links
- duplicates
-
SERVER-28889 Partial index shouldn't do fetch on conditions that are true by the definition of the index
-
- Open
-
- 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
-
- Open
-