|
The partial filter expression contains a scalar equality expression : "bool" : true
db.coll.getIndexes()
|
[
|
...
|
{
|
"v" : 1,
|
"key" : {
|
"timestamp" : 1,
|
"userId" : 1
|
},
|
"name" : "timestamp_1_userId_1",
|
"ns" : "...",
|
"background" : true,
|
"partialFilterExpression" : {
|
"bool" : true
|
}
|
}
|
]
|
A query contains the index fields, projects the index field and uses the single possible value for the partial expression:
db.coll.explain("executionStats").find({ timestamp: { $gte: 1511041284 }, userId: { $in: [ 1,2,3,4 ]}, bool: true },{timestamp: 1, userId:1, _id:0 })
|
{
|
...
|
"executionStats" : {
|
"executionSuccess" : true,
|
"nReturned" : 2,
|
"executionTimeMillis" : 14,
|
"totalKeysExamined" : 294,
|
"totalDocsExamined" : 2,
|
"executionStages" : {
|
"stage" : "PROJECTION",
|
"nReturned" : 2,
|
"executionTimeMillisEstimate" : 0,
|
"works" : 296,
|
"advanced" : 2,
|
"needTime" : 292,
|
"needYield" : 0,
|
"saveState" : 4,
|
"restoreState" : 4,
|
"isEOF" : 1,
|
"invalidates" : 0,
|
"transformBy" : {
|
"timestamp" : 1,
|
"userId" : 1,
|
"_id" : 0
|
},
|
"inputStage" : {
|
"stage" : "FETCH",
|
"filter" : {
|
"bool" : {
|
"$eq" : true
|
}
|
},
|
"nReturned" : 2,
|
"executionTimeMillisEstimate" : 0,
|
"works" : 296,
|
"advanced" : 2,
|
"needTime" : 292,
|
"needYield" : 0,
|
"saveState" : 4,
|
"restoreState" : 4,
|
"isEOF" : 1,
|
"invalidates" : 0,
|
"docsExamined" : 2,
|
"alreadyHasObj" : 0,
|
"inputStage" : {
|
"stage" : "IXSCAN",
|
"nReturned" : 2,
|
"executionTimeMillisEstimate" : 0,
|
"works" : 295,
|
"advanced" : 2,
|
"needTime" : 292,
|
"needYield" : 0,
|
"saveState" : 4,
|
"restoreState" : 4,
|
"isEOF" : 1,
|
"invalidates" : 0,
|
"keyPattern" : {
|
"timestamp" : 1,
|
"userId" : 1
|
},
|
"indexName" : "timestamp_1_userId_1",
|
"isMultiKey" : false,
|
"isUnique" : false,
|
"isSparse" : false,
|
"isPartial" : true,
|
"indexVersion" : 1,
|
"direction" : "forward",
|
"indexBounds" : {
|
"timestamp" : [
|
"[1511041284.0, inf.0]"
|
],
|
"userId" : [
|
...
|
Under such conditions, shouldn't it be enough for the index to cover the query?
|