TechLead
Lesson 7 of 10
5 min read
PostgreSQL

Indexing & Performance

Speed up queries with the right indexes and EXPLAIN

Why Indexes Matter

Indexes let Postgres find rows quickly without scanning the entire table. The default index type is B‑tree (great for equality and range queries).

Create an Index

CREATE INDEX users_email_idx ON users (email);

Analyze with EXPLAIN

EXPLAIN ANALYZE
SELECT * FROM users WHERE email = 'ada@example.com';

Look for Index Scan vs Seq Scan to understand performance.

Indexing Tips

  • • Index columns used in WHERE, JOIN, and ORDER BY
  • • Don’t over-index (writes become slower)
  • • Use GIN for JSONB or full-text search

Continue Learning