Cookbook recipe

How a b-tree index speeds up a lookup

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

Scenario

You hear "add an index" constantly but want to know what actually makes it fast. The b-tree turns a full scan into a few page reads. Diagnose it Compare a scan with and without an index:…

Investigation Path

You hear “add an index” constantly but want to know what actually makes it fast. The b-tree turns a full scan into a few page reads.

Diagnose it

Compare a scan with and without an index:

EXPLAIN SELECT * FROM users WHERE email = '[email protected]';  -- Seq Scan
CREATE INDEX ON users (email);
EXPLAIN SELECT * FROM users WHERE email = '[email protected]';  -- Index Scan

Why it happens

A b-tree keeps keys sorted in a shallow, balanced tree. Finding a value walks from the root down a handful of levels — O(log n) page reads — instead of reading every row.

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:

  • How to fix it
  • Prevent it next time
  • Related & next steps
  • All 36 Learning Pathway lessons
  • 170+ cookbook recipes
  • Source-grounded diagnostics & fixes

Secure checkout Cancel anytime Source-grounded

Career Impact

This scenario builds production judgment and operational confidence under pressure.

Open Career Dashboard →

Keep going

Related & next steps

Was this helpful?

← All cookbook recipes