Databases

Index

A data structure maintained alongside a table that makes lookups by specific columns faster, at the cost of slower writes and additional storage.

A B-tree index is the default in most engines and handles equality and range queries. Other types serve narrower purposes: GIN for full-text and JSONB, GiST for spatial data, hash for equality-only. Every index must be written on every INSERT and relevant UPDATE, so unused indexes are pure cost. The query planner decides whether to use an index based on selectivity - if the query would read most of the table anyway, a sequential scan is faster.

Explained in depth

Implemented by

Learn it in context

Related concepts