1 为什么要执行explain,什么时候执行

explain的目的是将mongo的黑盒操作白盒化。

比如查询很慢的时候想知道原因。

2 explain的三种模式

2.1 queryPlanner

不会真正的执行查询,只是分析查询,选出winning plan。

2.2 executionStats

返回winning plan的关键数据。

executionTimeMillis该query查询的总体时间。

2.3 allPlansExecution

执行所有的plans。

通过explain("executionStats")来选择模式,默认是第一种模式。

3 queryPlanner分析

3.1 namespace

本次所查询的表。

3.2 indexFilterSet

是否使用partial index,比如只对某个表中的部分文档进行index。

3.3 parsedQuery

本次执行的查询

3.4 winning plan

3.4.1 stage

COLLSCAN:全表扫描

IXSCAN:索引扫描

FETCH:根据索引去检索指定document

SHARD_MERGE:将各个分片返回数据进行merge

SORT:表明在内存中进行了排序

LIMIT:使用limit限制返回数

SKIP:使用skip进行跳过

IDHACK:针对_id进行查询

winning plan的stage是一个树状结构,最外面的stage是根节点,然后inputStage或者inputStages里面的stage是它的子stage。

The explain results present the query plans as a tree of stages. Each stage passes its results (i.e. documents or index keys) to the parent node. The leaf nodes access the collection or the indices. The internal nodes manipulate the documents or the index keys that result from the child nodes. The root node is the final stage from which MongoDB derives the result set.

explain.queryPlanner.winningPlan.stage A string that denotes the name of the stage.

Each stage consists of information specific to the stage. For instance, an IXSCAN stage will include the index bounds along with other data specific to the index scan. If a stage has a child stage or multiple child stages, the stage will have an inputStage or inputStages.

explain.queryPlanner.winningPlan.inputStage A document that describes the child stage, which provides the documents or index keys to its parent. The field is present if the parent stage has only one child.

3.4.2 filter

对子stage返回的结果进行过滤,filter给本stage指明了fetch的条件。

3.4.3 inputStage

用于容纳一个子stage。

3.4.3.1 stage

子stage

3.4.3.2 indexName

所使用的索引的名字。

3.4.3.3 indexBounds

索引查找时使用的范围。

4 db.getCollection("AndroidDataReport").getIndexes()解析

每个json是一个索引,如果key有多个就是复合索引,复合索引的顺序很重要。

mongo explain分析详解的更多相关文章

  1. 转载:MySQL EXPLAIN 命令详解学习

    转载自:https://blog.csdn.net/mchdba/article/details/9190771 MySQL EXPLAIN 命令详解 MySQL的EXPLAIN命令用于SQL语句的查 ...

  2. MySQL EXPLAIN 命令详解

    MySQL EXPLAIN 命令详解 MySQL的EXPLAIN命令用于SQL语句的查询执行计划(QEP).这条命令的输出结果能够让我们了解MySQL 优化器是如何执行SQL 语句的.这条命令并没有提 ...

  3. Memcache的使用和协议分析详解

    Memcache的使用和协议分析详解 作者:heiyeluren博客:http://blog.csdn.NET/heiyeshuwu时间:2006-11-12关键字:PHP Memcache Linu ...

  4. wav文件格式分析详解

    wav文件格式分析详解 文章转载自:http://blog.csdn.net/BlueSoal/article/details/932395 一.综述    WAVE文件作为多媒体中使用的声波文件格式 ...

  5. 线程组ThreadGroup分析详解 多线程中篇(三)

    线程组,顾名思义,就是线程的组,逻辑类似项目组,用于管理项目成员,线程组就是用来管理线程. 每个线程都会有一个线程组,如果没有设置将会有些默认的初始化设置 而在java中线程组则是使用类ThreadG ...

  6. HanLP中人名识别分析详解

    HanLP中人名识别分析详解 在看源码之前,先看几遍论文<基于角色标注的中国人名自动识别研究> 关于命名识别的一些问题,可参考下列一些issue: l ·名字识别的问题 #387 l ·机 ...

  7. Explain 参数详解,重点部分已经全部完成,还有少数几个参数没不理解没标注。

    Explain 参数详解,重点部分已经全部完成,还有少数几个参数没不理解没标注.http://naotu.baidu.com/file/cdb631355392e317e1d925dc2e48f592 ...

  8. GC日志分析详解

    点击返回上层目录 原创声明:作者:Arnold.zhao 博客园地址:https://www.cnblogs.com/zh94 GC日志分析详解 以ParallelGC为例,YoungGC日志解释如下 ...

  9. MongoDB执行计划分析详解

    要保证数据库处于高效.稳定的状态,除了良好的硬件基础.高效高可用的数据库架构.贴合业务的数据模型之外,高效的查询语句也是不可少的.那么,如何查看并判断我们的执行计划呢?我们今天就来谈论下MongoDB ...

随机推荐

  1. Java获取运行环境信息

    在做视频截取封面的时候用到了ffmpeg.我采用的是通过Java调用bat或sh脚本然后生成图片文件. 在线上使用的是Centos 7.所以程序中需要获取到当前运行环境的信息来选择调用bat命令还是s ...

  2. oracle sql试题

    转载 数据准备 create table student(  sno varchar2(10) primary key,  sname varchar2(20),  sage number(3),  ...

  3. [转]js模块化编程之彻底弄懂CommonJS和AMD/CMD!

    原文: https://www.cnblogs.com/chenguangliang/p/5856701.html ------------------------------------------ ...

  4. AForge.NET Framework-2.2.5

    http://www.aforgenet.com/framework/downloads.html AForge.NET Framework-2.2.5 简介 AForge.NET是一个专门为开发者和 ...

  5. Node.js 内存泄露 定位

    之前我们在64位Linux服务器上使用Node.js时,当Node进程物理内存接近1.6G,由于谷歌V8引擎对内存的限制,会导致进程退出! 显然我们自身编码或npm加载的第3行模块存在内存泄露问题,那 ...

  6. 【转载】Loadrunner实现Android / IOS 手机APP压力测试

    随着手机APP用户量的增大,大的手机APP一般都需要进行压力测试,这几天用了loadrunner 12进行了手机APP的压力测试,整理了下,大家可以参考参考怎样给Andorid / IOS手机APP进 ...

  7. 【Nginx】HTTP配置模型

    当Nginx检測到配置文件里存在配置块http{}时.会建立一个ngx_http_conf_ctx_t结构体,该结构体定义例如以下: typedef struct { void **main_conf ...

  8. flex-direction用法解释

    语法: flex-direction:row | row-reverse | column | column-reverse 默认值:row 适用于:flex容器 继承性:无 动画性:否 计算值:指定 ...

  9. 百度js 获取定位城市名称

    首先引用百度 script <script type="text/javascript" src="http://api.map.baidu.com/api?typ ...

  10. Docker Push 镜像到公共仓库

    首选需要在https://hub.docker.com/上注册用户. 1.登录docker账号主要命令:docker login sudo docker login 2.推送镜像主要命令:docker ...