我可以帮您进行翻译。以下是需要翻译的内容:
我的一个集合中有1644662条记录,我已经在名为“document_type_id”的列上创建了索引。当我运行查询时
db.getCollection('my_collection').find({"document_type_id": {"$in": ["7"]}}).count()
当我运行一个查询时,它在0.285秒内返回了计数为“753800”的结果。
db.getCollection('my_collection').find({"document_type_id": {"$in": ["3"]}}).count()
当我分别运行这两个查询时,它们都能完美地返回计数"819438"并且用时0.365秒。但是当我将这两个查询组合在一起运行时问题就来了。
db.getCollection('my_collection').find({"document_type_id": {"$in": ["3", "7"]}}).count()
这个查询需要54秒才能返回计数。第三个查询的执行计划如下:
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "test.my_collection",
"indexFilterSet" : false,
"parsedQuery" : {
"document_type_id" : {
"$in" : [
"3",
"7"
]
}
},
"winningPlan" : {
"stage" : "COUNT",
"inputStage" : {
"stage" : "FETCH",
"inputStage" : {
"stage" : "IXSCAN",
"keyPattern" : {
"document_type_id" : 1.0
},
"indexName" : "document_type_id_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"document_type_id" : []
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"document_type_id" : [
"[\"3\", \"3\"]",
"[\"7\", \"7\"]"
]
}
}
}
},
"rejectedPlans" : []
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 0,
"executionTimeMillis" : 74166,
"totalKeysExamined" : 1573238,
"totalDocsExamined" : 1573238,
"executionStages" : {
"stage" : "COUNT",
"nReturned" : 0,
"executionTimeMillisEstimate" : 73504,
"works" : 1573239,
"advanced" : 0,
"needTime" : 1573238,
"needYield" : 0,
"saveState" : 14007,
"restoreState" : 14007,
"isEOF" : 1,
"invalidates" : 0,
"nCounted" : 1573238,
"nSkipped" : 0,
"inputStage" : {
"stage" : "FETCH",
"nReturned" : 1573238,
"executionTimeMillisEstimate" : 73253,
"works" : 1573239,
"advanced" : 1573238,
"needTime" : 0,
"needYield" : 0,
"saveState" : 14007,
"restoreState" : 14007,
"isEOF" : 1,
"invalidates" : 0,
"docsExamined" : 1573238,
"alreadyHasObj" : 0,
"inputStage" : {
"stage" : "IXSCAN",
"nReturned" : 1573238,
"executionTimeMillisEstimate" : 2729,
"works" : 1573239,
"advanced" : 1573238,
"needTime" : 0,
"needYield" : 0,
"saveState" : 14007,
"restoreState" : 14007,
"isEOF" : 1,
"invalidates" : 0,
"keyPattern" : {
"document_type_id" : 1.0
},
"indexName" : "document_type_id_1",
"isMultiKey" : false,
"multiKeyPaths" : {
"document_type_id" : []
},
"isUnique" : false,
"isSparse" : false,
"isPartial" : false,
"indexVersion" : 2,
"direction" : "forward",
"indexBounds" : {
"document_type_id" : [
"[\"3\", \"3\"]",
"[\"7\", \"7\"]"
]
},
"keysExamined" : 1573238,
"seeks" : 1,
"dupsTested" : 0,
"dupsDropped" : 0,
"seenInvalidated" : 0
}
}
}
},
"serverInfo" : {
"host" : "nb-fara",
"port" : 27017,
"version" : "3.4.9",
"gitVersion" : "876ebee8c7dd0e2d992f36a848ff4dc50ee6603e"
},
"ok" : 1.0
}
document_type_id
的值是字符串中的数字吗?Object.bsonsize(db.my_collection.findOne())