Clustered vs Non-clustered

Clustered Index

A clustered index decides the physical order of the rows: the table data is the index. There can be only one per table, usually the primary key.

  • SQL Server: the primary key is clustered by default.
  • MySQL InnoDB: rows are always clustered by the primary key.
  • PostgreSQL: tables are heaps; CLUSTER reorders once but is not maintained.

Non-clustered Index

A non-clustered index is a separate structure holding the indexed columns plus a pointer to the row. A table can have many.

ClusteredNon-clustered
Per tableonemany
Storesthe full rows, in key orderkey + pointer to the row
Best forrange scans on the key, ORDER BY keyselective lookups on other columns