Lesson 4 of 12

Beyond B-Tree: GIN, GiST, BRIN, and Hash Indexes

Applies to PostgreSQL 13–17 Last reviewed May 2026 Grounded in source

The one thing to understand first

B-tree assumes a total ordering of scalar keys. Many workloads do not fit that model — full-text search, JSON containment, geometric overlap, or simply tables too large to index conventionally. PostgreSQL’s extensible access-method framework provides specialised index types for each.

The index type must match the operator in your WHERE clause, not the column’s data type. “Containment” wants GIN, “overlap” wants GiST, “this huge table is already sorted on disk” wants BRIN — pick the structure that speaks your query’s operator and the rest is detail.

GIN — Generalized Inverted Index

src/backend/access/gin/. A GIN index maps each component of a value to the list of rows containing it — an inverted index. It powers:

This is a Pro lesson

Get every Learning Pathway and cookbook recipe — grounded in PostgreSQL source code, with diagnostics, fixes, and prevention for each topic.

Continue this lesson to learn:

  • GiST — Generalized Search Tree
  • BRIN — Block Range Index
  • Hash indexes
  • Layer 3 — Watch it happen on your own database
  • Layer 4 — The levers this hands you
  • Layer 5 — What an Oracle DBA should expect vs what they get
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Was this helpful?

← Back to 02 — Performance: Query & Index Mastery