MongoDB view an execution plan
explain MongoDB in the () function can help us see the relevant information, which helps us to quickly find the search bottleneck and then solve it, we'll take a look at this article explain () usage and meaning of some of the query results.
This article is the eighth in the series of articles MongoDB, understand the previous article contribute to a better understanding of the article:
Overall, explain () usage and sort (), limit () uses about the same, except that explain () must be placed last.
Basic Usage
First look at a basic usage:
1 |
db.sang_collect.find({x:1}).explain() |
Directly with the find () after the function, that the implementation plan view the find () function, the results are as follows:
1 |
{ |
Return result contains two blocks of information, one is queryPlanner, namely query plan, there is a serverInfo, some of the information that is MongoDB service. This parameter involved more, we look one by one:
parameter | meaning | ||
---|---|---|---|
plannerVersion | Query Plan Version | ||
namespace | Collection to be queried | ||
indexFilterSet | Whether to use index | ||
parsedQuery | Query, here x = 1 | ||
winningPlan | Best execution plan | ||
stage | Query, a common ** COLLSCAN / full table scan, IXSCAN / index scan, FETCH / according to the index to retrieve documents, SHARD_MERGE / merge fragmented results, IDHACK / for
|
In addition to the above, here we are introduced to some of the parameters, but also more executionStats parameters, the following meanings:
parameter | meaning |
---|---|
executionSuccess | Whether success |
nReturned | The number of returned results |
executionTimeMillis | Time-consuming |
totalKeysExamined | An index number of scans |
totalDocsExamined | Document scanning frequency |
executionStages | Describe the state of the implementation of this classified |
stage | Scanning the same manner, and specific optional value above |
nReturned | The number of query results |
executionTimeMillisEstimate | Estimated time consuming |
works | The number of units of work, a query into smaller units of work |
advanced | Priority number of results returned |
docsExamined | The number of documents checked, totalDocsExamined consistent with |
allPlansExecution
allPlansExecution used to get all execution plans, the results of the basic parameters the same as above, will not elaborate here.
Well, explain MongoDB in () Here we are, small partners have discussed questions please leave a message.
References:
- "MongoDB Definitive Guide 2nd Edition"
- MongoDB implementation plan acquisition (db.collection.explain ())
- mongodb .explain ( 'executionStats') query performance analysis (could not find the original source)