On this page本页内容
queryPlanner
executionStats
$lookup
Pipeline Stage$lookup
管道阶段查询的执行计划统计信息serverInfo
$or
$sort
and $group
Stages$sort
阶段和$group
阶段To return information on query plans and execution statistics of the query plans, MongoDB provides:为了返回查询计划的信息和查询计划的执行统计信息,MongoDB提供:
db.collection.explain()
method,db.collection.explain()
方法,cursor.explain()
method, andcursor.explain()
方法,以及explain
command.explain
命令。This page shows the output for the explain results in different versions of MongoDB.此页面显示不同版本MongoDB中解释结果的输出。
The explain
results present the query plans as a tree of stages.explain
结果将查询计划呈现为一个阶段树。
"winningPlan" : { "stage" : <STAGE1>, ... "inputStage" : { "stage" : <STAGE2>, ... "inputStage" : { "stage" : <STAGE3>, ... } } },
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 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.根节点是MongoDB获得结果集的最后一个阶段。
Stages are descriptive of the operation. For example:阶段是对操作的描述。例如:
New in version 5.1.在版本5.1中新增。
This section shows the 本节显示MongoDB 5.1及更高版本的explain
output for MongoDB 5.1 and later.explain
输出。
winningPlan: { stage: <STAGE1>, ... inputStage: { stage: <STAGE2>, ... inputStage: { stage: <STAGE3>, ... } } },
winningPlan: { queryPlan: { stage: <STAGE1>, ... inputStage: { stage: <STAGE2>, ... inputStage: { stage: <STAGE3>, ... } } } slotBasedPlan: { ... } },
explain.explainVersion
Integer field with the explain planner version.解释计划器版本的整数字段。
explainVersion
is:
New in version 5.1.在版本5.1中新增。
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以阶段树的形式展示了该计划。
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 instance, an 例如,IXSCAN
stage will include the index bounds along with other data specific to the index scan.IXSCAN
阶段将包括索引边界以及特定于索引扫描的其他数据。
Starting in MongoDB 5.2, MongoDB can execute 从MongoDB 5.2开始,MongoDB可以使用基于插槽的执行查询引擎执行$group
stages using the slot-based execution query engine. $group
阶段。When the slot-based engine is used for 当基于插槽的引擎用于$group
, this field value is GROUP
.$group
时,此字段值为GROUP
。
This section shows the 本节显示MongoDB 4.4及更早版本的explain
output for MongoDB 4.4 and earlier.explain
输出。
This list presents some of the key fields returned by the 此列表显示explain
operation.explain
操作返回的一些关键字段。
queryPlanner
queryPlanner
information details the plan selected by the query optimizer.信息详细说明了查询优化器选择的计划。
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 (i.e., 一个字符串,指定对其运行查询的命名空间(即,<database>.<collection>
) against which the query is run.<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.可以帮助识别具有相同查询形状的慢速查询(包括写操作的查询筛选器)。
As 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
and planCacheKey
, see queryHash
and planCacheKey
.queryHash
和planCacheKey
的更多信息,请参阅queryHash
和planCacheKey
。
New in version 4.2.在版本4.2中新增。
explain.queryPlanner.planCacheKey
A hash of the key for the plan cache entry associated with the query.与查询关联的计划缓存项的密钥哈希。
Unlike the 与queryHash
, the planCacheKey
is a function of both the query shape and the currently available indexes for that shape. queryHash
不同,planCacheKey
是查询形状和该形状当前可用索引的函数。That is, if indexes that can support the query shape are added/dropped, the 也就是说,如果添加/删除支持查询形状的索引,planCacheKey
value may change whereas the queryHash
value would not change.planCacheKey
值可能会更改,而queryHash
值不会更改。
For more information on 有关queryHash
and planCacheKey
, see queryHash
and planCacheKey
.queryHash
和planCacheKey
的更多信息,请参阅queryHash
和planCacheKey
。
New in version 4.2.在版本4.2中新增。
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
,则由于管道已优化,因此输出中不会出现聚合阶段信息。
New in version 4.2.在版本4.2中新增。
explain.queryPlanner.winningPlan
A document that details the plan selected by the query optimizer. 详细说明查询优化器选择的计划的文档。MongoDB presents the plan as a tree of stages; i.e. a stage can have an MongoDB将该计划呈现为一棵阶段树;也就是说,一个阶段可以有一个inputStage
or, if the stage has multiple child stages, inputStages
.inputStage
,如果该阶段有多个子阶段,则可以有inputStages
。
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. IXSCAN
阶段将包括索引边界以及特定于索引扫描的其他数据。If a stage has a child stage or multiple child stages, the stage will have an inputStage or inputStages.如果一个阶段有一个子阶段或多个子阶段,该阶段将有一个或多个inputStage。
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 or index intersection consume input from multiple sources.例如,$or
表达式或索引交集的阶段使用来自多个源的输入。
executionStats
The returned 返回的executionStats
information details the execution of the winning plan. executionStats
信息详细说明了获胜计划的执行情况。In order to include 为了在结果中包含executionStats
in the results, you must run the explain in either:executionStats
,您必须在以下任一位置运行解释:
executionStats
allPlansExecution
allPlansExecution
mode to include partial execution data captured during plan selection.allPlansExecution
模式包括在计划选择期间捕获的部分执行数据。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 by cursor.explain()
in earlier versions of MongoDB.cursor.explain()
返回的n
字段。
explain.executionStats.executionTimeMillis
Total time in milliseconds required for query plan selection and query execution. 查询计划选择和查询执行所需的总时间(毫秒)。executionTimeMillis
corresponds to the 对应于早期版本MongoDB中millis
field returned by cursor.explain()
in earlier versions of MongoDB.cursor.explain()
返回的millis
(毫秒)字段。
explain.executionStats.totalKeysExamined
Number of index entries scanned. 扫描的索引项数。totalKeysExamined
corresponds to the 对应于早期版本MongoDB中nscanned
field returned by cursor.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
and FETCH
.COLLSCAN
和FETCH
。
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, 如果在查询执行期间多次检查文档,则totalDocsExamined
counts each examination. totalDocsExamined
会对每次检查进行计数。That is, 也就是说,totalDocsExamined
is not a count of the total number of unique documents examined.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 multiple inputStages
.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.“工作单元”可能包括检查单个索引键、从集合中提取单个文档、对单个文档应用投影,或者执行一项内部簿记。
Starting in MongoDB 5.1, this field is omitted.从MongoDB 5.1开始,省略此字段。
explain.executionStats.executionStages.nReturned
The number of intermediate results returned by this stage to its parent stage.此阶段返回给其父阶段的中间结果数。
Starting in MongoDB 5.1, this field is omitted.从MongoDB 5.1开始,省略此字段。
explain.executionStats.executionStages.needTime
The number of work cycles that did not advance an intermediate result to its parent stage (see 未将中间结果提前到其父阶段的工作周期数(请参阅解释explain.executionStats.executionStages.nReturned
). explain.executionStats.executionStages.nReturned
)。For instance, an index scan stage may spend a work cycle seeking to a new position in the index as opposed to returning an index key; this work cycle would count towards 例如,索引扫描阶段可以花费一个工作周期来寻找索引中的新位置,而不是返回索引键;此工作周期将计入explain.executionStats.executionStages.needTime
rather than explain.executionStats.executionStages.nReturned
.explain.executionStats.executionStages.needTime
,而不是explain.executionStats.executionStages.nReturned
。
Starting in MongoDB 5.1, this field is omitted.从MongoDB 5.1开始,省略此字段。
explain.executionStats.executionStages.needYield
The number of times that the storage layer requested that the query stage suspend processing and yield its locks.存储层请求查询阶段暂停处理并产生锁的次数。
Starting in MongoDB 5.1, this field is omitted.从MongoDB 5.1开始,省略此字段。
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:指定执行阶段是否已到达流的末尾:
true
or 1
, the execution stage has reached end-of-stream.true
或1
,则执行阶段已到达流的末尾。false
or 0
, the stage may still have results to return. false
或0
,该阶段可能仍有结果要返回。LIMIT
stage with an input stage of IXSCAN
for the query. LIMIT
阶段组成,该查询的输入阶段为IXSCAN
。LIMIT
stage will report isEOF: 1
, but its underlying IXSCAN
stage will report isEOF: 0
.LIMIT
阶段将报告isEOF:1
,但其基础IXSCAN
阶段将报告isEOF:0
。explain.executionStats.executionStages.inputStage.keysExamined
For query execution stages that scan an index (e.g. IXSCAN), 对于扫描索引的查询执行阶段(例如IXSCAN),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.如果索引边界由多个键范围组成,则索引扫描执行过程可能会检查越界键,以便从一个范围的末尾跳到下一个范围的开头。
Consider the following example, where there is an index of field 考虑以下示例,其中有一个字段x
and the collection contains 100 documents with x
values 1 through 100:x
的索引,集合包含100个x
值为1到100的文档:
db.keys.find( { x : { $in : [ 3, 4, 50, 74, 75, 90 ] } } ).explain( "executionStats" )
The query will scan keys 查询将扫描键3
and 4
. 3
和4
。It will then scan the key 然后,它将扫描键5
, detect that it is out-of-bounds, and skip to the next key 50
.5
,检测它是否超出范围,并跳到下一个键50
。
Continuing this process, the query scans keys 3, 4, 5, 50, 51, 74, 75, 76, 90, and 91. 继续这个过程,查询将扫描键3、4、5、50、51、74、75、76、90和91。Keys 键5
, 51
, 76
, and 91
are out-of-bounds keys that are still examined. 5
、51
、76
和91
是仍在检查的界外键。The value of 检查的键的值为keysExamined
is 10.10
。
explain.executionStats.executionStages.inputStage.docsExamined
Specifies the number of documents scanned during the query execution stage.指定在查询执行阶段扫描的文档数。
Present for the 用于COLLSCAN
stage, as well as for stages that retrieve documents from the collection (e.g. FETCH
)COLLSCAN
阶段,以及从集合中检索文档的阶段(例如FETCH
)
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 in allPlansExecution
verbosity mode.explain
在allPlansExecution
详细模式下运行时,该字段才会出现。
$lookup
Pipeline Stage$lookup
管道阶段查询的执行计划统计信息New 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:要包含这些执行统计信息,必须在以下执行详细度模式之一下运行explain操作:
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.如果不存在覆盖查询的适当索引,则会进行集合扫描。
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> } ...
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.该阶段包括索引键模式、遍历方向和索引边界等信息。
For more information on execution statistics of collection scans, see Analyze Query Performance.有关集合扫描的执行统计信息的更多信息,请参阅分析查询性能。
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 totalDocsExamined
is 0
.IXSCAN
阶段,它不是FETCH
阶段的后代,在executionStats
中,totalDocsExamined
为0
。
For an index intersection plan, the result will include either an 对于索引交叉点计划,结果将包括AND_SORTED
stage or an AND_HASH
stage with an inputStages
array that details the indexes; e.g.:AND_SORTED
AND_HASH阶段,以及详细说明索引的inputStages
数组;如。:
{ "stage" : "AND_SORTED", "inputStages" : [ { "stage" : "IXSCAN", ... }, { "stage" : "IXSCAN", ... } ] }
$or
If MongoDB uses indexes for an 如果MongoDB对$or
expression, the result will include the OR
stage with an inputStages
array that details the indexes; e.g.:$or
表达式使用索引,结果将包括OR
阶段,以及详细说明索引的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
阶段When 在explain
is run in either executionStats or allPlansExecution verbosity mode, the $sort
and $group
stages have additional output.executionStats
或allPlansExecution
详细模式下运行explain
时,$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 阶段是否写入磁盘。 |
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. 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 MB的系统内存来执行阻塞排序操作,MongoDB将返回一个错误,除非查询指定cursor.allowDiskUse()
(New in MongoDB 4.4). cursor.allowDiskUse()
(MongoDB 4.4中新增)。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 MB系统内存限制的数据。If the explain plan does not contain an explicit 如果解释计划不包含显式SORT
stage, then MongoDB can use an index to obtain the sort order.SORT
阶段,那么MongoDB可以使用索引来获取排序顺序。