CertGrid CertGrid
Hands-on Lab·MySQL

MySQL Query Plans with EXPLAIN

`EXPLAIN` shows what the optimizer intends; `EXPLAIN ANALYZE` runs it and reports what happened. On 400,000 rows the difference between the estimate and the actual is the whole lesson.

Performance Guide 31 of 45 Intermediate

Written against the versions above. `EXPLAIN ANALYZE` is 8.0.18+. It executes the query, so do not run it on a statement whose side effects you cannot afford.

Every command on this page ran on db-a01.
Server NameIP AddressOSRolesCPURAMHDD
db-a01192.168.0.81Ubuntu 26.04 LTSPrimary / Source / Replica Set Member 12 Core4 GB50 GB

Before you start

  1. Build a table worth measuring

  2. Read a plan with no index available

  3. Measure it rather than estimating it

Official sources