What does EXPLAIN show you, and which fields do you look at first when tuning a query?
EXPLAIN prints the plan the optimiser intends to use. The columns worth reading in order:
- type — the access method, and the first thing to check. Roughly best to worst:
const,eq_ref,ref,range,index,ALL. SeeingALLon a large table means a full scan. - key — which index was actually chosen. NULL here alongside a large
rowsvalue is the classic missing-index signature. - rows — the optimiser's estimate of rows examined at this step. Multiply across joined tables to see the real cost.
- filtered — the percentage of those rows expected to survive the WHERE clause.
- Extra — where the useful warnings live.
Using filesortandUsing temporarymean work is spilling out of the index;Using indexis the good case, a covering index that never touches the table.
Note: EXPLAIN shows the plan; EXPLAIN ANALYZE actually runs the query and shows real timings and real row counts next to the estimates. When the estimate and the actual differ wildly, your table statistics are stale — run ANALYZE TABLE.





