MongoDB中怎么查看执行计划方法

39次阅读
没有评论

共计 1671 个字符,预计需要花费 5 分钟才能阅读完成。

自动写代码机器人,免费开通

这期内容当中丸趣 TV 小编将会给大家带来有关 MongoDB 中怎么查看执行计划方法,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

db.chenfeng.find()
{_id : ObjectId( 5714419cf7c81959e12a904e), age : 1, name : duansf }
{_id : ObjectId( 571441a3f7c81959e12a904f), age : 2, name : duansf }
{_id : ObjectId( 571441a7f7c81959e12a9050), age : 3, name : duansf }
{_id : ObjectId( 571441abf7c81959e12a9051), age : 4, name : duansf }
{_id : ObjectId( 571442b0f7c81959e12a9052), age : 5, name : duansf }
{_id : ObjectId( 571442bcf7c81959e12a9053), age : 6, name : duansf }

db.chenfeng.find().explain()
{
        cursor : BasicCursor ,
        isMultiKey : false,
        n : 6,
        nscannedObjects : 6,
        nscanned : 6,
        nscannedObjectsAllPlans : 6,
        nscannedAllPlans : 6,
        scanAndOrder : false,
        indexOnly : false,
        nYields : 0,
        nChunkSkips : 0,
        millis : 0,
        server : XCC-Duanshufeng:27017 ,
        filterSet : false
}

加 hint 强制使用索引方法, 这点和关系数据库特别像:
db.chenfeng.find().hint({age:6}).explain()
{
        cursor : BtreeCursor idx_age_6 ,
        isMultiKey : false,
        n : 6,
        nscannedObjects : 6,
        nscanned : 6,
        nscannedObjectsAllPlans : 6,
        nscannedAllPlans : 6,
        scanAndOrder : false,
        indexOnly : false,
        nYields : 1,
        nChunkSkips : 0,
        millis : 135,
        indexBounds : {
                age : [
                        [
                                {
                                        $minElement : 1
                                },
                                {
                                        $maxElement : 1
                                }
                        ]
                ]
        },
        server : XCC-Duanshufeng:27017 ,
        filterSet : false
}

字段说明:
cursor:返回游标类型,有 BasicCursor 和 BtreeCursor,BtreeCursor 意味着使用了索引
nscanned:扫描 document 的行数
nscannedObjects:扫描对象的数量
n:返回的文档行数
millis:耗时(毫秒)
indexBounds:如果不为空,表示此查询使用的索引信息
server:MongoDB 所在的服务器名字,27017 是端口号

索引的限制:
索引名称不能超过 128 个字符
每个集合不能超过 64 个索引
复合索引不能超过 31 列

上述就是丸趣 TV 小编为大家分享的 MongoDB 中怎么查看执行计划方法了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注丸趣 TV 行业资讯频道。

向 AI 问一下细节

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-12-04发表,共计1671字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)