Lesson 14: Indexes & Query Performance

15 Jul 2026 1 min Swarnil Singhai

An index is a data structure that lets the database find rows without scanning the whole table — the single biggest lever for query speed.

Real-time example

A customer lookup by email goes from scanning 10 million rows to an instant lookup once email has an index.

CREATE INDEX idx_customers_email ON customers(email);

EXPLAIN ANALYZE
SELECT * FROM customers WHERE email = 'amit@example.com';
-- before: Seq Scan; after: Index Scan

What's happening

EXPLAIN ANALYZE shows the actual query plan — 'Seq Scan' means it read every row; 'Index Scan' means it jumped straight to the match.

Index columns you filter or join on frequently — but every index also slows down writes, so don't index everything blindly.

Advertisement