Skip to content

Commit 1ef1818

Browse files
committed
DOCS-13943 Add plan cache limit and stats
1 parent cbb7e86 commit 1ef1818

File tree

2 files changed

+66
-16
lines changed

2 files changed

+66
-16
lines changed

source/core/query-plans.txt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,42 @@ Users can also:
141141

142142
.. seealso:: :ref:`query-hash-plan-cache-key`
143143

144+
Plan Cache Debug Info Size Limit
145+
--------------------------------
146+
147+
Starting in 4.2.12 (and 4.0.23 and 3.6.23), the
148+
:doc:`plan cache </core/query-plans>` will save full ``plan cache``
149+
entries only if the cumulative size of the ``plan caches`` for all
150+
collections is lower than 0.5 GB. When the cumulative size of the
151+
``plan caches`` for all collections exceeds this threshold, additional
152+
``plan cache`` entries are stored without the following debug
153+
information:
154+
155+
- :ref:`createdFromQuery <plancachestats-createdFromQuery>`
156+
- :ref:`cachedPlan <plancachestats-cachedPlan>`
157+
- :ref:`creationExecStats <plancachestats-creationExecStats>`
158+
- :ref:`candidatePlanScores <plancachestats-candidatePlanScores>`
159+
160+
When ``plan cache`` entries are stored with stripped debug information,
161+
the :dbcommand:`planCacheListQueryShapes` command output contains only
162+
``queryHash`` fields in the ``shapes`` array. Similarly, detailed
163+
execution statistics for the candidate plans are omitted from the
164+
:dbcommand:`planCacheListPlans` command output when ``plan cache``
165+
entries are stored with stripped debug information. When debug info is
166+
present, you can find these detailed statistics in the ``plans.reason``
167+
field.
168+
169+
The estimated size in bytes of a ``plan cache`` entry is available in
170+
the output of :pipeline:`$planCacheStats` and
171+
:dbcommand:`planCacheListPlans`.
172+
144173
.. _query-hash-plan-cache-key:
145174

146175
``queryHash`` and ``planCacheKey``
147176
----------------------------------
148177

149178
.. _query-hash:
150179

151-
152180
``queryHash``
153181
~~~~~~~~~~~~~
154182

source/reference/operator/aggregation/planCacheStats.txt

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ document similar to the following:
108108
<number>,
109109
...
110110
],
111-
"indexFilterSet" : <boolean>
111+
"indexFilterSet" : <boolean>,
112+
"estimatedSizeBytes" : <num> // Available starting in MongoDB 4.2.12, 4.0.23, 3.6.23
112113
}
113114

114115
Each document includes various query plan and execution stats,
@@ -123,7 +124,9 @@ including:
123124

124125
* - ``createdFromQuery``
125126

126-
- A document that contains the specific query that resulted in
127+
- .. _plancachestats-createdFromQuery:
128+
129+
A document that contains the specific query that resulted in
127130
this cache entry; i.e.
128131

129132
.. code-block:: javascript
@@ -161,9 +164,11 @@ including:
161164
currently available indexes for that shape. For more information, see
162165
:data:`explain.queryPlanner.planCacheKey`
163166

164-
* - ``cachedPlan``
167+
* - :ref:`cachedPlan <plancachestats-cachedPlan>`
168+
169+
- .. _plancachestats-cachedPlan:
165170

166-
- The details of the cached plan. See :data:`explain.queryPlanner`.
171+
The details of the cached plan. See :data:`explain.queryPlanner`.
167172

168173
* - ``works``
169174

@@ -175,24 +180,36 @@ including:
175180
* - ``timeOfCreation``
176181
- Time of creation for the entry.
177182

178-
* - ``creationExecStats``
183+
* - :ref:`creationExecStats <plancachestats-creationExecStats>`
184+
185+
- .. _plancachestats-creationExecStats:
179186

180-
- An array of execution stats documents. The array contains a
187+
An array of execution stats documents. The array contains a
181188
document for each candidate plan.
182189

183190
For details on the execution stats, see
184191
:data:`explain.executionStats`.
185192

186-
* - ``candidatePlanScores``
193+
* - :ref:`candidatePlanScores <plancachestats-candidatePlanScores>`
187194

188-
- An array of scores for the candidate plans listed in the
195+
- .. _plancachestats-candidatePlanScores:
196+
197+
An array of scores for the candidate plans listed in the
189198
``creationExecStats`` array.
190199

191200
* - ``indexFilterSet``
192201

193202
- A boolean that indicates whether the an :ref:`index filter
194203
<index-filters>` exists for the query shape.
195204

205+
* - ``estimatedSizeBytes``
206+
207+
- A number that describes the estimated size in bytes of a plan
208+
cache entry.
209+
210+
.. versionadded:: 4.2.12 (*and 4.0.23 and 3.6.23*)
211+
212+
196213
Examples
197214
--------
198215

@@ -275,7 +292,8 @@ The operation returns all entries in the cache:
275292
1.5003000000000002,
276293
1.5003000000000002
277294
],
278-
"indexFilterSet" : false
295+
"indexFilterSet" : false,
296+
"estimatedSizeBytes" : NumberLong(3160) // Available starting in MongoDB 4.2.12, 4.0.23, 3.6.23
279297
}
280298
{ // Plan Cache Entry 2
281299
"createdFromQuery" : {
@@ -303,7 +321,8 @@ The operation returns all entries in the cache:
303321
1.0003000000000002,
304322
1.0003000000000002
305323
],
306-
"indexFilterSet" : false
324+
"indexFilterSet" : false,
325+
"estimatedSizeBytes" : NumberLong(2539) // Available starting in MongoDB 4.2.12, 4.0.23, 3.6.23
307326
}
308327
{ // Plan Cache Entry 3
309328
"createdFromQuery" : {
@@ -331,7 +350,8 @@ The operation returns all entries in the cache:
331350
1.7503000000000002,
332351
1.7503000000000002
333352
],
334-
"indexFilterSet" : false
353+
"indexFilterSet" : false,
354+
"estimatedSizeBytes" : NumberLong(3183) // Available starting in MongoDB 4.2.12, 4.0.23, 3.6.23
335355
}
336356
{ // Plan Cache Entry 4
337357
"createdFromQuery" : {
@@ -363,7 +383,8 @@ The operation returns all entries in the cache:
363383
1.6669666666666665,
364384
1.6669666666666665
365385
],
366-
"indexFilterSet" : false
386+
"indexFilterSet" : false,
387+
"estimatedSizeBytes" : NumberLong(4653) // Available starting in MongoDB 4.2.12, 4.0.23, 3.6.23
367388
}
368389

369390
See also :ref:`plan-cache-key`.
@@ -415,7 +436,7 @@ specific information for a particular query shape:
415436

416437
.. code-block:: javascript
417438

418-
db.orders.aggregate( [
439+
db.orders.aggregate( [
419440
{ $planCacheStats: { } },
420441
{ $match: { planCacheKey: "DD67E353"} }
421442
] )
@@ -424,7 +445,7 @@ The operation returns the following:
424445

425446
.. code-block:: javascript
426447
:copyable: false
427-
448+
428449
{
429450
"createdFromQuery" : {
430451
"query" : { "quantity" : { "$gte" : 5 }, "type" : "apparel" },
@@ -589,7 +610,8 @@ The operation returns the following:
589610
1.5003000000000002,
590611
1.5003000000000002
591612
],
592-
"indexFilterSet" : false
613+
"indexFilterSet" : false,
614+
"estimatedSizeBytes" : NumberLong(3160) // Available starting in MongoDB 4.2.12, 4.0.23, 3.6.23
593615
}
594616

595617
See also :ref:`plan-cache-key` and :ref:`query-hash`.

0 commit comments

Comments
 (0)