1and1 Help Centre Categories

print article

What is the MySQL Query Cache?

MySQL server features a Query Cache. When in use, the query cache stores the text of a SELECT query together with the corresponding result that was sent to the client. If an identical query is later received, the server will retrieve the results from the query cache rather than parsing and executing the same query again.

Please note:
The query cache does not return stale data. When data is modified, any old entries in the query cache are flushed so the updated data will be issued.

The query cache is extremely useful in an environment where some tables do not change very often and you have a lot of identical queries. This is a typical situation for many web servers that use a lot of dynamic content.

Below is some performance data for the query cache. (These results were generated by running the MySQL benchmark suite on a Linux Alpha 2 x 500 MHz with 2 GB RAM and a 64 MB query cache):

If all of the queries you are performing are simple (such as selecting a row from a table with one row) but still differ so that the queries cannot be cached, the overhead for having the query cache active is 13%. This could be regarded as the worst case scenario. However, in real life, queries are much more complicated than our simple example, so the overhead is significantly lower.

Searches after one row in a one row table is 238% faster. This can be regarded as close to the minimum speedup to be expected for a query that is cached.

If you want to disable the query cache code, set query_cache_size=0. By disabling the query cache code there is no noticeable overhead (query cache can be excluded from code with help of configure option --without-query-cache ).

For additional information, you may want to reference: