Context
The MySQL optimizer estimates how many rows an operation will process when it chooses a plan. A major import or a changed distribution can make those estimates less useful. The resulting regression may look like a missing index even when the schema has not changed. Compare the optimizer's picture with the current data before adding more structures.
Prerequisites
Gather the exact query shape, representative parameter values, before-and-after plans if available, table definitions, recent data changes, and MySQL version. This guide targets MySQL 8.4. Use a representative test copy for statements that execute expensive queries or modify statistics. Inspection privileges differ from maintenance privileges, so establish who can approve and run a targeted analysis.
Investigate the estimate
- Capture
EXPLAINfor the same query and parameters that show the regression. Record chosen indexes, join order, estimated rows, and filtering assumptions. Use bounded, read-only statements for production inspection.EXPLAIN ANALYZEactually executes a statement and can be expensive, so reserve it for an appropriate controlled environment after reviewing its behavior for your version. - Compare the plan with the changed data. Did an import introduce a new dominant status, tenant, date range, or uneven value distribution? Use sampled or indexed checks appropriate to the table size. A full count across a busy large table can itself create an incident. Capture enough evidence to explain the estimate without turning diagnosis into an unrestricted scan.
- Inspect index cardinality and any column histogram information. These are related inputs, not interchangeable features. A histogram on an unindexed filter can inform selectivity, while indexed conditions may use other estimation methods. Identify the specific stale or missing input rather than scheduling every table for analysis.
- On the test copy, run a targeted
ANALYZE TABLEprocedure and compare plans and representative execution behavior. The statement updates statistics, requires privileges, and can acquire locks; it is maintenance work, not a harmless display command. Check whether its binary logging and replica effects fit the rollout plan before applying the approved production change.
Diagnostic table
| Observation | Interpretation | Next check |
|---|---|---|
| Estimates differ after bulk import | Distribution changed | Relevant key and histogram statistics |
| Estimates improve but query remains slow | Another cost dominates | I/O, joins, and actual returned rows |
| One parameter works, another regresses | Workload values differ | Representative parameter set |
| Repeated analysis changes estimates | Sampling variation matters | Persistent-statistics configuration |
Illustrative scenario
An order table previously contained mostly completed orders. A migration adds a large backlog of pending orders, and a filter that used to be selective now returns much more data. The team compares plans for both status values on a test copy. Refreshing the relevant statistics changes the estimate, but it also reveals that the pending-order workflow needs pagination and a different access pattern. Statistics explain the change without promising to remove the underlying work.
Correct and verify
Validate a correction against several meaningful parameter values, not only the example that first failed. Compare response time, rows examined, resource use, and plan stability during representative demand. If analysis worsens important queries, use the documented rollback or mitigation plan and preserve both plans for review. Avoid repeatedly forcing maintenance until one convenient sample looks faster.
Monitoring and SOP
Associate imports and large data corrections with a statistics review checkpoint. Retain representative plans and workload samples without sensitive parameter values. Monitor regressions by query family and business journey, then check whether estimates or actual workload volume changed. Keep targeted analysis decisions in the maintenance record so the team can distinguish data-driven plan changes from schema and application releases.
Explore Clouvenix server performance for implementation and operational handover.