I have a pretty large DB for 180M documents and some indexes.
One such index is on the field block_height
. This field is present in every document.
Now, when I query for a particular block_height, I get the following execution plan (see below).
The query returns 6 documents. Problem is: there are 7 documents in the DB! I can find the missing document using its _id
no problem, but it will not show up in the query on block_height
.
How is this even possible? Any remedies?
Output of the Explain Plan:
{
"explainVersion": "1",
"queryPlanner": {
"namespace": "db.impacted_addresses",
"parsedQuery": {
"block_height": { "$eq": 5521120 }
},
"indexFilterSet": false,
"queryHash": "4D149BD8",
"planCacheKey": "F3CEF760",
"optimizationTimeMillis": 0,
"maxIndexedOrSolutionsReached": false,
"maxIndexedAndSolutionsReached": false,
"maxScansToExplodeReached": false,
"prunedSimilarIndexes": false,
"winningPlan": {
"isCached": false,
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": { "block_height": 1 },
"indexName": "block_height_1",
"isMultiKey": false,
"multiKeyPaths": { "block_height": [] },
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": 2,
"direction": "forward",
"indexBounds": {
"block_height": ["[5521120, 5521120]"]
}
}
},
"rejectedPlans": [
{
"isCached": false,
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": { "block_height": -1 },
"indexName": "block_height_-1",
"isMultiKey": false,
"multiKeyPaths": { "block_height": [] },
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": 2,
"direction": "forward",
"indexBounds": {
"block_height": ["[5521120, 5521120]"]
}
}
}
]
},
"executionStats": {
"executionSuccess": true,
"nReturned": 6,
"executionTimeMillis": 55,
"totalKeysExamined": 6,
"totalDocsExamined": 6,
"executionStages": {
"isCached": false,
"stage": "FETCH",
"nReturned": 6,
"executionTimeMillisEstimate": 21,
"works": 8,
"advanced": 6,
"needTime": 0,
"needYield": 0,
"saveState": 2,
"restoreState": 2,
"isEOF": 1,
"docsExamined": 6,
"alreadyHasObj": 0,
"inputStage": {
"stage": "IXSCAN",
"nReturned": 6,
"executionTimeMillisEstimate": 2,
"works": 7,
"advanced": 6,
"needTime": 0,
"needYield": 0,
"saveState": 2,
"restoreState": 2,
"isEOF": 1,
"keyPattern": { "block_height": 1 },
"indexName": "block_height_1",
"isMultiKey": false,
"multiKeyPaths": { "block_height": [] },
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": 2,
"direction": "forward",
"indexBounds": {
"block_height": ["[5521120, 5521120]"]
},
"keysExamined": 6,
"seeks": 1,
"dupsTested": 0,
"dupsDropped": 0
}
}
},
"command": {
"find": "impacted_addresses",
"filter": { "block_height": 5521120 },
"sort": { "block_height": 1 },
"skip": 0,
"limit": 0,
"maxTimeMS": 60000,
"$db": "db"
},
"serverInfo": {
"host": "e08b0e958b78",
"port": 27017,
"version": "8.0.0",
"gitVersion": "d7cd03b239ac39a3c7d63f7145e91aca36f93db6"
},
"serverParameters": {
"internalQueryFacetBufferSizeBytes": 104857600,
"internalQueryFacetMaxOutputDocSizeBytes": 104857600,
"internalLookupStageIntermediateDocumentMaxSizeBytes": 104857600,
"internalDocumentSourceGroupMaxMemoryBytes": 104857600,
"internalQueryMaxBlockingSortMemoryUsageBytes": 104857600,
"internalQueryProhibitBlockingMergeOnMongoS": 0,
"internalQueryMaxAddToSetBytes": 104857600,
"internalDocumentSourceSetWindowFieldsMaxMemoryBytes": 104857600,
"internalQueryFrameworkControl": "trySbeRestricted",
"internalQueryPlannerIgnoreIndexWithCollationForRegex": 1
},
"ok": 1,
"$clusterTime": {
"clusterTime": {
"$timestamp": "7425699293131964435"
},
"signature": {
"hash": "G6BwkviSJ+sPWfj6CT1MCtERInQ=",
"keyId": {
"low": 2,
"high": 1720210990,
"unsigned": false
}
}
},
"operationTime": {
"$timestamp": "7425699293131964435"
}
}`