EXPLAIN ANALYZE: Reading the Database's Mind
It's **Day 89**, and we're becoming "Database Whisperers." If you want to know why a query is slow, you don't guess—you use `EXPLAIN ANALYZE`.
The Command
Put `EXPLAIN ANALYZE` before any query:
EXPLAIN ANALYZE
SELECT * FROM users WHERE email = 'test@example.com';
How to Read the Output
The database will return a "Query Plan." Look for these red flags:
1. **Seq Scan (Sequential Scan)**: This means it's doing a Full Table Scan. Bad!
2. **Index Scan**: It's using your index. Good!
3. **Cost**: A relative number representing how hard the DB has to work. Lower is better.
4. **Actual Time**: Exactly how many milliseconds the query took to run.
Why "ANALYZE"?
*Warning: Don't use `EXPLAIN ANALYZE` on a `DELETE` query unless you actually want to delete the data!*
Your Task for Today
Run `EXPLAIN` on a simple query and try to locate the "Seq Scan" or "Index Scan" in the output.
*Day 90: Indexing for Joins—The #1 Speedup.*