-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 4.2.10
-
Component/s: Index Maintenance, Querying
-
None
-
ALL
-
If you're doing a query with $exists, it takes much more time than doing a query by value.
Example query: db.getCollection('test').find({status: {$exists: false}}, {}).count()
Explain looks like this:
"winningPlan" : {
"stage" : "FETCH",
"filter" : {
"status" : {
"$not" :
}},
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" :
,
"indexName" : "status_1",
"isMultiKey" : false,
"multiKeyPaths" :
,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" :
}},
So, there is IXSCAN and next FETCH with filter. Why filter is here?
This is explain for db.getCollection('test').find({status: 1}, {}).count():
"queryHash" : "E6304EB6",
"planCacheKey" : "7A94191B",
"winningPlan" : {
"stage" : "FETCH",
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" :
,
"indexName" : "status_1",
"isMultiKey" : false,
"multiKeyPaths" :
,
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" :
}},
As you can see, there are no filter in FETCH, and this query is faster.
I tried it in cloud.mongodb.com on 4.2.10.
- duplicates
-
SERVER-12869 Index null values and missing values differently
- Backlog