Repaso
Español
Databases & SQLIntermediateDB-17

EXPLAIN shows a sequential scan on a 50M-row table for WHERE email = ?. Most likely fix?

Options

  1. Add more RAM
  2. Add an index on email (Correct option)
  3. Rewrite in NoSQL
  4. 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.

Key terms

Practice this question in Repaso