Skip to content

Commit 5fea6d1

Browse files
committed
DOCS-5392 : nscanned/keysExamined "end" check update
R2: CR + addtl. feedback R3: Further Refinement
1 parent 1a64ae9 commit 5fea6d1

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

source/reference/explain-results.txt

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,10 @@ information:
181181
"inputStage" : {
182182
"stage" : <STAGE2>,
183183
...
184-
"nReturned" : 0,
184+
"nReturned" : <int>,
185185
"executionTimeMillisEstimate" : <int>,
186+
"keysExamined" : <int>,
187+
"docsExamined" : <int>,
186188
...
187189
"inputStage" : {
188190
...
@@ -219,9 +221,9 @@ information:
219221
.. data:: explain.executionStats.totalKeysExamined
220222

221223
Number of index entries scanned.
222-
:data:`~explain.executionStats.totalKeysExamined` corresponds to the
223-
``nscanned`` field returned by ``cursor.explain()`` in earlier
224-
versions of MongoDB.
224+
:data:`~explain.executionStats.totalKeysExamined` corresponds to the
225+
``nscanned`` field returned by ``cursor.explain()`` in
226+
earlier versions of MongoDB.
225227

226228
.. data:: explain.executionStats.totalDocsExamined
227229

@@ -283,6 +285,42 @@ information:
283285
returns more than the specified limit, the ``LIMIT`` stage
284286
will report ``isEOF: 1``, but its underlying ``IXSCAN`` stage
285287
will report ``isEOF: 0``.
288+
289+
.. data:: explain.executionStats.executionStages.inputStage.keysExamined
290+
291+
For query execution stages that scan an index (e.g. IXSCAN),
292+
``keysExamined`` is the total number of in-bounds and out-of-bounds
293+
keys that are examined in the process of the index scan. If the
294+
index scan consists of a single contiguous range of keys, only
295+
in-bounds keys need to be examined. If the index bounds consists of
296+
several key ranges, the index scan execution process may examine
297+
out-of-bounds keys in order to skip from the end of one range to the
298+
beginning of the next.
299+
300+
Consider the following example, where there is an index of field
301+
``x`` and the collection contains 100 documents with ``x`` values
302+
1 through 100:
303+
304+
.. code-block:: javascript
305+
306+
db.keys.find( { x : $in : [ 3, 4, 50, 74, 75, 90 ] } ).explain( "executionStats" )
307+
308+
The query will scan keys ``3`` and ``4``. It will then scan the key
309+
``5``, detect that it is out-of-bounds, and skip to the next key
310+
``50``.
311+
312+
Continuing this process, the query scans keys
313+
3, 4, 5, 50, 51, 74, 75, 76, 90, and 91. Keys
314+
``5``, ``51``, ``76``, and ``91`` are out-of-bounds keys that are
315+
still examined. The value of ``keysExamined`` is 10.
316+
317+
.. data:: explain.executionStats.executionStages.inputStage.docsExamined
318+
319+
Specifies the number of documents scanned during the
320+
query execution stage.
321+
322+
Present for the ``COLLSCAN`` stage, as well as for stages that
323+
retrieve documents from the collection (e.g. ``FETCH``)
286324

287325
.. data:: explain.executionStats.allPlansExecution
288326

source/release-notes/3.2.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,22 @@ addition to the numbers corresponding to the BSON types.
747747
:method:`db.collection.distinct()` method. For more information, see
748748
:method:`db.collection.explain()`.
749749

750+
``keysExamined`` Statistic Corrected
751+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
752+
753+
The :method:`explain()` method's output in ``executionStats`` or
754+
``allPlansExecution`` mode contains the ``keysExamined`` statistic,
755+
representing the number of index keys examined during index scans.
756+
It is also reported in the diagnostic logs and the system profiler.
757+
758+
An accounting error prior to 3.2 resulted in the last scanned key not being
759+
included in the ``keysExamined`` count for some queries.
760+
As of 3.2 this error has been corrected.
761+
762+
See :data:`keysExamined
763+
<explain.executionStats.executionStages.inputStage.keysExamined>`
764+
for more information.
765+
750766
.. _3.2-relnotes-2dsphere-index:
751767

752768
Geospatial Optimization

0 commit comments

Comments
 (0)