What are the differences between a B-tree, GIN, GiST, and BRIN index?
Answer
B-tree (default): balanced tree supporting equality (=), range (<, >), sorting, and LIKE prefix patterns. Best for most scalar data types. Hash: only equality (=); slightly faster than B-tree for equality-only workloads; not WAL-logged in older versions. GIN (Generalized Inverted Index): for composite values (arrays, JSONB, full-text tsvector); maps each element to its containing rows; fast for @>, ?, @@ operators; large, slow to update. GiST (Generalized Search Tree): extensible framework for geometric data, full-text, network addresses; supports PostGIS spatial queries; faster to update than GIN. BRIN (Block Range Index): stores min/max per block range; tiny size; useful for very large tables with naturally ordered data (e.g., time-series); not good for random access patterns.
Previous
What is streaming replication in PostgreSQL?
Next
How do you use full-text search in PostgreSQL?