Skip to content

Commit c38daf9

Browse files
DOCS-13668: Expose statistics which indicate how many collection scans have executed
1 parent 8dc7435 commit c38daf9

File tree

3 files changed

+101
-7
lines changed

3 files changed

+101
-7
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The ``collectionScans`` field contains an embedded document bearing the
2+
following fields:
3+
4+
.. list-table::
5+
:header-rows: 1
6+
:widths: 30 70
7+
8+
* - Field Name
9+
- Description
10+
11+
* - ``total``
12+
- A 64-bit integer giving the total number of queries that
13+
performed a collection scan. The total consists of queries that
14+
did and did not use a :doc:`tailable cursor
15+
</core/tailable-cursors>`.
16+
17+
* - ``nonTailable``
18+
- A 64-bit integer giving the number of queries that performed a
19+
collection scan that did not use a :doc:`tailable cursor
20+
</core/tailable-cursors>`.

source/reference/command/serverStatus.txt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3915,7 +3915,11 @@ metrics
39153915
},
39163916
"queryExecutor": {
39173917
"scanned" : NumberLong(<num>),
3918-
"scannedObjects" : NumberLong(<num>)
3918+
"scannedObjects" : NumberLong(<num>),
3919+
"collectionScans" : {
3920+
"nonTailable" : NumbeLong(<num>),
3921+
"total" : NumberLong(<num>)
3922+
}
39193923
},
39203924
"record" : {
39213925
"moves" : NumberLong(<num>)
@@ -4153,6 +4157,28 @@ metrics
41534157
:data:`~explain.executionStats.totalDocsExamined` in the output of
41544158
:method:`~cursor.explain()`.
41554159

4160+
.. serverstatus:: metrics.queryExecutor.collectionScans
4161+
4162+
A document that reports on the number of queries that performed a
4163+
collection scan.
4164+
4165+
.. versionadded:: 4.4
4166+
4167+
.. serverstatus:: metrics.queryExecutor.collectionScans.nonTailable
4168+
4169+
The number of queries that performed a collection scan that did not
4170+
use a :doc:`tailable cursor </core/tailable-cursors>`.
4171+
4172+
.. versionadded:: 4.4
4173+
4174+
.. serverstatus:: metrics.queryExecutor.collectionScans.total
4175+
4176+
The total number queries that performed a collection scan. The total
4177+
consists of queries that did and did not use a :doc:`tailable cursor
4178+
</core/tailable-cursors>`.
4179+
4180+
.. versionadded:: 4.4
4181+
41564182
.. serverstatus:: metrics.record
41574183

41584184
A document that reports on data related to record allocation in the

source/reference/operator/aggregation/collStats.txt

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Definition
2828
{
2929
latencyStats: { histograms: <boolean> },
3030
storageStats: { scale: <number> },
31-
count: {}
31+
count: {},
32+
queryExecStats: {}
3233
}
3334
}
3435

@@ -90,6 +91,12 @@ Definition
9091

9192
.. versionadded:: 3.6
9293

94+
* - ``queryExecStats``
95+
- Adds :ref:`query execution statistics
96+
<collstat-queryexecstats>` to the return document.
97+
98+
.. versionadded:: 4.4
99+
93100
For a collection in a replica set or a
94101
:ref:`non-sharded collection<sharded-vs-non-sharded-collections>` in
95102
a cluster, ``$collStats`` outputs a single document. For a
@@ -127,16 +134,16 @@ Definition
127134
milliseconds since the :term:`Unix epoch`.
128135

129136
* - ``latencyStats``
130-
- A collection of statistics related to request latency for a
131-
collection or :doc:`view </core/views>`. See
132-
:ref:`latency-stats-document` for details on this document.
137+
- Statistics related to request latency for a collection or
138+
:doc:`view </core/views>`. See :ref:`latency-stats-document`
139+
for details on this document.
133140

134141
Only present when the ``latencyStats: {}`` option is specified.
135142

136143
* - ``storageStats``
137144

138-
- A collection of statistics related to a collection's storage
139-
engine. See :ref:`storage-stats-document` for details on this
145+
- Statistics related to a collection's storage engine. See
146+
:ref:`storage-stats-document` for details on this
140147
document.
141148

142149
The various size data is scaled by the specified factor (with
@@ -160,6 +167,13 @@ Definition
160167
Only present when the ``count: {}`` option is specified. Returns
161168
an error if applied to a :doc:`view </core/views>`.
162169

170+
* - ``queryExecStats``
171+
- Statistics related to query execution for the collection.
172+
173+
Only present when the ``queryExecStats: {}`` option is
174+
specified. Returns an error if applied to a :doc:`view
175+
</core/views>`.
176+
163177
Behavior
164178
--------
165179

@@ -339,6 +353,40 @@ The total number of documents in the collection is also available as
339353
``storageStats.count`` when ``storageStats: {}`` is specified. For more
340354
information, see :ref:`storage-stats-document`.
341355

356+
.. _collstat-queryexecstats:
357+
358+
``queryExecStats`` Document
359+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
360+
361+
.. versionadded:: 4.4
362+
363+
The ``queryExecStats`` embedded document only exists in the output if
364+
you specify the ``queryExecStats`` option.
365+
366+
.. include:: /includes/fact-queryexecstats-reference.rst
367+
368+
For example, if you run ``$collStats`` with the ``queryExecStats: {}``
369+
option on a ``matrices`` collection:
370+
371+
.. code-block:: javascript
372+
373+
db.matrices.aggregate( [ { $collStats: { queryExecStats: { } } } ] )
374+
375+
The query returns a result similar to the following:
376+
377+
.. code-block:: javascript
378+
379+
{
380+
"ns": "test.matrices",
381+
"host": "mongo.example.net:27017",
382+
"localTime": ISODate("2020-06-03T14:23:29.711Z"),
383+
"queryExecStats": {
384+
"collectionScans": {
385+
"total": NumberLong(33),
386+
"nonTailable": NumberLong(31)
387+
}
388+
}
389+
}
342390

343391
``$collStats`` on Sharded Collections
344392
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)