OPTIMIZATION PRO

Slow Query Analyzer

Automatically detects slow database queries, runs MySQL EXPLAIN analysis, and suggests specific index fixes — all locally, with no external API calls.

What It Does

The Slow Query Analyzer monitors every database query WordPress executes and logs any that exceed a configurable time threshold (default: 0.1 seconds). Each logged query is analyzed using MySQL EXPLAIN to identify performance issues like full table scans, missing indexes, and inefficient joins. The module then generates ready-to-run SQL statements to add the recommended indexes. All analysis happens on your server — no data is sent externally.

Features

  • Real-time query monitoring using WordPress SAVEQUERIES constant (enabled via MU-plugin for early initialization)
  • Configurable slow query threshold (default 0.1s) — queries slower than this are logged automatically
  • Query fingerprinting and deduplication — normalizes SQL by replacing literals with placeholders, so repeated slow queries are grouped together
  • MySQL EXPLAIN-based analysis that detects full table scans, missing indexes, filesort usage, temporary tables, and suboptimal join types
  • Health scoring system (1-10) based on detected issues — critical issues like full table scans score lowest
  • Generates ready-to-run CREATE INDEX SQL statements as fix suggestions
  • One-click index application and revert from the admin UI
  • Background batch processing via WP-Cron for non-blocking analysis
  • Admin-only monitoring option to reduce overhead on frontend requests
  • Export query log to CSV for external analysis
  • Mark queries as fixed to track resolution progress
  • Purge all logged queries to start fresh
  • Reanalyze previously logged queries after database changes
  • Works with WooCommerce, ACF, and any plugin that uses $wpdb

How to Use

  1. Enable the module

    Go to WP Multitool dashboard and toggle on "Slow Query Analyzer". The module deploys an MU-plugin to enable SAVEQUERIES early in the WordPress bootstrap.

  2. Configure the threshold

    Navigate to WP Multitool > Slow Queries > Settings. The default threshold is 0.1 seconds (100ms). Lower it to 0.05s to catch more queries, or raise it if you only want to find the worst offenders.

  3. Let it collect data

    Browse your site normally. The analyzer runs in the background and logs slow queries as you (or your visitors, if admin-only is off) use the site. WP-Cron processes the analysis in batches.

  4. Review the query log

    Go to WP Multitool > Slow Queries. You will see a table of logged queries sorted by duration, with health scores and occurrence counts. Each query shows its EXPLAIN analysis.

  5. Apply suggested fixes

    For queries with index suggestions, click "Apply Index" to run the CREATE INDEX statement. The module tracks which indexes it has created so you can revert them if needed.

  6. Monitor improvements

    After applying fixes, mark queries as fixed. New occurrences of the same query pattern will be re-logged if they still exceed the threshold, letting you verify the fix worked.

Settings

SettingDefaultDescription
Enable Monitoring On Toggle query monitoring on or off. When off, no queries are logged but existing log data is preserved.
Slow Query Threshold 0.1s (100ms) Minimum query duration to trigger logging. Queries faster than this are ignored. Typical range: 0.05s for thorough analysis, 0.5s for only critical issues.
Monitor Admin Only On When enabled, only tracks queries during admin/logged-in sessions. Reduces overhead on frontend requests for visitors.

FAQ

Does monitoring slow down my site?

The SAVEQUERIES constant adds minor overhead to every database query (storing the query string and timing data in memory). With "Admin Only" enabled (the default), this only affects admin sessions. The actual EXPLAIN analysis runs in background WP-Cron batches, not during page loads.

Is any data sent to an external server or AI service?

No. Despite the "AI" in the internal module name, all analysis is done locally using MySQL EXPLAIN and rule-based logic. No queries, no data, nothing leaves your server.

Why are no queries being logged?

Check three things: (1) monitoring is enabled in Settings, (2) the threshold is not set too high — try 0.05s, (3) WP-Cron is running — test with: wp cron event run wpmultitool_sqaa_batch_process. Also verify the MU-plugin exists at wp-content/mu-plugins/wp-multitool-fixes.php.

Is it safe to apply the suggested indexes?

Generally yes. The module suggests standard MySQL indexes based on EXPLAIN analysis. However, adding too many indexes can slow down INSERT/UPDATE operations. The module tracks applied indexes so you can revert any of them with one click.

Does this work with WooCommerce?

Yes. WooCommerce sites often have the most to gain since WooCommerce generates complex queries on product pages, cart, checkout, and admin order screens. The analyzer catches slow WooCommerce queries and suggests indexes for custom WooCommerce tables.

Ready to optimize your WordPress site?

Join developers using WP Multitool to debug, optimize, and maintain WordPress.

Get WP Multitool