Explain Results解释结果
On this page本页内容
Explain Output Structure解释输出结构Explain Output for MongoDB 5.1 and Later解释MongoDB 5.1及更高版本的输出queryPlanner
executionStats
serverInfo
Execution Plan Statistics for Query with$lookup
Pipeline Stage$lookup
管道阶段查询的执行计划统计信息Collection Scan集合扫描Covered Queries涵盖的查询$or
Expression表示$sort
and$group
Stages$sort
和$group
阶段Sort Stage排序阶段
To return information on query plans and execution statistics of the query plans, MongoDB provides:为了返回查询计划的信息和查询计划的执行统计信息,MongoDB提供:
thedb.collection.explain()
method,db.collection.explain()
方法,thecursor.explain()
method, andcursor.explain()
方法,以及theexplain
command.explain
命令。
Only the most important output fields are shown on this page.此页面上只显示最重要的输出字段。The output is subject to change.输出可能会发生变化。Some fields are for internal use and are not documented.有些字段仅供内部使用,没有文档记录。
Explain Output Structure解释输出结构
The explain
results present the query plans as a tree of stages. explain
结果将查询计划表示为阶段树。The output structure can differ based on which query engine the operation uses. 输出结构可能因操作使用的查询引擎而异。Operations can use the classic query engine or the slot-based execution query engine.操作可以使用经典查询引擎或基于槽的执行查询引擎。
To see how the output structure can differ between the two execution engines, see the following examples:要了解两个执行引擎之间的输出结构有何不同,请参阅以下示例:
winningPlan: {
stage: <STAGE1>,
...
inputStage: {
stage: <STAGE2>,
...
inputStage: {
stage: <STAGE3>,
...
}
}
},
winningPlan: {
queryPlan: {
stage: <STAGE1>,
...
inputStage: {
stage: <STAGE2>,
...
inputStage: {
stage: <STAGE3>,
...
}
}
}
slotBasedPlan: {
...
}
},
Each stage passes its resulting documents or index keys to the parent node. 每个阶段都将其生成的文档或索引键传递给父节点。The leaf nodes access the collection or the indices. The internal nodes use the documents or the index keys that result from the child nodes. 叶节点访问集合或索引。内部节点使用子节点产生的文档或索引键。The root node indicates the stage that MongoDB ultimately derives the result set from.根节点表示MongoDB最终从中派生结果集的阶段。
Stages are descriptive of the operation. 阶段是对操作的描述。For example:例如:
COLLSCAN
for a collection scan用于集合扫描IXSCAN
for scanning index keys用于扫描索引键FETCH
for retrieving documents用于检索文档GROUP
for grouping documents用于分组文档SHARD_MERGE
for merging results from shards用于从分片合并结果SHARDING_FILTER
for filtering out orphan documents from shards用于从分片中筛选孤立文档BATCHED_DELETE
for multiple document deletions that are batched together internally (starting in MongoDB 6.1)用于内部批处理在一起的多个文档删除(从MongoDB 6.1开始)
Explain Output for MongoDB 5.1 and Later解释MongoDB 5.1及更高版本的输出
This section shows the 本节显示MongoDB 5.1及更高版本的explain
output for MongoDB 5.1 and later. To see the explain output for older versions of MongoDB, refer to the documentation for that version.explain
输出。要查看旧版本MongoDB的解释输出,请参阅该版本的文档。
explain.explainVersion
-
Integer field with the explain planner version.具有解释计划器版本的整数字段。explainVersion
is:是:1 when classic query execution is used.当使用经典查询执行时为1。2 when slot based query execution is used.2。
New in version 5.1.5.1版新增。
queryPlanner
explain.queryPlanner
information details the plan selected by the query optimizer.信息详细说明了查询优化器所选择的计划。
These examples may combine the output structures of MongoDB's classic and slot-based execution engines. 这些示例可以结合MongoDB的经典执行引擎和基于插槽的执行引擎的输出结构。They are not meant to be representative. Your output may differ significantly.它们并不具有代表性。您的输出可能存在显著差异。
For unsharded collections, 对于未分片的集合,explain
returns the following queryPlanner
information:explain
返回以下queryPlanner
信息:
queryPlanner: {
namespace: <string>,
indexFilterSet: <boolean>,
parsedQuery: {
...
},
queryHash: <hexadecimal string>,
planCacheKey: <hexadecimal string>,
maxIndexedOrSolutionsReached: <boolean>,
maxIndexedAndSolutionsReached: <boolean>,
maxScansToExplodeReached: <boolean>,
winningPlan: {
stage: <STAGE1>,
inputStage: {
stage: <string>,
...
}
},
rejectedPlans: [
<candidate plan1>,
]
}
For sharded collections, 对于分片集合,explain
includes the core query planner and server information for each accessed shard in the shards
field:explain
在shards
字段中包括每个访问的分片的核心查询计划器和服务器信息:
{
queryPlanner: {
mongosPlannerVersion: <int>
winningPlan: {
stage: <STAGE1>,
shards: [
{
shardName: <string>,
connectionString: <string>,
serverInfo: {
...
},
namespace: <string>,
indexFilterSet: <boolean>,
parsedQuery: {
...
},
queryHash: <hexadecimal string>,
planCacheKey: <hexadecimal string>,
maxIndexedOrSolutionsReached: <boolean>,
maxIndexedAndSolutionsReached: <boolean>,
maxScansToExplodeReached: <boolean>,
winningPlan: {
stage: <STAGE1>,
inputStage: {
stage: <string>,
...
}
},
rejectedPlans: [
<candidate plan1>,
]
}
]
}
}
}
explain.queryPlanner
-
Contains information on the selection of the query plan by the query optimizer.包含有关查询优化器选择查询计划的信息。explain.queryPlanner.namespace
-
A string that specifies the namespace with the names of the database and the collection accessed by the query.一个字符串,用于指定带有数据库名称和查询访问的集合名称的命名空间。The namespace has the format命令空间的格式为<database>.<collection>
.<database>.<collection>
。
explain.queryPlanner.indexFilterSet
-
A boolean that specifies whether MongoDB applied an index filter for the query shape.一个布尔值,指定MongoDB是否为查询形状应用了索引筛选器。
explain.queryPlanner.queryHash
-
A hexadecimal string that represents the hash of the query shape and is dependent only on the query shapes.十六进制字符串,表示查询形状的哈希,并且仅依赖于查询形状。queryHash
can help identify slow queries (including the query filter of write operations) with the same query shape.可以帮助识别具有相同查询形状的慢速查询(包括写入操作的查询筛选器)。NoteAs with any hash function, two different query shapes may result in the same hash value. However, the occurrence of hash collisions between different query shapes is unlikely.与任何哈希函数一样,两种不同的查询形状可能会产生相同的哈希值。但是,不同查询形状之间不太可能发生哈希冲突。For more information on有关queryHash
andplanCacheKey
, seequeryHash
andplanCacheKey
.queryHash
和planCacheKey
的更多信息,请参阅queryHash
与planCacheKey
。
explain.queryPlanner.planCacheKey
-
A hash of the key for the plan cache entry associated with the query.与查询关联的计划缓存项的键的哈希。Unlike the与explain.queryPlanner.queryHash
, theexplain.queryPlanner.planCacheKey
is a function of both the query shape and the currently available indexes for that shape.explain.queryPlanner.queryHash
不同,explain.queryPlanner.planCacheKey
是查询形状和该形状当前可用索引的函数。That is, if indexes that can support the query shape are added/dropped, the也就是说,如果添加/删除了可以支持查询形状的索引,planCacheKey
value may change whereas thequeryHash
value would not change.planCacheKey
值可能会更改,而queryHash
值不会更改。For more information on有关queryHash
andplanCacheKey
, seequeryHash
andplanCacheKey
.queryHash
和planCacheKey
的更多信息,请参阅queryHash
与planCacheKey
。
explain.queryPlanner.optimizedPipeline
-
A boolean that indicates that the entire aggregation pipeline operation was optimized away, and instead, fulfilled by a tree of query plan execution stages.一个布尔值,表示整个聚合管道操作已被优化,而是由查询计划执行阶段的树来完成。For example, starting in MongodB 4.2, the following aggregation operation can be fulfilled by the tree of query plan execution rather than using the aggregation pipeline.例如,从MongodB 4.2开始,以下聚合操作可以通过查询计划执行树来完成,而不是使用聚合管道。db.example.aggregate([ { $match: { someFlag: true } } ] )
The field is only present if the value is只有当值为true
and only applies to explain on aggregation pipeline operations.true
时,该字段才存在,并且仅适用于解释聚合管道操作。When如果为true
, because the pipeline was optimized away, no aggregation stage information appears in the output.true
,则由于管道已被优化,因此输出中不会显示聚合阶段信息。
explain.queryPlanner.winningPlan
-
A document that details the plan selected by the query optimizer.详细说明查询优化器所选计划的文档。
explain.queryPlanner.winningPlan.stage
-
A string that denotes the name of the stage.表示阶段名称的字符串。Each stage consists of information specific to the stage. For example, an每个阶段都包含特定于该阶段的信息。例如,IXSCAN
stage includes the index bounds along with other data specific to the index scan.IXSCAN
阶段包括索引边界以及特定于索引扫描的其他数据。If a stage has a child stage or multiple child stages, the stage will have an如果一个阶段有一个子阶段或多个子阶段,则该阶段将有一个inputStage
orinputStages
.inputStage
或inputStages
。This field appears if the operation used the classic query execution engine.如果操作使用了经典查询执行引擎,则会显示此字段。
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.描述子阶段的文档,该文档为其父阶段提供文档或索引键。如果父阶段只有一个子阶段,则该字段存在。
explain.queryPlanner.winningPlan.inputStages
-
An array of documents describing the child stages.描述子阶段的一组文档。Child stages provide the documents or index keys to the parent stage.子阶段为父阶段提供文档或索引键。The field is present if the parent stage has multiple child nodes.如果父阶段具有多个子节点,则会出现该字段。For example, stages for $or expressions might consume input from multiple sources.例如,$or
表达式的阶段可能会使用来自多个源的输入。This field appears if the operation used the classic query execution engine.如果操作使用了经典查询执行引擎,则会显示此字段。
explain.queryPlanner.winningPlan.queryPlan
-
A document that details the plan selected by the query optimizer. MongoDB presents the plan as a tree of stages.详细说明查询优化器所选计划的文档。MongoDB将计划呈现为一个阶段树。This document appears if the query used the slot-based execution query engine.如果查询使用基于槽的执行查询引擎,则会显示此文档。New in version 5.1.5.1版新增。explain.queryPlanner.winningPlan.queryPlan.stage
-
A string that denotes the name of the stage.表示阶段名称的字符串。Each stage consists of information specific to the stage. For example, an每个阶段都包含特定于该阶段的信息。例如,IXSCAN
stage includes the index bounds along with other data specific to the index scan.IXSCAN
阶段包括索引边界以及特定于索引扫描的其他数据。
explain.queryPlanner.winningPlan.queryPlan.planNodeId
-
Unique integer field that identifies each stage in the execution plan. Field is included in all stages throughout the标识执行计划中每个阶段的唯一整数字段。字段包含在整个explain
results.explain
结果的所有阶段中。New in version 5.1.5.1版新增。
explain.queryPlanner.winningPlan.queryPlan.inputStage
-
See请参阅explain.queryPlanner.winningPlan.inputStage
.explain.queryPlanner.winningPlan.inputStage
。
explain.queryPlanner.rejectedPlans
-
Array of candidate plans considered and rejected by the query optimizer.查询优化器考虑和拒绝的候选计划的数组。The array can be empty if there were no other candidate plans.如果没有其他候选计划,则数组可以为空。
executionStats
The returned 返回的explain.executionStats
information details the execution of the winning plan. explain.executionStats
信息详细说明了获胜计划的执行情况。In order to include 为了在结果中包括executionStats
in the results, you must run the explain in either:executionStats
,您必须在中运行解释:
executionStats
or或allPlansExecution
verbosity mode.冗长模式。Use使用allPlansExecution
mode to include partial execution data captured during plan selection.allPlansExecution
模式可以包括在计划选择期间捕获的部分执行数据。
These examples may combine the output structures of MongoDB's classic and slot-based execution engines. They are not meant to be representative. Your output may differ significantly.这些示例可以结合MongoDB的经典执行引擎和基于插槽的执行引擎的输出结构。它们并不具有代表性。您的输出可能存在显著差异。
For unsharded collections, 对于未分片的集合,explain
returns the following executionStats
information:explain
返回以下executionStats
信息:
executionStats: {
executionSuccess: <boolean>,
nReturned: <int>,
executionTimeMillis: <int>,
totalKeysExamined: <int>,
totalDocsExamined: <int>,
executionStages: {
stage: <STAGE1>
nReturned: <int>,
executionTimeMillisEstimate: <int>,
opens: <int>, // Starting in MongoDB 5.1
closes: <int>, // Starting in MongoDB 5.1
works: <int>,
advanced: <int>,
needTime: <int>,
needYield: <int>,
saveState: <int>,
restoreState: <int>,
isEOF: <boolean>,
...
inputStage: {
stage: <STAGE2>,
nReturned: <int>,
...
numReads: <int>, // Starting in MongoDB 5.1
...
executionTimeMillisEstimate: <int>,
...
inputStage: {
...
}
}
},
allPlansExecution: [
{
nReturned: <int>,
executionTimeMillisEstimate: <int>,
totalKeysExamined: <int>,
totalDocsExamined:<int>,
executionStages: {
stage: <STAGEA>,
nReturned: <int>,
executionTimeMillisEstimate: <int>,
...
inputStage: {
stage: <STAGEB>,
...
inputStage: {
...
}
}
}
},
...
]
}
For sharded collections, 对于分片集合,explain
includes the execution statistics for each accessed shard.explain
包括每个访问的分片的执行统计信息。
executionStats: {
nReturned: <int>,
executionTimeMillis: <int>,
totalKeysExamined: <int>,
totalDocsExamined: <int>,
executionStages: {
stage: <STAGE1>
nReturned: <int>,
executionTimeMillis: <int>,
opens: <int>, // Starting in MongoDB 5.1
closes: <int>, // Starting in MongoDB 5.1
totalKeysExamined: <int>,
totalDocsExamined: <int>,
totalChildMillis: <NumberLong>,
shards: [
{
shardName: <string>,
executionSuccess: <boolean>,
executionStages: {
stage: <STAGE2>,
nReturned: <int>,
executionTimeMillisEstimate: <int>,
...
chunkSkips: <int>,
inputStage: {
stage: <STAGE3>,
...
numReads: <int>, // Starting in MongoDB 5.1
...
inputStage: {
...
}
}
}
},
...
]
}
allPlansExecution: [
{
shardName: <string>,
allPlans: [
{
nReturned: <int>,
executionTimeMillisEstimate: <int>,
totalKeysExamined: <int>,
totalDocsExamined:<int>,
executionStages: {
stage: <STAGEA>,
nReturned: <int>,
executionTimeMillisEstimate: <int>,
...
inputStage: {
stage: <STAGEB>,
...
inputStage: {
...
}
}
}
},
...
]
},
{
shardName: <string>,
allPlans: [
...
]
},
...
]
}
explain.executionStats
-
Contains statistics that describe the completed query execution for the winning plan.包含描述获胜计划的已完成查询执行情况的统计信息。For write operations, completed query execution refers to the modifications that would be performed, but does not apply the modifications to the database.对于写操作,已完成的查询执行指的是将要执行的修改,但不将这些修改应用于数据库。explain.executionStats.nReturned
-
Number of documents that match the query condition.符合查询条件的文档数。nReturned
corresponds to the对应于早期版本的MongoDB中n
field returned bycursor.explain()
in earlier versions of MongoDB.cursor.explain()
返回的n
字段。
explain.executionStats.executionTimeMillis
-
Total time in milliseconds required for query plan selection and query execution.选择查询计划和执行查询所需的总时间(以毫秒为单位)。explain.executionStats.executionTimeMillis
corresponds to the对应于早期版本的MongoDB中millis
field returned bycursor.explain()
in earlier versions of MongoDB.cursor.explain()
返回的millis
字段。
explain.executionStats.totalKeysExamined
-
Number of index entries scanned.扫描的索引条目数。explain.executionStats.totalKeysExamined
corresponds to the对应于早期版本的MongoDB中nscanned
field returned bycursor.explain()
in earlier versions of MongoDB.cursor.explain()
返回的nscanned
字段。
explain.executionStats.totalDocsExamined
-
Number of documents examined during query execution.查询执行期间检查的文档数。Common query execution stages that examine documents are检查文档的常见查询执行阶段是COLLSCAN
andFETCH
.COLLSCAN
和FETCH
。Noteexplain.executionStats.totalDocsExamined
refers to the total number of documents examined and not to the number of documents returned.是指检查的文件总数,而不是返回的文件数量。For example, a stage can examine a document in order to apply a filter. If the document is filtered out, then it has been examined but will not be returned as part of the query result set.例如,阶段可以检查文档以应用筛选器。如果文档被筛选掉,则它已被检查,但不会作为查询结果集的一部分返回。If a document is examined multiple times during query execution,如果在查询执行过程中多次检查文档,explain.executionStats.totalDocsExamined
counts each examination.explain.executionStats.totalDocsExamined
会对每次检查进行计数。That is,也就是说,explain.executionStats.totalDocsExamined
is not a count of the total number of unique documents examined.explain.executionStats.totalDocsExamined
不是检查的唯一文档总数的计数。
explain.executionStats.executionStages
-
Details the completed execution of the winning plan as a tree of stages; i.e. a stage can have an以阶段树的形式详细说明已完成的获胜计划执行情况;即一个阶段可以有一个inputStage
or multipleinputStages
.inputStage
或多个inputStages
。Starting in MongoDB 5.1, a stage can have these input stages:从MongoDB 5.1开始,一个阶段可以有以下输入阶段:thenStage
elseStage
innerStage
outerStage
Each stage consists of execution information specific to the stage.每个阶段都包含特定于该阶段的执行信息。explain.executionStats.executionStages.executionTimeMillisEstimate
-
The estimated amount of time in milliseconds for query execution.查询执行的估计时间量(以毫秒为单位)。
explain.executionStats.executionStages.opens
-
Starting in MongoDB 5.1, the number of times a stage was opened during query execution.从MongoDB 5.1开始,阶段在查询执行过程中打开的次数。
explain.executionStats.executionStages.closes
-
Starting in MongoDB 5.1, the number of times a stage was closed during query execution.从MongoDB 5.1开始,阶段在查询执行期间关闭的次数。
explain.executionStats.executionStages.works
-
Specifies the number of "work units" performed by the query execution stage.指定查询执行阶段执行的“工作单位”数。Query execution divides its work into small units. A "work unit" might consist of examining a single index key, fetching a single document from the collection, applying a projection to a single document, or doing a piece of internal bookkeeping.查询执行将其工作划分为几个小单元。“工作单元”可能包括检查单个索引键、从集合中获取单个文档、对单个文档应用投影或进行内部记账。This field appears if the operation used the classic query execution engine.如果操作使用了经典查询执行引擎,则会显示此字段。
explain.executionStats.executionStages.saveState
-
The number of times that the query stage suspended processing and saved its current execution state, for example in preparation for yielding its locks.查询阶段挂起处理并保存其当前执行状态的次数,例如为生成其锁做准备的次数。
explain.executionStats.executionStages.restoreState
-
The number of times that the query stage restored a saved execution state, for example after recovering locks that it had previously yielded.查询阶段恢复已保存的执行状态的次数,例如在恢复以前产生的锁之后。
explain.executionStats.executionStages.isEOF
-
Specifies whether the execution stage has reached end of stream:指定执行阶段是否已到达流的末尾:If如果为true
or1
, the execution stage has reached end-of-stream.true
或1
,则执行阶段已到达流的末尾。If如果为false
or0
, the stage may still have results to return.false
或0
,则该阶段可能仍有结果要返回。For example, consider a query with a limit whose execution stages consists of a例如,考虑一个具有限制的查询,其执行阶段由一个LIMIT
stage with an input stage ofIXSCAN
for the query.LIMIT
阶段组成,该查询的输入阶段为IXSCAN
。If the query returns more than the specified limit, the如果查询返回的值超过指定的限制,LIMIT
stage will reportisEOF: 1
, but its underlyingIXSCAN
stage will reportisEOF: 0
.LIMIT
阶段将报告isEOF:1
,但其底层IXSCAN
阶段将报告isEOF:0
。
explain.executionStats.executionStages.inputStage
-
Each根据inputStage
can have different fields depending on the value ofinputStage.stage
. The following table describes possible fields and what stages they can appear in.inputStage.stage
的值,每个inputStage
可以有不同的字段。下表介绍了可能的字段以及它们可以出现在哪些阶段。Each每个inputStage
can have anotherinputStage
as a field.inputStage
可以有另一个inputStage
作为字段。See Explain Output Structure.请参阅解释输出结构。Field字段Description描述Applicable Stages适用阶段docsExamined
Specifies the number of documents scanned during the query execution stage.指定在查询执行阶段扫描的文档数。COLLSCAN
,FETCH
keysExamined
For query execution stages that scan an index对于扫描索引的查询执行阶段,keysExamined
is the total number of in-bounds and out-of-bounds keys that are examined in the process of the index scan.keysExamined
是在索引扫描过程中检查的入界键和出界键的总数。If the index scan consists of a single contiguous range of keys, only in-bounds keys need to be examined.如果索引扫描由单个连续范围的键组成,则只需要检查边界内的键。If the index bounds consists of several key ranges, the index scan execution process may examine out-of-bounds keys in order to skip from the end of one range to the beginning of the next.如果索引边界由多个键范围组成,则索引扫描执行过程可以检查越界键,以便从一个范围的末尾跳到下一个区域的开头。IXSCAN
numReads
The number of documents scanned or index keys examined during the query execution stage.在查询执行阶段扫描的文档数或检查的索引键数。
New in version 5.1.5.1版新增。COLLSCAN
,IXSCAN
seeks
The number of times that we had to seek the index cursor to a new position in order to complete the index scan.为了完成索引扫描,我们必须将索引游标搜索到新位置的次数。IXSCAN
spilledBytesApprox
The approximate number of in-memory bytes spilled to disk in the stage.阶段中溢出到磁盘的内存中字节的大致数量。
New in version 5.3.5.3版新增。GROUP
spilledRecords
The number of produced records spilled to disk in the stage.阶段中溢出到磁盘的已生成记录数。
New in version 5.3.5.3版新增。GROUP
usedDisk
Whether the stage wrote to disk.阶段是否写入磁盘。
New in version 5.3.5.3版新增。GROUP
explain.executionStats.allPlansExecution
-
Contains partial execution information captured during the plan selection phase for both the winning and rejected plans.包含在计划选择阶段为获胜计划和被拒绝计划捕获的部分执行信息。The field is present only if仅当explain
runs inallPlansExecution
verbosity mode.explain
在allPlansExecution
详细模式下运行时,该字段才存在。
serverInfo
For unsharded collections, 对于未排序的集合,explain
returns the following serverInfo
information for the MongoDB instance:explain
返回MongoDB实例的以下serverInfo
信息:
serverInfo: {
host: <string>,
port: <int>,
version: <string>,
gitVersion: <string>
}
For sharded collections, 对于分片集合,explain
returns the serverInfo
for each accessed shard, and a top-level serverInfo
object for the mongos
.explain
为每个访问的分片返回serverInfo
,并为mongos
返回顶级serverInfo
对象。
queryPlanner: {
...
winningPlan: {
stage: <STAGE1>,
shards: [
{
shardName: <string>,
connectionString: <string>,
serverInfo: {
host: <string>,
port: <int>,
version: <string>,
gitVersion: <string>
},
...
}
...
]
}
},
serverInfo: { // serverInfo for mongos
host: <string>,
port: <int>,
version: <string>,
gitVersion: <string>
}
...
Execution Plan Statistics for Query with $lookup
Pipeline Stage$lookup
管道阶段查询的执行计划统计信息
$lookup
Pipeline StageNew in version 5.0. 5.0版新增。
The explain results can include execution statistics for queries that use a 解释结果可以包括使用$lookup
pipeline stage. $lookup
管道阶段的查询的执行统计信息。To include those execution statistics, you must run the explain operation in one of these execution verbosity modes:要包含这些执行统计信息,必须以以下执行详细程度模式之一运行解释操作:
The following fields are included in the explain results for a $lookup
query:$lookup
查询的解释结果中包括以下字段:
'$lookup': {
from: <string>,
as: <string>,
localField: <string>,
foreignField: <string>
},
totalDocsExamined: <long>,
totalKeysExamined: <long>,
collectionScans: <long>,
indexesUsed: [ <string_1>, <string_2>, ..., <string_n> ],
nReturned: <long>,
executionTimeMillisEstimate: <long>
To see the descriptions for the fields in the 要查看$lookup
section, see the $lookup
page.$lookup
部分中字段的说明,请参阅$lookup
页面。
The other fields are:其他字段包括:
explain.collectionScans
-
Number of times a collection scan occurred during query execution.查询执行期间发生集合扫描的次数。During a collection scan, each document in a collection is compared to the query predicate.在集合扫描期间,将集合中的每个文档与查询谓词进行比较。Collection scans occur if no appropriate index exists that covers the query.如果不存在覆盖查询的适当索引,则会进行集合扫描。
explain.indexesUsed
-
Array of strings with the names of the indexes used by the query.字符串数组,其中包含查询所用索引的名称。
explain.executionTimeMillisEstimate
-
Estimated time in milliseconds for the query execution.查询执行的估计时间(以毫秒为单位)。
Collection Scan集合扫描
If the query planner selects a collection scan, the explain result includes a 如果查询计划器选择集合扫描,则解释结果将包括COLLSCAN
stage.COLLSCAN
阶段。
If the query planner selects an index, the explain result includes a 如果查询计划器选择了一个索引,那么解释结果将包括一个IXSCAN
stage. IXSCAN
阶段。The stage includes information such as the index key pattern, direction of traversal, and index bounds.该阶段包括诸如索引键模式、遍历方向和索引边界之类的信息。
Starting in MongoDB 5.3, if the query planner selects a clustered index for a clustered collection, the explain result includes a 从MongoDB 5.3开始,如果查询规划器为集群集合选择了一个集群索引,那么解释结果包括一个CLUSTERED_IXSCAN
stage. CLUSTERED_IXSCAN
阶段。The stage includes information about the clustered index key and index bounds.该阶段包括有关聚集索引键和索引边界的信息。
For more information on execution statistics of collection scans, see Analyze Query Performance.有关集合扫描的执行统计信息的详细信息,请参阅分析查询性能。
Covered Queries涵盖的查询
When an index covers a query, MongoDB can both match the query conditions and return the results using only the index keys; i.e. MongoDB does not need to examine documents from the collection to return the results.当索引覆盖查询时,MongoDB既可以匹配查询条件,也可以仅使用索引键返回结果;即MongoDB不需要检查集合中的文档就可以返回结果。
When an index covers a query, the explain result has an 当索引覆盖查询时,解释结果的IXSCAN
stage that is not a descendant of a FETCH
stage, and in the executionStats
, the explain.executionStats.totalDocsExamined
is 0
.IXSCAN
阶段不是FETCH
阶段的后代,并且在executionStats
中,explain.executionStats.totalDocsExamined
为0
。
$or
Expression表达式
If MongoDB uses indexes for an 如果MongoDB为$or
expression, the result will include the OR
stage with an explain.queryPlanner.winningPlan.inputStages
array that details the indexes; e.g.:$or
表达式使用索引,结果将包括OR
阶段,该阶段带有explain.queryPlanner.winningPlan.inputStages
数组,该数组详细说明了索引;例如:
{
stage: 'OR',
inputStages: [
{
stage: 'IXSCAN',
...
},
{
stage : 'IXSCAN',
...
},
...
]
}
In previous versions of MongoDB, 在MongoDB的早期版本中,cursor.explain()
returned the clauses
array that detailed the indexes.cursor.explain()
返回了详细说明索引的clauses
数组。
$sort
and $group
Stages$sort
阶段和$group
阶段
$sort
and $group
StagesWhen 当explain
is run in either executionStats or allPlansExecution verbosity mode, the $sort
and $group
stages have additional output.explain
在executionStats
或allPlansExecution
冗长模式下运行时,$sort
和$group
阶段会有额外的输出。
$sort | totalDataSizeSortedBytesEstimate | long | $sort stage.$sort 阶段中处理的估计字节数。 |
$sort | usedDisk | boolean | $sort stage wrote to disk.$sort 阶段是否写入磁盘。 |
$group | totalOutputDataSizeBytes | long | $group stage in bytes.$group 阶段输出的所有文档的总大小估计值(以字节为单位)。 |
$group | usedDisk | boolean | $group stage wrote to disk.$group 阶段是否写入磁盘。 |
$group | spillFileSizeBytes | long | $group stage. $group 阶段中写入磁盘的溢出文件的大小。spillFileSizeBytes should be less than or equal to numBytesSpilledEstimate .spillFileSizeBytes 的值应小于或等于numBytesSpilledEstimate 。 |
$group | numBytesSpilledEstimate | long | $group stage before compression.$group 阶段中写入磁盘的字节数的估计值。 |
Sort Stage排序阶段
If MongoDB cannot use an index or indexes to obtain the sort order, the results include a 如果MongoDB不能使用一个或多个索引来获得排序顺序,那么结果将包括一个SORT
stage indicating a blocking sort operation. SORT
阶段,指示阻塞排序操作。Blocking sorts do not block concurrent operations on the collection or database. 阻止排序不会阻止对集合或数据库的并发操作。The name refers to the requirement that the 该名称指的是SORT
stage reads all input documents before returning any output documents, blocking the flow of data for that specific query.SORT
阶段在返回任何输出文档之前读取所有输入文档的要求,从而阻止特定查询的数据流。
If MongoDB requires using more than 100 megabytes of system memory for the blocking sort operation, MongoDB returns an error unless the query specifies 如果MongoDB需要使用超过100兆字节的系统内存进行阻塞排序操作,则除非查询指定cursor.allowDiskUse()
(New in MongoDB 4.4). cursor.allowDiskUse()
,否则MongoDB将返回错误(MongoDB 4.4中的新增)。cursor.allowDiskUse()
allows MongoDB to use temporary files on disk to store data exceeding the 100 megabyte system memory limit while processing a blocking sort operation. 允许MongoDB在处理阻塞排序操作时使用磁盘上的临时文件来存储超过100兆字节系统内存限制的数据。If the explain plan does not contain an explicit 如果解释计划不包含显式SORT
stage, then MongoDB can use an index to obtain the sort order.SORT
阶段,那么MongoDB可以使用索引来获得排序顺序。