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

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

This guide includes

Use this when a query is slow and you need to know what the server intends to do about it. This matters because EXPLAIN shows the plan while EXPLAIN ANALYZE runs it and reports what happened - and those are two different questions.

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