Index (database)

Applies to: sql

A database index is an auxiliary structure (usually a B-tree) that lets the engine find rows by a column's value without scanning the whole table, turning O(n) lookups into O(log n). It speeds reads at the cost of extra storage and slightly slower writes.

CREATE INDEX idx_users_email ON users(email);
-- now WHERE email = '...' can use the index

See also: big-o, join