Skip to content

Postgresql Indexing Strategies Textbook

A free, self-paced textbook in 7 chapters. Read a chapter, then drill it with the 120 companion flashcards using spaced repetition.

7 chapters · 120 cards · Updated

Chapters

  1. 1Index 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...

  2. 2The B-tree Family

    The most common task is creating a single-column B-tree, for example CREATE INDEX idx_users_email ON users (email). Adding the UNIQUE keyword makes the index enforce uniqueness, an...

  3. 3Specialized Access Methods

    Hash, GIN, GiST, SP-GiST, and BRIN each address workloads that B-tree handles poorly. A Hash index supports only equality (=) comparisons using a hash of the key. Since PostgreSQL...

  4. 4Extensions for Special Workloads

    Two extensions are particularly valuable for real applications. The bloom extension, enabled with CREATE EXTENSION bloom, supplies a Bloom filter index that supports many equality...

  5. 5Index Maintenance and Lifecycle

    Indexes accumulate bloat over time as MVCC creates dead tuples, page splits fragment the structure, and updates produce sparse pages. Bloated indexes waste space and slow scans, so...

  6. 6The Planner, Statistics, and EXPLAIN

    The query planner does not directly know which index to use; it estimates the cost of every candidate plan based on statistics stored in pg_statistic (exposed via pg_stats) and pic...

  7. 7Indexes Beyond SELECT Queries

    Indexes serve more than SELECT queries. Foreign key columns should be indexed to speed up referential integrity checks on the referenced table during INSERT, UPDATE, and DELETE, an...

← Back to the Postgresql Indexing Strategies deck