Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up

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. Seeing ALL on a large table means a full scan.
  • key — which index was actually chosen. NULL here alongside a large rows value 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 filesort and Using temporary mean work is spilling out of the index; Using index is 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.

All MySQL interview questions

Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up as