A few of our WordPress theme demos started to run slowly. Time to fire up newrelic to find out the problem.
It quickly stood out that WordPress SQL queries are chewing up most of the time:
What did I find in these demo database tables? 18000 WooCommerce “wc_session” entries.
All of these wc_session entries had “autoload” set to “no”. When WordPress starts it does a SQL query a bit like this:
SELECT * FROM wp_demo_options WHERE autoload = "yes"
But – there is no MySQL index on “autoload”! (Google for reasons).
So this SQL query was very expensive, since 99.99% of the option entries (wc_session) in this database table have autoload = “no”.
The quick fix for my live demos was to delete all %wc_session% entries and add an autoload
index so it doesn’t slow down again in the future.