@@ -670,6 +670,44 @@ addition to the numbers corresponding to the BSON types.
670670:method:`db.collection.distinct()` method. For more information, see
671671:method:`db.collection.explain()`.
672672
673+ ``keysExamined`` Statistic Corrected
674+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
675+
676+ The :method:`explain()` method's output in ``executionStats`` or
677+ ``allPlansExecution`` mode contains the ``keysExamined`` statistic
678+ (``nScanned`` in MongoDB 2.4 and 2.6), representing the number of
679+ index keys examined during index scans. It is also reported in the
680+ logs and the system profiler.
681+
682+ For the ``IXSCAN`` query execution stage, ``keysExamined`` is the total number
683+ of in-range and out-of-range keys that are examined in the process of the
684+ index scan. If the index scan consists of a single contiguous range of keys,
685+ generally only in-range keys need to be examined. If the index bounds
686+ translate to several key ranges, the index scan execution process may examine
687+ out-of-range keys in order to skip from the end of one range to the beginning
688+ of the next.
689+
690+ For example, given a collection with an index on field ``x`` with 100 unique
691+ values between 1 and 100, the following performs a find operation with the
692+ :method:`explain()` method in ``executionStats`` mode:
693+
694+ .. code-block:: javascript
695+
696+ db.keys.find( { x : $in : [ 3, 4, 50, 74, 75, 90 ] } ).explain( "executionStats" )
697+
698+ The query will scan keys ``3`` and ``4``. It will then scan the key ``5``,
699+ detect that it is out of range, and skip to the next key ``50``.
700+
701+ The query scans keys 3, 4, 5, 50, 51, 74, 75, 76, 90, and 91. Keys
702+ ``5``, ``51``, ``76``, and ``91`` are out-of-range keys that are still
703+ examined.
704+
705+ Prior to 3.2, the last out-of-range key ``91`` was not counted due to an
706+ accounting error. ``keysExamined`` returned ``9``.
707+
708+ As of 3.2, that last out-of-range key is included in the ``keysExamined``
709+ value. ``keysExamined`` now returns ``10``.
710+
673711.. _3.2-relnotes-2dsphere-index:
674712
675713Geospatial Optimization
0 commit comments