Standard WordPress performance advice focuses on three main areas: hosting, themes and plugins, and caching. Choose a fast, scalable WooCommerce hosting provider. Avoid heavy themes and carelessly coded plugins. Install a caching solution to limit the time-consuming work a site has to do.
All excellent advice, but it hides an important detail. One reason heavy plugins and themes hurt performance is that they make too many database queries. If you want to know why a page loads slowly, one of the best ways to find out is to explore how many database queries it makes, how often it makes them, and which code is responsible.
In this article, we’ll explore WordPress’s relationship to its database, how it affects WordPress and WooCommerce performance, and how to use the Query Monitor tool to identify and correct database-related performance issues.
WordPress Database Fundamentals
WordPress, and therefore WooCommerce, generates pages on-the-fly when a user visits them. That’s a broad generalization, and we’ll see that it’s not always true, but at its core, WordPress is a dynamic site generator.
It receives a request for a page and runs PHP code, which queries the database to retrieve information such as a post’s content and author, slots that information into a template, and generates the HTML, which is sent to the browser.
How Does the WordPress Database Affect Site Performance?
Network latency aside, much of a page’s load time occurs during page generation, with database queries accounting for a big chunk of that. The more database queries your site runs, the longer that processing time becomes.
There are, of course, other factors, like JavaScript code execution and media loading. But let’s say you’ve applied standard WooCommerce performance optimization techniques and your product and cart pages continue to perform poorly on metrics like Time to First Byte (TTFB).
There’s a good chance that excessive, complex, or unindexed database queries are the root cause. Common culprits include:
Badly coded plugins or themes that make redundant or unoptimized queries.
Outdated or bloated database tables filled with post revisions, spam comments, transients, and orphaned data that slow down queries.
Complex JOIN operations across multiple tables without indexes or caching.
Inefficient WooCommerce queries for product variations, attributes, and metadata..
WooCommerce database optimization focuses on identifying which of these is your issue and the responsible code, whether it’s in a theme, a plugin, or a WooCommerce extension.
The Impact of Caching on WordPress Database Performance
For simplicity’s sake, the above explanation left out one important consideration where database performance is concerned: caching. Database queries are time and resource-intensive. It makes sense to save the results and reuse them next time the same data is queried. This is called database caching.
Instead of storing the retrieved data, WordPress could go a step further and store the object generated from the query data. For example, a post object that contains all the properties and methods needed to display a particular post.
The next time a user loads the page, WordPress skips the query and grabs the ready-made object from the cache. This process is called object caching, and it’s much quicker than querying the database.
By default, WordPress doesn’t do object caching. It regenerates objects on every page load. At Pressable, we offer built-in object caching on every WordPress and WooCommerce hosting account. If you use a less well-optimized hosting provider, you can install a premium caching plugin like WP Rocket or W3 Total Cache to implement an object cache.
If objects are cached, does that mean you don’t have to worry about optimizing database queries? No, for a few reasons:
The cache needs to be built initially. The first time a page loads or after the cache expires, WordPress needs to query the database to generate the objects that will be cached.
Not everything can be cached. Dynamic content that changes frequently or is user-specific (like shopping cart contents or personalized data) can’t be cached effectively.
Poorly optimized queries affect cache building. Even with caching enabled, inefficient queries slow down cache generation and increase server load during cache rebuilds.
Cache storage has limits. Object caches have memory constraints, so not every query result can be stored indefinitely, especially on high-traffic sites with lots of dynamic content, like a busy WooCommerce store.
However, the object cache can obscure database performance problems during testing. It’s important to flush the object cache before you load your test page. That way, you get a clear view of what’s going on under the hood.
Query Monitor is a free developer plugin for WordPress and WooCommerce. You can use it to analyze and debug various aspects of WordPress performance, including database queries, PHP errors, hooks and actions, HTTP API calls, and more.
Most relevant to our purposes, it displays detailed information about all database queries made during a page request, including execution time, affected rows, and the components responsible for each query.
Query Monitor is a powerful and flexible tool, but to give you an example of how it works, let’s assume that a plugin on our WooCommerce store is slowing cart performance by running a large number of unnecessary database queries.
Step 1: Flush the Object Cache
As we mentioned earlier, it’s a good idea to flush the object cache before you proceed with WooCommerce database analysis. You should consider testing on a staging site instead of your live site. Flushing the cache will temporarily degrade performance on a busy store.
Step 2: Check the Overview
Click on the Query Monitor metrics in the admin bar. This opens the Overview panel at the bottom of your screen, showing detailed performance information. When you load a page, pay attention to the database query time and total number of queries. A well-optimized page typically runs fewer than 100 queries.
Step 3: Identify Problem Plugins
In the Query Monitor navigation menu, click on “Queries by Component.” This panel shows aggregate database query information grouped by plugin, theme, and WordPress core. Components are sorted by total query time, helping you identify which plugins slow down performance.
Look for plugins with unusually high query times or excessive query counts. These are your primary suspects for performance issues.
Step 4: Test and Verify
Temporarily deactivate the suspect plugin and reload the page. Check if the total query time improves. If multiple plugins appear problematic, deactivate them one by one to isolate the main culprit.
Once you’ve identified the problem plugin or theme element, you can try changing its configuration to reduce queries or look for alternative plugins.
Boost Your WooCommerce Store’s Performance with Pressable
A dedicated WordPress user since 2007, Varsha has witnessed the platform’s growth and transformations firsthand. With a Masters’ in Computer Science and experience as a web designer/developer, Varsha possesses a strong foundation in various web development technologies.
Her entrepreneurial spirit and freelance background further honed her ability to think creatively and deliver results. This deep understanding, coupled with her technical skills and customer-centric approach, makes her a great part of the Pressable Team. Her genuine desire to help others and her knack for finding solutions make her a customer success rockstar.
Are you struggling to stay on top of server management, up-to-date security, or maintaining adequate backups? These tasks are all part of the operations or “ops” workload for managing a website. The ops workload often […]
If you are responsible for updating multiple websites, the last thing you want to do is hop from one WordPress account to another — logging on and off repeatedly. You want to be able to run […]
To select a host that truly meets the needs of your WordPress website, it’s important to understand what sets the best providers apart from the rest. A number of companies offer managed WordPress hosting plans, […]