Middle+
What indexes exist in PostgreSQL?
sobes.tech AI
Answer from AI
In PostgreSQL, there are several types of indexes, each suitable for different tasks:
- B-tree — the most common type, used for equality and range queries.
- Hash — optimal for equality operations, but less versatile.
- GIN (Generalized Inverted Index) — suitable for full-text search and indexing arrays.
- GiST (Generalized Search Tree) — used for geometric data and full-text search.
- SP-GiST (Space-Partitioned GiST) — for specific data structures, such as points in space.
- BRIN (Block Range Index) — efficient for very large tables with ordered data.
Example of creating a B-tree index:
CREATE INDEX idx_users_email ON users USING btree (email);