Skip to content

DOCS-13943 Add plan cache limit and stats #5115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion source/core/query-plans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,32 @@ Users can also:

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

Plan Cache Debug Info Size Limit
--------------------------------

Starting in MongoDB 5.0 (and 4.4.3, 4.2.12, 4.0.23, and 3.6.23), the
:doc:`plan cache </core/query-plans>` will save full ``plan cache``
entries only if the cumulative size of the ``plan caches`` for all
collections is lower than 0.5 GB. When the cumulative size of the
``plan caches`` for all collections exceeds this threshold, additional
``plan cache`` entries are stored without the following debug
information:

- :ref:`createdFromQuery <plancachestats-createdFromQuery>`
- :ref:`cachedPlan <plancachestats-cachedPlan>`
- :ref:`creationExecStats <plancachestats-creationExecStats>`
- :ref:`candidatePlanScores <plancachestats-candidatePlanScores>`

The estimated size in bytes of a ``plan cache`` entry is available in
the output of :pipeline:`$planCacheStats`.

.. _query-hash-plan-cache-key:

``queryHash`` and ``planCacheKey``
----------------------------------

.. _query-hash:


``queryHash``
~~~~~~~~~~~~~

Expand Down
8 changes: 5 additions & 3 deletions source/reference/method/PlanCache.list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ associated with the following shapes:
1.5002
],
"indexFilterSet" : false,
"host" : "mongodb1.example.net:27018",
"estimatedSizeBytes" : NumberLong(3160), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
"host" : "mongodb1.example.net:27018",
"shard" : "shardA" // Available if run on sharded cluster
},

Expand Down Expand Up @@ -292,7 +293,7 @@ associated with the following shapes:

For details on the output, see :ref:`$planCacheStats output
<planCacheStats-output>`.

.. planCache-list-query-shapes:

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

db.orders.getPlanCache().list( [ { $project: {createdFromQuery: 1, queryHash: 1 } } ] )

The operation returns the following query shapes:

.. code-block:: javascript
Expand Down Expand Up @@ -521,6 +522,7 @@ The operation returns the following:
1.5002
],
"indexFilterSet" : false,
"estimatedSizeBytes" : NumberLong(3160), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
"host" : "mongodb1.example.net:27018",
"shard" : "shardA" // Available if run on sharded cluster
}
Expand Down
36 changes: 28 additions & 8 deletions source/reference/operator/aggregation/planCacheStats.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ document similar to the following:
...
],
"indexFilterSet" : <boolean>,
"estimatedSizeBytes" : <num>, // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
"host" : <string>, // Available starting in MongoDB 4.4
"shard" : <string> // Available starting in MongoDB 4.4 if run on sharded cluster
}
Expand Down Expand Up @@ -189,9 +190,11 @@ including:
currently available indexes for that shape. For more information, see
:data:`explain.queryPlanner.planCacheKey`

* - ``cachedPlan``
* - :ref:`cachedPlan <plancachestats-cachedPlan>`

- The details of the cached plan. See :data:`explain.queryPlanner`.
- .. _plancachestats-cachedPlan:

The details of the cached plan. See :data:`explain.queryPlanner`.

* - ``works``

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

* - ``creationExecStats``
* - :ref:`creationExecStats <plancachestats-creationExecStats>`

- .. _plancachestats-creationExecStats:

- An array of execution stats documents. The array contains a
An array of execution stats documents. The array contains a
document for each candidate plan.

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

* - ``candidatePlanScores``
* - :ref:`candidatePlanScores <plancachestats-candidatePlanScores>`

- .. _plancachestats-candidatePlanScores:

- An array of scores for the candidate plans listed in the
An array of scores for the candidate plans listed in the
``creationExecStats`` array.

* - ``indexFilterSet``

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

* - ``estimatedSizeBytes``

- A number that describes the estimated size in bytes of a plan
cache entry.

.. versionadded:: 5.0 (*Also available starting in 4.4.3, 4.2.12,
4.0.23, and 3.6.23*)

* - :ref:`host <plancachestats-host>`

- .. _plancachestats-host:
Expand Down Expand Up @@ -330,6 +345,7 @@ The operation returns all entries in the cache:
1.5002
],
"indexFilterSet" : false,
"estimatedSizeBytes" : NumberLong(3160), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
"host" : "mongodb1.example.net:27018", // Available starting in MongoDB 4.4
"shard" : "shardA" // Available starting in MongoDB 4.4 if run on sharded cluster
}
Expand Down Expand Up @@ -360,6 +376,7 @@ The operation returns all entries in the cache:
1.0002
],
"indexFilterSet" : false,
"estimatedSizeBytes" : NumberLong(2539), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
"host" : "mongodb1.example.net:27018", // Available starting in MongoDB 4.4
"shard" : "shardA" // Available starting in MongoDB 4.4 if run on sharded cluster
}
Expand Down Expand Up @@ -390,6 +407,7 @@ The operation returns all entries in the cache:
1.7502
],
"indexFilterSet" : false,
"estimatedSizeBytes" : NumberLong(3183), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
"host" : "mongodb1.example.net:27018", // Available starting in MongoDB 4.4
"shard" : "shardA" // Available starting in MongoDB 4.4 if run on sharded cluster
}
Expand Down Expand Up @@ -424,6 +442,7 @@ The operation returns all entries in the cache:
1.6668666666666665
],
"indexFilterSet" : false,
"estimatedSizeBytes" : NumberLong(4653), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
"host" : "mongodb1.example.net:27018", // Available starting in MongoDB 4.4
"shard" : "shardA" // Available starting in MongoDB 4.4 if run on sharded cluster
}
Expand Down Expand Up @@ -476,7 +495,7 @@ specific information for a particular query shape:

.. code-block:: javascript

db.orders.aggregate( [
db.orders.aggregate( [
{ $planCacheStats: { } },
{ $match: { planCacheKey: "DD67E353"} }
] )
Expand All @@ -485,7 +504,7 @@ The operation returns the following:

.. code-block:: javascript
:copyable: false

{
"createdFromQuery" : {
"query" : { "quantity" : { "$gte" : 5 }, "type" : "apparel" },
Expand Down Expand Up @@ -651,6 +670,7 @@ The operation returns the following:
1.5002
],
"indexFilterSet" : false,
"estimatedSizeBytes" : NumberLong(3160), // Available starting in MongoDB 5.0, 4.4.3, 4.2.12, 4.0.23, 3.6.23
"host" : "mongodb1.example.net:27018", // Available starting in MongoDB 4.4
"shard" : "shardA" // Available starting in MongoDB 4.4 if run on sharded cluster
}
Expand Down