Indexes
RequiredRequired
An index is a sorted copy of one or more columns that lets the database find rows without reading the whole table. It speeds up reads and costs space plus a little time on every write.
How to use them
- Index the columns you filter and join on, starting with the most selective.
- Read the plan with
EXPLAIN ANALYZEbefore and after adding one; trust the plan, not intuition. - A composite index on
(a, b)helps queries onaor onaandb, but not onbalone.