Why Is My Query Slow? (Indexes & EXPLAIN)
A query that's instant on your laptop crawls in production because the database is reading every row to find matches; an index lets it jump straight to them, and EXPLAIN lets you see which one is happening.
Download EPUB- The Full-Table Scan A database with no help reads every single row to find your matches - a full-table scan. That's invisible on 100 rows and brutal on 10 million, which is why a query is fast on your laptop and dying in prod.
- Indexes An index is a separate, sorted structure (a B-tree) that lets the database jump straight to matching rows instead of scanning every one - like the index at the back of a book. It speeds up reads but costs you on writes and disk, so index the columns you filter, join, and sort on, not everything.
- Reading EXPLAIN EXPLAIN shows the database's plan for a query and EXPLAIN ANALYZE actually runs it; learn to read seq scan vs. index scan, compare estimated vs. actual rows to spot a bad plan, and follow the measure-add-index-recheck loop to fix a slow query for real.