# EXPLAIN at a Glance — MySQL Fundamentals: SQL, Joins and Transactions

Source: https://www.skillbyai.com/en/mysql/sql-explain

> Read EXPLAIN output to see whether MySQL uses an index or a full table scan, and fix slow queries.

## Reading a query plan

`EXPLAIN` shows whether MySQL will use an index or scan the whole table.

```sql
EXPLAIN SELECT * FROM orders WHERE customer_id = 1;
```

Output:

```
id | table  | type | possible_keys        | key                  | rows
1  | orders | ref  | idx_orders_customer  | idx_orders_customer  | 2
```

## type: ALL is a red flag

`type: ALL` in `EXPLAIN` means a full table scan — on a large table, that's usually a sign a useful index is missing.

**Quiz:** In EXPLAIN output, what does `type: ALL` usually indicate?

- [ ] The query used an index perfectly
- [ ] The table has no rows
- [ ] The query will always be fast
- [x] A full table scan happened

*Answer:* A full table scan happened. ALL means MySQL had to read every row — often fixable with an index.
