Optimize WordPress Database Queries with Query Monitor
We discuss a useful tool — Query Monitor — that helps with debugging slow WordPress database queries.
Why Query Optimization?
We recommend investigating WP Query optimization only if you feel you have optimized all of the above items as much as you can. Another good reason to look into it is if your site has a lot of dynamic data and you have created a lot of custom post types to support it. For some useful pointers on how to do dynamic data design in WP, you can check out article.
Query Monitor Features
Alright, with all those caveats, let’s jump in. A great place to start is the Query Monitor tool. You can download it here. The plugin lets you analyze much more than DB query times.
Database Query Optimization
A great place to start is the Query Tab.
shows all database queries executed along with the corresponding execution time. We can filter queries by query type (SELECT, UPDATE, DELETE) as well as the calling components. Each query is monitored, timed, and tied back to the function that generated it. As a result, you can sort queries based on how long they take to process and pinpoint problematic, slow-loading queries.
Another useful feature is that you can check for any redundant queries in the Duplicate Queries tab:
Filtering queries by component or calling functions makes it easy to see which plugins, themes, or functions on your site are making the most (or the slowest) database queries.
Finally, you should also check out the Transient Updates tab for any ineffective caching. Transients are a way of caching data for a predefined time in WordPress. Unlike storing data in the object cache, Transient API allows developers to store information in your WordPress database with an expiration time.
The Transient Updates section shows any transients that were set, along with their timeout, component, and call stack. In summary, Query Monitor is a wonderful tool to optimize WordPress database queries. While there are more advanced Application Performance Management (APM) products such as New Relic and Firebase, we feel this is a great place to start.
This article was first published at www.exemplifi.io