← Lessons

quiz vs the machine

Silver1100

Databases

The Query Cache Deprecation

Why MySQL removed its built in query cache and what to use instead.

4 min read · intro · beat Silver to climb

What the query cache did

The old MySQL query cache stored the full result of a SELECT keyed by the exact query text. A later identical query could return the cached result without executing. It sounded ideal, but its design fought against concurrent write workloads.

Why it was removed

  • Any write to a table invalidated every cached result for that table, so write heavy workloads thrashed the cache constantly.
  • A single global mutex guarded the cache, turning it into a contention point that hurt throughput on multi core servers.
  • Cache lookups required the query text to match byte for byte, so trivial differences missed.

For these reasons the query cache was deprecated in MySQL 5.7.20 and removed in MySQL 8.0.

What replaces it

  • Rely on the buffer pool to keep hot pages in memory, which speeds the underlying reads.
  • Use an application or proxy cache such as an external key value store for result caching with explicit invalidation you control.

Key idea

The MySQL query cache was removed in 8.0 because table writes invalidated whole result sets and a global mutex caused contention, so rely on the buffer pool and external caches instead.

Check yourself

Answer to earn rating on the learn ladder.

1. Why did writes hurt the query cache so badly?

2. In which MySQL version was the query cache removed?