Query plan cache does not auto‑invalidate after schema changes
0 reputation · 16 May 2022, 07:27 UTC
Goal
Ensure that Cypher queries reflect the latest schema state without manual intervention.
Constraints & Uncertainty
Neo4j’s plan cache stores compiled execution plans to avoid re‑planning. The cache is not automatically invalidated when indexes, constraints, or labels are added or removed. Consequently, a query that previously used an index may continue to use a stale plan, potentially omitting newly indexed properties or applying an outdated index strategy. Administrators must explicitly clear the cache with CALL dbms.clearQueryCache() or restart the instance, which can impact throughput.
Unresolved Questions
- Will future Neo4j releases introduce an automatic cache invalidation mechanism triggered by schema changes, or will the manual approach remain the only option?
- Under what circumstances can stale cache usage lead to incorrect query results, and how can applications detect such inconsistencies without a cache flush?
- Is there a configuration knob to enable selective cache invalidation (e.g., only for specific indexes or constraints) that balances performance with correctness?