explain.queryPlanner: queryPlanner的返回web
explain.queryPlanner.namespace:該值返回的是該query所查詢的表mongodb
explain.queryPlanner.indexFilterSet:針對該query是否有indexfilter優化
explain.queryPlanner.winningPlan:查詢優化器針對該query所返回的最優執行計劃的詳細內容。spa
explain.queryPlanner.winningPlan.stage:最優執行計劃的stage,這裏返回是FETCH,能夠理解爲經過返回的index位置去檢索具體的文檔(stage有數個模式,將在後文中進行詳解)。orm
Explain.queryPlanner.winningPlan.inputStage:用來描述子stage,而且爲其父stage提供文檔和索引關鍵字。排序
explain.queryPlanner.winningPlan.stage的child stage,此處是IXSCAN,表示進行的是index scanning。索引
explain.queryPlanner.winningPlan.keyPattern:所掃描的index內容,此處是did:1,status:1,modify_time: -1與scid : 1ip
explain.queryPlanner.winningPlan.indexName:winning plan所選用的index。內存
explain.queryPlanner.winningPlan.isMultiKey是不是Multikey,此處返回是false,若是索引創建在array上,此處將是true。ci
explain.queryPlanner.winningPlan.direction:此query的查詢順序,此處是forward,若是用了.sort({modify_time:-1})將顯示backward。
explain.queryPlanner.winningPlan.indexBounds:winningplan所掃描的索引範圍,若是沒有制定範圍就是[MaxKey, MinKey],這主要是直接定位到mongodb的chunck中去查找數據,加快數據讀取。
explain.queryPlanner.rejectedPlans:其餘執行計劃(非最優而被查詢優化器reject的)的詳細返回,其中具體信息與winningPlan的返回中意義相同,故不在此贅述。
2.2 executionStats返回結構的意義
"executionStats" : {
"executionSuccess" : ,
"nReturned" : ,
"executionTimeMillis" : ,
"totalKeysExamined" : ,
"totalDocsExamined" : ,
"executionStages" : {
"stage" :
"nReturned" : ,
"executionTimeMillisEstimate" : ,
"works" : ,
"advanced" : ,
"needTime" : ,
"needYield" : ,
"isEOF" : ,
...
"inputStage" : {
"stage" : ,
...
"nReturned" : 0,
"executionTimeMillisEstimate" : ,
...
"inputStage" : {
...
}
}
},
executionStats.executionSuccess:是否執行成功
executionStats.nReturned:知足查詢條件的文檔個數,即查詢的返回條數
executionStats.executionTimeMillis:總體執行時間
executionStats.totalKeysExamined:索引總體掃描的文檔個數,和早起版本的nscanned 是同樣的
executionStats.totalDocsExamined:document掃描個數, 和早期版本中的nscannedObjects 是同樣的
executionStats.executionStages:整個winningPlan執行樹的詳細信息,一個executionStages包含一個或者多個inputStages
executionStats.executionStages.stage:這裏是FETCH去掃描對於documents,後面會專門用來解釋大部分查詢使用到的各類stage的意思
executionStats.executionStages.nReturned:因爲是FETCH,因此這裏該值與executionStats.nReturned一致
executionStats.executionStages.docsExamined:與executionStats.totalDocsExamined一致executionStats.inputStage中的與上述理解方式相同
explain.executionStats.executionStages.works:被查詢執行階段所操做的「工做單元(work units)」數。
explain.executionStats.executionStages.advanced:優先返回給父stage的中間結果集中文檔個數
explain.executionStats.executionStages.isEOF:查詢執行是否已經到了數據流的末尾
這些值的初始值都是0。Works的 值當isEOF爲1時要比nReturned大1, isEOF爲0是相同。
2.3 stage的類型的意義
mongodb的文檔中列出了前4種類型,還有一些沒有列出來,可是會比較常見,這裏一併解釋一下。
COLLSCAN :全表掃描
IXSCAN:索引掃描
FETCH::根據索引去檢索指定document
SHARD_MERGE:各個分片返回數據進行merge
SORT:代表在內存中進行了排序(與前期版本的scanAndOrder:true一致)
SORT_MERGE:代表在內存中進行了排序後再合併
LIMIT:使用limit限制返回數
SKIP:使用skip進行跳過
IDHACK:針對_id進行查詢
SHARDING_FILTER:經過mongos對分片數據進行查詢
COUNT:利用db.coll.count()之類進行count運算
COUNTSCAN:count不使用用Index進行count時的stage返回
COUNT_SCAN:count使用了Index進行count時的stage返回
SUBPLA:未使用到索引的$or查詢的stage返回
TEXT:使用全文索引進行查詢時候的stage返回