planCacheSize and $planCacheStats
Parent: MongoDB Explain Plans, Query Planner and Plan Cache · Published reference · snapshot 2026-10-22 · skill ranked-a333aac1
↓ Facts as markdownall context files
Source-anchored research for planCacheSize and $planCacheStats. Run status: COMPLETED.
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
Definitions
- `$planCacheStats` is a collection-scoped aggregation stage that must appear first and returns one document per cache entry; its output can include `isActive`, `works`, and `estimatedSizeBytes` for inspecting entries and their estimated per-entry sizes. (high confidence) (verified as of 2026-10-22) [source]
- The `estimatedSizeBytes` field is an estimate for one cache entry, not an exact total for the whole plan cache. MongoDB's serializer populates that output field from the entry's `estimatedEntrySizeBytes` value. (high confidence) [source]
How it works
- The plan cache is in memory and per collection, is discarded when `mongod` restarts, and uses LRU replacement to remove the least recently accessed entry. (high confidence) [source]
Measurements and reference values
- Starting in MongoDB 6.3, `planCacheSize` is a `mongod` string parameter with a 5% default; it accepts a percentage of system total physical memory or a fixed MB/GB amount and supports startup and runtime changes. MongoDB documents it as applying only to the slot-based query execution engine's plan cache. (high confidence) (verified as of 2026-10-22) [source]
- Starting in MongoDB 5.0, when cumulative plan-cache size across collections exceeds 0.5 GB, MongoDB stores later entries without `createdFromQuery`, `cachedPlan`, `creationExecStats`, or `candidatePlanScores`; `$planCacheStats` also documents `estimatedSizeBytes` as an individual entry estimate. (high confidence) (verified as of 2026-10-22) [source]
Facts and statements
- Plan cache contents are local to each `mongod` and can differ between members. By default, `$planCacheStats` follows read preference and returns data from one member per replica set; on sharded clusters, `allHosts: true` broadcasts to all nodes for affected shards. The `allHosts` option was added in MongoDB 7.1. (high confidence) (verified as of 2026-10-14) [source]
- Per-entry inspection and aggregate hit/miss monitoring provide different views: DataDog's MongoDB integration release 6.10.0, dated 2024-09-05, added plan cache hit and miss rate metrics for MongoDB 7.0 and later. (high confidence) [source]
- Increasing `planCacheSize` can let the planner retain more query shapes and may improve query performance, but it also increases memory use. (high confidence) [source]
Children
- No children recorded.