Chapter 14: Data and failure

The commonest thing a plan shows you is a whole table being read to find one row.

Index

A separate sorted structure that lets the database find rows without reading the whole table, like the index at the back of a book. The usual kind is a B-tree, a wide shallow tree you can walk from top to bottom in a few steps, however many rows there are.

On your laptop with 100 rows, a missing index is invisible, so no test or demo will show it. Agents rarely add one unless asked. But they also over-add when asked to make things fast, and every index is more work on every write. Ask for the index a real query needs, and for the plan that proves it gets used.

Say it to your agent

“The orders page filters on customer_id and sorts by created_at. Add an index on (customer_id, created_at) with CREATE INDEX CONCURRENTLY. Show me EXPLAIN ANALYZE before and after on a table with a million rows, and don't add any other indexes.”

The workshop

Name a word, or describe what you mean in everyday language.