On a recently launched site, I noticed that, well over the actual heavy queries on the site, the most costly request, out of several million queries, is actually SET NAMES, which clocks over 2.3 seconds on average, while various multi-join union queries are well below 2 seconds. In the end, this places it near the top of the slow query log, and I just can't think of a way to optimize it.
This does not seem to be a common problem, as I found no reference to it googling.
Since SET NAMES is about collation, here is the related information:
- The MySQL Charset is UTF-8 Unicode (utf8)
- The database connection collation is utf8_unicode_ci
- the database and all its tables use utf8_general_ci
FWIW, this is running MySQL 5.0.45-log. The DB server is localhost.