Skip to content
Commitwise
Menu

Database index

Also called: Index

A sorted structure on one or more columns that lets the database find rows without reading the whole table.

Definition

Most indexes are B-trees: lookups and range scans take a logarithmic number of steps instead of a full scan. A composite index on (a, b) helps queries that filter on a, or on a and b, but not on b alone. Every index makes writes slower and uses space, so indexes are added for the queries an app actually runs, and checked with EXPLAIN.

In practice

An index on orders (customer_id, created_at) turns "a customer's last 10 orders" from a 20-million-row scan into a 10-row read.

Learn it in context

Lessons that use this term.

Related terms

Esc

Type to search the whole site.