I’m analyzing a count command on a collection, which has 440k docs:
db.collection.count({"a" : 100, "b" : {$in : [1, 4]}, "c" : -1, "d" : {$in : [1,2,3]}, "e" : "hello"})
In order to improve the performance, I create the following index:
{"a" : -1, "b" : -1, "c" : -1, "d" : -1, "e" : -1}
The result of explain
shows that mongodb does a IXSCAN
step to do the counting. However, I’m confused by the executionTimeMillis:
{
"executionStats": {
"executionSuccess": true,
"nReturned": 141603,
"executionTimeMillis": 177, <-------------
"totalKeysExamined": 141604,
"totalDocsExamined": 0,
"executionStages": {
"stage": "IXSCAN",
"nReturned": 141603,
"executionTimeMillisEstimate": 13 <-----------
}
}
}
You can see that executionStats.executionTimeMillis is much larger than executionStats.executionStages.executionTimeMillisEstimate .
It seem that the IXSCAN step only takes 13ms, but why count takes 117ms? Is it possible to optimize this?