Where it helps
Searching a table of two million bookings for one phone number without an index means reading every row. With an index on the phone column, the engine goes almost straight to the match. Columns used in WHERE filters, JOIN conditions and ORDER BY clauses are the usual candidates.
The price of an index
Each index takes disk space and must be updated on every insert, update and delete, so too many indexes slow writes. An index on a column with only two values, such as a yes/no flag, rarely helps.
Practical tips
- Use EXPLAIN to see whether a query uses an index or scans the table.
- A composite index on (company_id, created_at) serves queries filtering by both, and column order matters.
- Wrapping an indexed column in a function, such as LOWER(email), can stop the index being used unless the index matches.
- Remove indexes that monitoring shows are never used.
Questions, answered
The planner may skip it for small tables, the query may not match the index, or the real cost may be elsewhere, such as sorting or network.
Yes, in virtually all relational databases a primary key is indexed automatically.