Learning path

Full curriculum

Full curriculum

Unit content

Database indexes

Without an index, a database may need to inspect many rows to find those matching a query condition. A database index is an additional data structure that organizes selected column values so matching rows can be located more efficiently.

Index entries

An index stores search keys together with information that identifies the corresponding table rows or records.

For example, an index on users.email can let the database navigate by email value instead of scanning every user row.

Ordered indexes

B-tree-family indexes keep keys ordered. They support equality lookups as well as ordered ranges such as

WHERE created_at >= '2026-01-01'

and can sometimes supply an requested ordering directly.

The cost of an index

An index occupies storage and must be updated when indexed data changes. Additional indexes can therefore speed reads while increasing write work, memory pressure and maintenance cost.

Indexes are workload-specific

An index helps only when its organization matches useful access patterns. Indexing every column indiscriminately is not a substitute for understanding the queries the application actually performs.