Mysql – query_cache_type = 0 vs query_cache_type = 1

cacheMySQLpercona

Recently, I moved from standard MySQL to Percona, and used the Percona Wizard to generate my.cnf.

However, I can see that, by default, the generated settings for my.cnf use query_cache_type = 0. (query cache is disabled).

The only thing I run on the server is a WordPress blog. My questions are:

  1. May I enable query cache?
  2. There are some WordPress plugins that offer database cache. Is the result similar of enabling query cache?

Best Answer

For a Wordpress blog it should be fine to set query_cache_type = 1. See, the major problems with the query cache are:

  1. It invalidates very easily (any update on some table invalidates all queries related to said table)

  2. It has a single mutex on which any incoming or outgoing query must go through.

The query cache was fine in the days where machines had one core, maybe two; it does not fare well with multiple cores and high concurrency, and it does not fare well with write intensive applications.

Your Wordpress blog is not likely to be write intensive: your writes are new posts, updates, comments... How many of these? You may not even counter them on a per-minute basis...

It would actually not be read intensive either. Hundreds of reads per day Thousands? That's nothing.

With regard plugins, that greatly depends on the plugin and on your deployment. Wordpress is written in PHP, and PHP might use such cache mechanisms as file system, memcached or APC. It should be typically "better" caching for the specific purpose it is oriented. That is, it will invalidate cached data based on real changes to relevant data -- not for irrelevant operations on some table. The programmers of the plugin would need to decide which pieces of data are important to cache, which are not, how invalidation works.

Again, in the scale of a blog, this is no big deal, and should not make a significant difference (of course there could always be some crazy plugin).

Bottom line: for your needs, anything goes and it does not matter much.