Skip to main content
InterviewHubPRO
Section Overview
Q14

Question 14 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

28%
PostgreSQL Enterprise (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)

What are the 6 primary Index Types in PostgreSQL?

senior LevelMost AskedCode ExampleSystem DesignDatabases & SQLPostgreSQL

In Simple Words:

  1. B-Tree (Default): Self-balancing search tree. Best for equality (=) and range queries (<, <=, >, BETWEEN).
  2. GIN (Generalized Inverted Index): Indexes composite items (Arrays, Full-Text Search tsvectors, JSONB documents).
  3. GiST (Generalized Search Tree): Tree structure for geometric shapes, spatial ranges, and full-text search (PostGIS coordinates).
  4. BRIN (Block Range Index): Stores min/max values for ranges of physical disk pages. Extremely compact; ideal for massive append-only sequential data (timestamps, serial IDs).
  5. SP-GiST (Space-Partitioned GiST): For unbalanced data structures (e.g. Radix trees, quad-trees, telephone area codes).
  6. Hash: Fast exact equality matching (=).
text
PostgreSQL Index Types:
┌──────────┬──────────────────────────┬─────────────────────────────────┐
│ Type     │ Operators Supported      │ Ideal Use Case                  │
├──────────┼──────────────────────────┼─────────────────────────────────┤
│ B-Tree   │ <, <=, =, >=, >, BETWEEN │ Primary keys, timestamps, names │
│ GIN      │ @>, ?, ?&, @@ (contain)  │ JSONB, Arrays, Text Search      │
│ GiST     │ &&, &<, &>, <-> (geo)    │ PostGIS Lat/Long, Geometric     │
│ BRIN     │ <, <=, =, >=, >          │ Multi-billion row time-series   │
└──────────┴──────────────────────────┴─────────────────────────────────┘