When Does MySQL Query Cache Hurt More Than Help?
The article explains how MySQL's Query Cache, while simple and fast, can incur CPU overhead from hash calculations, suffer frequent invalidations on table changes, and consume excessive memory, making its use potentially counter‑productive under high‑concurrency or volatile data scenarios.
(1) Hash computation and lookup overhead
When a SELECT reaches MySQL with Query Cache enabled, MySQL must compute a hash of the query and look up a cached result. Although the algorithm is efficient, under high concurrency the cumulative CPU cost becomes noticeable.
(2) Cache invalidation problem
If a table changes frequently—data modifications, schema changes, or index alterations—the cached result is invalidated quickly. Consequently, a cached entry may be evicted almost immediately, preventing subsequent identical queries from benefiting from the cache.
(3) Excessive memory consumption
Query Cache stores result sets, not data pages, so the same row can be cached multiple times. This can lead to unnecessary memory usage. Limiting cache size may cause entries to be evicted due to memory pressure, reducing hit rate.
When these issues occur together, using Query Cache can become counter‑productive.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
