• mongo explain分析详解


    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有多个就是复合索引,复合索引的顺序很重要。

  • 相关阅读:
    使用事件模式(Event API)读取Excel2007(.xlsx)文件
    rocketMq消息的发送和消息消费
    Java 七牛云存储与下载
    Spring boot + Jpa + Maven + Mysql 初级整合
    Spring+SpringMvc+Hibernate整合记录
    Mybatis-Generator自动生成代码
    idea spring+springmvc+mybatis环境配置整合详解
    Linux下安装redis
    SpringMvc的基础配置<一>
    JAVA从本机获取IP地址
  • 原文地址:https://www.cnblogs.com/hustdc/p/9572090.html
Copyright © 2020-2023  润新知