← PostgreSQL learning path
PostgreSQL · Module 6 of 10

Indexes and performance

Make queries fast and read query plans.

📖 Key ideas

  1. B-tree indexes are the default: CREATE INDEX ON orders(user_id);
  2. EXPLAIN ANALYZE shows the plan and actual time.
  3. Seq Scan reads the whole table; Index Scan uses an index.
  4. GIN indexes suit JSONB and full-text; partial indexes cover subsets.
  5. VACUUM and ANALYZE keep tables healthy and statistics fresh.
💡 Real-life example: EXPLAIN is Google Maps for your query: it shows the route the database will take.
B-treeDefault index type
EXPLAIN ANALYZEShows plan with real timings
GIN indexIndex for JSONB/arrays/full-text
VACUUMCleans dead rows