Skip to the page

Indexes and query performance · Concept

Clustered and non-clustered indexes

The interviewer asks

What's the difference between a clustered and a non-clustered index? How does MySQL's InnoDB store a table compared with PostgreSQL?

Then

Follow-ups the interviewer asks next

  1. Why is a random UUID primary key a bad idea in InnoDB?
  2. What is the "double lookup" when you query by a secondary index in InnoDB?
  3. PostgreSQL has a CLUSTER command. Why isn't the table kept in that order, and what did PostgreSQL 19 change?
  4. Uber moved from PostgreSQL to MySQL in 2016, partly because of how indexes point to rows. What was the argument?

The answer

What a strong answer covers

  • Clustered: the rows themselves are stored in index order; one per table. Non-clustered: a separate structure pointing to rows.
  • InnoDB: the table is a B+ tree on the primary key (or the first NOT NULL unique key, or a hidden row id). Secondary indexes store the primary key value, so a lookup goes secondary index, then primary key tree.
  • PostgreSQL: a heap with no order; every index, including the primary key, points to a tuple id. CLUSTER reorders once but isn't maintained; PostgreSQL 19's REPACK replaces CLUSTER and VACUUM FULL, and REPACK (CONCURRENTLY) does it without blocking reads or writes.
  • InnoDB with a random primary key: inserts land all over the tree (page splits, cache misses), and every secondary index carries the wide key. Sequential keys (bigint, UUIDv7) are better.
  • Uber's 2016 point: in PostgreSQL an update that can't be HOT writes a new tuple and touches every index, which amplified their writes and replication; in InnoDB secondary indexes point to the primary key, so they change only when their own columns change.

The red pen

Common traps

Avoid:"PostgreSQL's primary key is clustered"; "you can have several clustered indexes".

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview