Skip to content

Commit 580ecd1

Browse files
npentrelandf-mongodb
authored andcommitted
DOCS-13943 Add plan cache limit and stats
1 parent d5f6df5 commit 580ecd1

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

source/core/query-plans.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,32 @@ 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 MongoDB 5.0 (and 4.4.3, 4.2.12, 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+
The estimated size in bytes of a ``plan cache`` entry is available in
161+
the output of :pipeline:`$planCacheStats`.
162+
144163
.. _query-hash-plan-cache-key:
145164

146165
``queryHash`` and ``planCacheKey``
147166
----------------------------------
148167

149168
.. _query-hash:
150169

151-
152170
``queryHash``
153171
~~~~~~~~~~~~~
154172

source/reference/method/PlanCache.list.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ associated with the following shapes:
248248
1.5002
249249
],
250250
"indexFilterSet" : false,
251-
"host" : "mongodb1.example.net:27018",
251+
"estimatedSizeBytes" : NumberLong(3160), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
252+
"host" : "mongodb1.example.net:27018",
252253
"shard" : "shardA" // Available if run on sharded cluster
253254
},
254255

@@ -292,7 +293,7 @@ associated with the following shapes:
292293

293294
For details on the output, see :ref:`$planCacheStats output
294295
<planCacheStats-output>`.
295-
296+
296297
.. planCache-list-query-shapes:
297298

298299
List Query Shapes
@@ -311,7 +312,7 @@ example, the following operation passes in a pipeline with a
311312
.. code-block:: javascript
312313

313314
db.orders.getPlanCache().list( [ { $project: {createdFromQuery: 1, queryHash: 1 } } ] )
314-
315+
315316
The operation returns the following query shapes:
316317

317318
.. code-block:: javascript
@@ -521,6 +522,7 @@ The operation returns the following:
521522
1.5002
522523
],
523524
"indexFilterSet" : false,
525+
"estimatedSizeBytes" : NumberLong(3160), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
524526
"host" : "mongodb1.example.net:27018",
525527
"shard" : "shardA" // Available if run on sharded cluster
526528
}

source/reference/operator/aggregation/planCacheStats.txt

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ document similar to the following:
129129
...
130130
],
131131
"indexFilterSet" : <boolean>,
132+
"estimatedSizeBytes" : <num>, // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
132133
"host" : <string>, // Available starting in MongoDB 4.4
133134
"shard" : <string> // Available starting in MongoDB 4.4 if run on sharded cluster
134135
}
@@ -189,9 +190,11 @@ including:
189190
currently available indexes for that shape. For more information, see
190191
:data:`explain.queryPlanner.planCacheKey`
191192

192-
* - ``cachedPlan``
193+
* - :ref:`cachedPlan <plancachestats-cachedPlan>`
193194

194-
- The details of the cached plan. See :data:`explain.queryPlanner`.
195+
- .. _plancachestats-cachedPlan:
196+
197+
The details of the cached plan. See :data:`explain.queryPlanner`.
195198

196199
* - ``works``
197200

@@ -203,24 +206,36 @@ including:
203206
* - ``timeOfCreation``
204207
- Time of creation for the entry.
205208

206-
* - ``creationExecStats``
209+
* - :ref:`creationExecStats <plancachestats-creationExecStats>`
210+
211+
- .. _plancachestats-creationExecStats:
207212

208-
- An array of execution stats documents. The array contains a
213+
An array of execution stats documents. The array contains a
209214
document for each candidate plan.
210215

211216
For details on the execution stats, see
212217
:data:`explain.executionStats`.
213218

214-
* - ``candidatePlanScores``
219+
* - :ref:`candidatePlanScores <plancachestats-candidatePlanScores>`
220+
221+
- .. _plancachestats-candidatePlanScores:
215222

216-
- An array of scores for the candidate plans listed in the
223+
An array of scores for the candidate plans listed in the
217224
``creationExecStats`` array.
218225

219226
* - ``indexFilterSet``
220227

221228
- A boolean that indicates whether the an :ref:`index filter
222229
<index-filters>` exists for the query shape.
223230

231+
* - ``estimatedSizeBytes``
232+
233+
- A number that describes the estimated size in bytes of a plan
234+
cache entry.
235+
236+
.. versionadded:: 5.0 (*Also available starting in 4.4.3, 4.2.12,
237+
4.0.23, and 3.6.23*)
238+
224239
* - :ref:`host <plancachestats-host>`
225240

226241
- .. _plancachestats-host:
@@ -330,6 +345,7 @@ The operation returns all entries in the cache:
330345
1.5002
331346
],
332347
"indexFilterSet" : false,
348+
"estimatedSizeBytes" : NumberLong(3160), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
333349
"host" : "mongodb1.example.net:27018", // Available starting in MongoDB 4.4
334350
"shard" : "shardA" // Available starting in MongoDB 4.4 if run on sharded cluster
335351
}
@@ -360,6 +376,7 @@ The operation returns all entries in the cache:
360376
1.0002
361377
],
362378
"indexFilterSet" : false,
379+
"estimatedSizeBytes" : NumberLong(2539), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
363380
"host" : "mongodb1.example.net:27018", // Available starting in MongoDB 4.4
364381
"shard" : "shardA" // Available starting in MongoDB 4.4 if run on sharded cluster
365382
}
@@ -390,6 +407,7 @@ The operation returns all entries in the cache:
390407
1.7502
391408
],
392409
"indexFilterSet" : false,
410+
"estimatedSizeBytes" : NumberLong(3183), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
393411
"host" : "mongodb1.example.net:27018", // Available starting in MongoDB 4.4
394412
"shard" : "shardA" // Available starting in MongoDB 4.4 if run on sharded cluster
395413
}
@@ -424,6 +442,7 @@ The operation returns all entries in the cache:
424442
1.6668666666666665
425443
],
426444
"indexFilterSet" : false,
445+
"estimatedSizeBytes" : NumberLong(4653), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
427446
"host" : "mongodb1.example.net:27018", // Available starting in MongoDB 4.4
428447
"shard" : "shardA" // Available starting in MongoDB 4.4 if run on sharded cluster
429448
}
@@ -476,7 +495,7 @@ specific information for a particular query shape:
476495

477496
.. code-block:: javascript
478497

479-
db.orders.aggregate( [
498+
db.orders.aggregate( [
480499
{ $planCacheStats: { } },
481500
{ $match: { planCacheKey: "DD67E353"} }
482501
] )
@@ -485,7 +504,7 @@ The operation returns the following:
485504

486505
.. code-block:: javascript
487506
:copyable: false
488-
507+
489508
{
490509
"createdFromQuery" : {
491510
"query" : { "quantity" : { "$gte" : 5 }, "type" : "apparel" },
@@ -651,6 +670,7 @@ The operation returns the following:
651670
1.5002
652671
],
653672
"indexFilterSet" : false,
673+
"estimatedSizeBytes" : NumberLong(3160), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
654674
"host" : "mongodb1.example.net:27018", // Available starting in MongoDB 4.4
655675
"shard" : "shardA" // Available starting in MongoDB 4.4 if run on sharded cluster
656676
}

0 commit comments

Comments
 (0)