Why is Your Query Slow? A 60-Second Guide to EXPLAIN

Why is Your Query Slow? A 60-Second Guide to EXPLAIN

T

Theodoros Kafantaris

Published on December 07, 2025

You have a query that takes 3 seconds to run. Why? Guessing doesn't work. MySQL tells you exactly what it is doing if you ask it.

The command is EXPLAIN.

How to use it: Run your slow query in your SQL client (TablePlus, PHPMyAdmin, etc), but put the word EXPLAIN in front of it.

Code
                    EXPLAIN SELECT * FROM orders WHERE status = 'pending';
                

What to look for: Look at the type column in the result.

  • ALL: 🚨 Bad. This is a "Full Table Scan." MySQL is reading every single row to find your data. You are missing an Index.

  • ref / eq_ref: âś… Good. It is using an Index to jump straight to the data.

The Fix: If you see ALL, add an index to the column in your WHERE clause.

Code
                    CREATE INDEX idx_status ON orders(status);
                

Share this post

Challenge Your Mind

NEW!

Take a break from reading and test your logic skills with our daily puzzle!

Latest Challenge: Dec 8, 2025

Daily Logic Ladder - Karl Marx

Play Today's Puzzle

About Our Blog

Explore where technology meets intellect. From technical tutorials to intellectual exploration—stay curious and inspired.

â’¸ 2025. All rights reserved by atomic