EXPLAIN shows a sequential scan on a 50M-row table for WHERE email = ?. Most likely fix?
Options
- Add more RAM
- Add an index on
email(Correct option) - Rewrite in NoSQL
- Use SELECT DISTINCT
Answer
Add an index on email
Why
EXPLAIN shows the plan the database will use for a query. A 'sequential scan' means it reads every row, here all 50 million, to find one email.
An index on email lets it jump directly to the matching row.
Use EXPLAIN ANALYZE to see real times, and watch out for functions like LOWER(email), which need an index on that expression.
Remember
Seq scan on a big table + selective filter → add an index.