MongoDB学习之Explain执行计划
时间:2023-02-16
浏览:288
作者:佚名
IT行业相对于一般传统行业,发展更新速度更快,一旦停止了学习,很快就会被行业所淘汰。所以我们需要踏踏实实的不断学习,精进自己的技术,尤其是初学者。今天golang学习网给大家整理了《MongoDB学习之Explain执行计划》,聊聊MySQL、JSON、mongodb、数据库、NoSQL,我们一起来看看吧!
db.collection.find().explain(verbose)
{
"queryPlanner":{
"plannerVersion":1,
"namespace":"mock.users",
"indexFilterSet":false,
"parsedQuery":{
"age":{
"$gte":10
}
},
"winningPlan":{
"stage":"FETCH",
"inputStage":{
"stage":"IXSCAN",
"keyPattern":{
"age":1,
"username":1
},
"indexName":"age_1_username_1",
"isMultiKey":false,
"multiKeyPaths":{
"age":[
],
"username":[
]
},
"isUnique":false,
"isSparse":false,
"isPartial":false,
"indexVersion":2,
"direction":"forward",
"indexBounds":{
"age":[
"[10, inf.0]"
],
"username":[
"[MinKey, MaxKey]"
]
}
}
},
"rejectedPlans":[
{
"stage":"FETCH",
"inputStage":{
"stage":"IXSCAN",
"keyPattern":{
"age":1
},
"indexName":"age_1",
"isMultiKey":false,
"multiKeyPaths":{
"age":[
]
},
"isUnique":false,
"isSparse":false,
"isPartial":false,
"indexVersion":2,
"direction":"forward",
"indexBounds":{
"age":[
"[10, inf.0]"
]
}
}
}
]
},
"executionStats":{ --这个集合是executionStats&allPlansExecution模式才有的
"executionSuccess":true,
"nReturned":680520,
"executionTimeMillis":1121,
"totalKeysExamined":680520,
"totalDocsExamined":680520,
"executionStages":{
"stage":"FETCH",
"nReturned":680520,
"executionTimeMillisEstimate":143,
"works":680521,
"advanced":680520,
"needTime":0,
"needYield":0,
"saveState":680,
"restoreState":680,
"isEOF":1,
"docsExamined":680520,
"alreadyHasObj":0,
"inputStage":{
"stage":"IXSCAN",
"nReturned":680520,
"executionTimeMillisEstimate":43,
"works":680521,
"advanced":680520,
"needTime":0,
"needYield":0,
"saveState":680,
"restoreState":680,
"isEOF":1,
"keyPattern":{
"age":1,
"username":1
},
"indexName":"age_1_username_1",
"isMultiKey":false,
"multiKeyPaths":{
"age":[
],
"username":[
]
},
"isUnique":false,
"isSparse":false,
"isPartial":false,
"indexVersion":2,
"direction":"forward",
"indexBounds":{
"age":[
"[10, inf.0]"
],
"username":[
"[MinKey, MaxKey]"
]
},
"keysExamined":680520,
"seeks":1,
"dupsTested":0,
"dupsDropped":0
}
},
"allPlansExecution":[ --这是allPlansExecution执行才会有的返回集合
{
"nReturned":101,
"executionTimeMillisEstimate":0,
"totalKeysExamined":101,
"totalDocsExamined":101,
"executionStages":{
.......
}
}
]
},
"serverInfo":{
"host":"supman",
"port":27017,
"version":"4.4.10",
"gitVersion":"58971da1ef93435a9f62bf4708a81713def6e88c"
},
"ok":1
}详解
db.users.createIndex({"username":1},{unique:true"})db.users.createIndex({"email":1},{sparse:true"})db.users.createIndex({age:1},{partialFilterExpression:{age:{"$gte":25}}})如上,这种索引只在查询条件为
db.users.find().sort() --这种情况是forward db.users.find().sort({age:-1}) --这种情况是backwardindexVersion
索引版本indexBounds
所扫描的索引范围,例如indexBounds: { age: [ '[36, 38]' ] } } }就是代表扫描[36,38]
这个区间的age
字段的索引rejectedPlans
拒绝计划,非最优的执行计划,它的字段与winningPlan
一样不再描述- .......
serverInfo
MongoDB服务器信息
host
主机名称port
端口version
服务版本gitVersion
git
版本号
executionStats包含一些统计信息
executionSuccesss
是否执行成nReturned
表示返回的行数executionTimeMillis
执行耗时,单位毫秒totalKeysExamined
索引扫描次数totalDocsExamined
文档扫描次数executionStages
成功的计划详情,下面的很多字段在上面已经陈述过了,在这里就不再写了works
工作单元数,一个查询会分解成很多小的查询单元advanced
优先返回的结果数needTime
未将中间结果推进到其父级的工作周期数needYield
存储层查询产生锁的次数isEOF
指定执行阶段是否达到流结束- ......
inputStage
seeks
为了完成索引扫描(stage),执行器必须将游标定位到新位置的次数- ......
allPlansExecution含有所有执行计划
- .......
撒花结束
哈哈,终于搞完了还有几个字段没有搞清楚
dupsTested、
saveState,不过有了上面这些内容对整个执行计划的基本拿捏肯定不成问题
今天关于《MongoDB学习之Explain执行计划》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于mysql的内容请关注golang学习网公众号!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
热门专题
