What is a database index?
A separate, sorted structure that lets the database find rows without reading the whole table.
A query that takes two milliseconds on your laptop takes ten seconds in production. Very often, the fix is one line: add an index.
What it is
A database index is a separate, sorted structure that lets the database find rows without reading the whole table.
How it works
Without an index, finding one email among ten million users means checking every row, a full table scan. With an index on the email column, the database keeps the emails sorted in a tree, usually a B-tree, and jumps to the right one in a handful of steps. Adding one is a single command: CREATE INDEX.
Why it matters
Indexes make reads much faster, but every write has to update them too, so they slow down writes and use extra space. Index the columns you search and sort by.










