Find it with an index

Play this lesson

Sorted makes it fast

An index keeps its values in order. So instead of reading every name, a search can look at one in the middle and keep only the half that could hold the name it wants.

Each look rules out a whole side.

Try it

Find Remy

These 16 player names are sorted, like an index. Tap a name to look at it. Each look rules out the names on the wrong side. Find Remy in as few looks as you can.

Try it in the lesson

Quick check

Remy comes after Ivo in the sorted list. Which names can the search skip?

  1. Ivo and every name before it
  2. Every name after Ivo
  3. None: it still has to check them all
Show the answer

Ivo and every name before it

The list is sorted, so nothing before Ivo can be Remy. One look removes that whole side.

Halving adds up

Looking at the middle each time finds any of 16 names in at most 5 looks. A million names takes at most 20. Reading one by one could take a million.

That is why a lookup on an indexed column hardly slows down as a table grows from thousands of rows to millions.

Quick check

With an index, finding one player among a million takes a million times longer than finding one among one.

Show the answer

False

Each look halves what is left, so a million needs about 20 looks, not a million.

Real indexes take bigger steps

A database index is a search tree where each step has many branches, not two, so each step rules out far more than half. That is what PostgreSQL means by walking "a few levels deep into a search tree".

Read the plan

EXPLAIN, find a player by name
Seq Scan on players  Filter: (name = 'Remy')  Rows: 2,000,000

What does Seq Scan tell Remy?

  1. The database reads every row: there is no usable index on name
  2. The query used an index
  3. The table is empty
Show the answer

The database reads every row: there is no usable index on name

Seq Scan means a sequential scan, every row in order. An index on name would turn it into an Index Scan.

On the studio board

The studio adds a decision to the board:

Every query a player waits for has an index. Each slow query's EXPLAIN plan is read in review.

Bolt says: Next: transactions, all or nothing.

Fact-checked 12 October 2026