mongodb
runtime_error
ai_generated
true
MongoServerError: PlanCache invalidated entry for query shape but could not re-plan: internal error
ID: mongodb/plan-cache-invalidation-failed
82%Fix Rate
88%Confidence
1Evidence
2024-01-10First Seen
Root Cause
The plan cache entry for a query shape was invalidated due to index changes or data distribution shifts, but the query planner failed to generate a new plan due to corrupted cache metadata or missing index.
generic中文
由于索引更改或数据分布变化,查询形状的计划缓存条目失效,但查询规划器因缓存元数据损坏或索引缺失而无法生成新计划。
Official Documentation
https://www.mongodb.com/docs/manual/reference/command/planCacheClear/Workarounds
-
85% success Run db.collection.getPlanCache().clear() followed by db.collection.createIndex() for the missing index, then re-execute the query to force a fresh plan.
Run db.collection.getPlanCache().clear() followed by db.collection.createIndex() for the missing index, then re-execute the query to force a fresh plan.
-
80% success Upgrade to MongoDB 7.0+ where plan cache invalidation is more robust; if not possible, set internalQueryPlanCacheSize to 0 in the configuration to disable caching temporarily.
Upgrade to MongoDB 7.0+ where plan cache invalidation is more robust; if not possible, set internalQueryPlanCacheSize to 0 in the configuration to disable caching temporarily.
中文步骤
Run db.collection.getPlanCache().clear() followed by db.collection.createIndex() for the missing index, then re-execute the query to force a fresh plan.
Upgrade to MongoDB 7.0+ where plan cache invalidation is more robust; if not possible, set internalQueryPlanCacheSize to 0 in the configuration to disable caching temporarily.
Dead Ends
Common approaches that don't work:
-
90% fail
Restarting mongod clears the plan cache temporarily, but the error reoccurs if the underlying cause (e.g., missing index or stale statistics) isn't addressed.
-
70% fail
Manually running db.collection.getPlanCache().clear() may not help if the query shape is still cached in the server's internal structures; the error persists.