我有一个设备集合,其中设置了以下索引:
nextLine()
我的文档如下:
{
"v" : 1,
"key" :
{ "sdk.id" : 1,
"sdk.createdAt" : 1,
"sdk.updatedAt" : 1,
"deviceInfo.isTablet" : 1 },
"name" : "sdk.id_1_sdk.createdAt_1_sdk.updatedAt_1_deviceInfo.isTablet_1",
"ns" : "company.Device"
}
当我{
_id: ObjectId("something"),
property: 'abcd',
sdk: [
{ id: 'ab', createdAt: new Date(), updatedAt: new Date()},
{ id: 'ac', createdAt: new Date(), updatedAt: new Date()},
]
}
时,我得到:
db.Device.explain(1).find({'sdk.id': 'ab'}).count()
正如您所看到的那样,请求非常非常缓慢,只有在我们切换到WiredTiger之后才会出现这种情况(之前就已经过了)。
该集合包含约600,000个文档,并且有大约550,000个文档{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "company.Device",
"indexFilterSet" : false,
"parsedQuery" : {
"sdk.id" : {
"$eq" : "ab"
}
},
"winningPlan" : {
"stage" : "COUNT",
"inputStage" : {
"stage" : "COUNT_SCAN",
"keyPattern" : {
"sdk.id" : 1,
"sdk.createdAt" : 1,
"sdk.updatedAt" : 1,
"deviceInfo.isTablet" : 1
},
"indexName" : "sdk.id_1_sdk.createdAt_1_sdk.updatedAt_1_deviceInfo.isTablet_1",
"isMultiKey" : true
}
},
"rejectedPlans" : [ ]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 0,
"executionTimeMillis" : 712,
"totalKeysExamined" : 569865,
"totalDocsExamined" : 0,
"executionStages" : {
"stage" : "COUNT",
"nReturned" : 0,
"executionTimeMillisEstimate" : 636,
"works" : 569865,
"advanced" : 0,
"needTime" : 569864,
"needFetch" : 0,
"saveState" : 4452,
"restoreState" : 4452,
"isEOF" : 1,
"invalidates" : 0,
"nCounted" : 569863,
"nSkipped" : 0,
"inputStage" : {
"stage" : "COUNT_SCAN",
"nReturned" : 569863,
"executionTimeMillisEstimate" : 616,
"works" : 569864,
"advanced" : 569863,
"needTime" : 1,
"needFetch" : 0,
"saveState" : 4452,
"restoreState" : 4452,
"isEOF" : 1,
"invalidates" : 0,
"keysExamined" : 569865,
"keyPattern" : {
"sdk.id" : 1,
"sdk.createdAt" : 1,
"sdk.updatedAt" : 1,
"deviceInfo.isTablet" : 1
},
"indexName" : "sdk.id_1_sdk.createdAt_1_sdk.updatedAt_1_deviceInfo.isTablet_1",
"isMultiKey" : true
}
},
"allPlansExecution" : [ ]
},
"serverInfo" : {
"host" : "rs-primary",
"port" : 27000,
"version" : "3.0.2",
"gitVersion" : "6201872043ecbbc0a4cc169b5482dcf385fc464f"
},
"ok" : 1
}
$ eq ab。
有人能解释一下上面的解释吗?我无法找到有关isEOF,saveState和restoreState
的任何信息由于
答案 0 :(得分:1)
isEOF :指定执行阶段是否已到达流的结尾
saveState和restoreState :在Mongo 3.0中,这些是查询阶段产生(saveState)然后恢复(restoreState)的次数的计数器。例如,集合扫描(COLLSCAN)阶段可能需要屈服以获取尚未在内存中的文档。查询也会产生,因此它们可以与其他查询交错,并通过$ maxTimeMS或kill操作安全地停止。
这些不是很有趣的数字。如果您对同一查询运行多个连续说明,您会注意到数字会根据当时的其他操作而变化,以及当时是否所有必需的文档都在内存中。