How many Queries are too many?

I have been asked this question quite a few times and I never have a perfect answer. It is obviously an important question to ask but it can be answered in many different ways based on preferences, need for plugins, optimization techniques used and a variety of other factors.

Weblog Tools Collection uses a lot of plugins and is very query heavy but the in spite of that, the front page uses 59 queries to generate itself. I think the default (on a vanilla WordPress install on the default theme) is 27 or something of that nature. The larger the number of queries, the slower the page is going to load and the more load you are going to put on your MySql server. All of the above is true if you do not use inline or regenerative caching mechanisms. The caveat on this blog is that its plugins and its MySql server are highly optimized (via inline caching mechanisms) to reduce load.

Larger number of queries on a WordPress blog are probably caused by plugins that have been installed. Plugin authors can have non-optimized and useless queries that either take a long time to execute or need a large(r) number of queries to acheive a simple(r) result. I suspect that one could follow the 80-20 rule with 80% of the queries on your blog being generated by 20% of the plugins. If you can identify the top hitters and either optimize or replace them, you will have a happier blog and a happier MySql server.

It is also important to remember that the number of queries might not be the only straw that is breaking the camel’s back. SQL queries can be poorly constructed and can put a tremendous drain on resources. I remember a certain recent comments plugin that made queries which scanned entire tables before producing a result. If you are concerned about the speed of you blog or the number of queries, start disabling plugins. You might be pleasantly surprised to find that a few plugins might be causing most of your headaches. Once you identify the suspect plugins, you can then either find replacements that are more oprtimized or find other ways of obtaining the same result.

How many queries does your font page generate? If you find efficiencies by disabling plugins, please tell us about the results.

Leave a Reply