Skip to content

Chapter 1 of 7

Index Fundamentals

An index in PostgreSQL is a secondary data structure maintained alongside a table that lets the query planner locate rows matching a predicate without scanning every row. The trade-off is universal: indexes accelerate reads (selections, joins, and orderings) at the cost of additional storage, slower writes (because every INSERT, UPDATE, or DELETE that touches an indexed column must update each relevant index), and extra work during VACUUM. PostgreSQL ships with a rich family of access methods: B-tree, Hash, GIN, GiST, SP-GiST, and BRIN, supplemented by extension-provided types such as Bloom, zombodb, rum, and pg_trgm's trigram operator classes.

B-tree is the default access method and the workhorse for most workloads. It maintains keys in sorted order on disk, which means it supports equality and range predicates, IS NULL and IS NOT NULL checks, and ORDER BY traversal in index order. The planner can also chain B-tree indexes through bitmap scans and use them as inputs to merge joins, making them remarkably versatile.

Writing performance is the constant reminder behind every indexing decision. Each indexed column adds write amplification: more WAL volume, more random I/O, and more dead tuples to clean up later. The art of indexing in PostgreSQL is choosing access methods and definitions that match real query patterns while keeping the write cost proportional to the benefit gained on reads.

All chapters
  1. 1Index Fundamentals
  2. 2The B-tree Family
  3. 3Specialized Access Methods
  4. 4Extensions for Special Workloads
  5. 5Index Maintenance and Lifecycle
  6. 6The Planner, Statistics, and EXPLAIN
  7. 7Indexes Beyond SELECT Queries

Drill it

Reading is not remembering. These come from the Postgresql Indexing Strategies deck:

Q

What is an index in PostgreSQL?

A secondary data structure that lets the planner find rows matching a predicate without scanning the whole table, at the cost of extra storage and write overhea...

Q

What is a B-tree index in PostgreSQL?

The default index type, a balanced tree that keeps keys sorted and supports equality and range predicates, plus IS NULL, IS NOT NULL, and ORDER BY traversal in...

Q

Which index access method is the default in PostgreSQL?

btree.

Q

What index types does PostgreSQL ship with for general use?

B-tree, Hash, GIN, GiST, SP-GiST, BRIN, and the extension-provided Bloom (and others like zombodb, rum, pg_trgm).