Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source/indexes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ page </reference/collation/>`.

.. include:: /includes/extracts/collation-index-type-restrictions.rst

.. _indexes-covered-queries:

Covered Queries
---------------

Expand Down
69 changes: 69 additions & 0 deletions source/reference/explain-results.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _explain-results:

===============
Explain Results
===============
Expand Down Expand Up @@ -605,6 +607,73 @@ execution of the winning plan. In order to include
both the winning and rejected plans. The field is present only if
``explain`` runs in ``allPlansExecution`` verbosity mode.

.. _explain-results-lookup:

Execution Plan Statistics for Query with ``$lookup`` Pipeline Stage
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 5.0

The :ref:`explain results <explain-results>` can include execution
statistics for queries that use a :pipeline:`$lookup` pipeline stage. To
include those execution statistics, you must run the explain operation
in one of these execution verbosity modes:

- :ref:`executionStats <explain-method-executionStats>`
- :ref:`allPlansExecution <explain-method-allPlansExecution>`

The following fields are included in the explain results for a
:pipeline:`$lookup` query:

.. code-block:: none
:copyable: false

'$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 :pipeline:`$lookup` page.

The other fields are:

.. data:: explain.totalDocsExamined

Number of documents examined during the query execution.

.. data:: explain.totalKeysExamined

Number of index keys examined.

.. data:: 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
:ref:`index <indexes>` exists that :ref:`covers
<indexes-covered-queries>` the query.

.. data:: explain.indexesUsed

Array of strings with the names of the indexes used by the query.

.. data:: explain.nReturned

Number of documents that match the query condition.

.. data:: explain.executionTimeMillisEstimate

Estimated time in milliseconds for the query execution.

.. _serverInfo:

``serverInfo``
Expand Down
7 changes: 7 additions & 0 deletions source/release-notes/5.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,13 @@ Transactions
General Improvements
--------------------

Execution Plan Statistics for Query with ``$lookup`` Pipeline Stage
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MongoDB 5.0 adds :ref:`execution plan statistics
<explain-results-lookup>` for queries that use a :pipeline:`$lookup`
pipeline stage.

Improved Handling of (``$``) and (``.``) in Field Names
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down