IT lexicon › Database › Heap table

Heap table

Database På svenska → Updated: 2026-07-30

A table without a clustered index — rows are stored unordered wherever there's room, not sorted on any key. PostgreSQL always stores this way (a "heap"); in SQL Server a table is a heap until you add a clustered index.

Mechanic: new rows land anywhere with free space; each row has a physical identifier (ctid in Postgres, RID in SQL Server) that indexes point to. Win: fast inserts (no order to maintain). Trade-off: range scans require an index + lookup (the data isn't sorted), and deleted rows leave "holes" → fragmentation/bloat (in Postgres cleaned up by VACUUM). In SQL Server a heap is usually considered worse than a clustered index for most workloads. In PostgreSQL the heap is the norm — order comes from indexes, and CLUSTER re-sorts once (not maintained). Understanding heap vs clustered = understanding how the data actually sits on disk.

← Back to the lexicon