Skip to main content
Back to Feed
WordPressMySQLWooCommerce

Scaling WooCommerce: Optimizing Options Table Queries on High-Traffic Sites

6 min read

When a WooCommerce store starts scaling, the single most common cause of high page response latency (specifically slow TTFB) is database congestion. And more often than not, the culprit is the wp_options table.

By default, WordPress queries all rows in the options table where autoload = 'yes' on every single request. If this dataset is bloated, it drains memory and clogs up the query execution pipeline.

Step 1: Auditing Your Autoloaded Options Size

To check if your options table is bloated, run this MySQL query directly in PHPMyAdmin or via WP-CLI:

SELECT SUM(LENGTH(option_value)) / 1024 AS size_kb 
FROM wp_options 
WHERE autoload = 'yes';

Autoload Size thresholds:

  • < 800kb — Good condition. Standard baseline.
  • 800kb - 2MB — Warning zone. Time to clean up.
  • > 2MB — Danger. Autoload options will cause visible query lag.

Step 2: Identifying the Bloat Culprits

To find the exact option keys that are taking up the most space, run this query:

SELECT option_name, LENGTH(option_value) AS option_len 
FROM wp_options 
WHERE autoload = 'yes' 
ORDER BY option_len DESC 
LIMIT 10;

WooCommerce transients, session storage keys, and legacy plugin configuration matrices are the most frequent causes of database bloat.

Step 3: Programmatic Clean-up Snippet

If you identify expired transients or session bloat, you can purge them safely. Copy this snippet to your theme's functions.php or execute it inside WP-CLI:

/**
 * @snippet       Purge Expired WooCommerce Transients
 * @author        Sayan Datta
 */
function sayan_purge_woocommerce_session_bloat() {
    global $wpdb;
    
    // Purge all old options transients
    $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_wc_session_%'" );
    $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_timeout_wc_session_%'" );
}

By keeping your database clean and using memory caches like Redis, you can ensure WooCommerce checkouts remain sub-second even under peak load.

Discussion & Feedback

Discussion (3)

Subir D.

Subir D.

It works great!

Reply
Sayan Datta

Sayan Datta

Thanks 🙂

Soumyendu

Soumyendu

I want to give cash back to customers opted for direct bank transfer; how to do that? Wallet plugins are not having such options. Please help.

Reply