What is the difference between a heap table and an index-organized table?
Answer
A heap table stores rows in no particular order — rows are inserted wherever free space is available. The clustered index (if present) stores pointers back to the heap. In PostgreSQL, all tables are heap tables. In MySQL InnoDB, all tables are index-organized tables (IOT): the primary key IS the clustered index and rows are stored in B-tree order by primary key. IOTs make primary key lookups very fast (single tree traversal to data) but secondary index lookups require two traversals (secondary B-tree to PK, then PK B-tree to data). Choosing a good primary key in InnoDB matters: sequential PKs (AUTO_INCREMENT) cause sequential writes; random PKs (UUIDs) cause random writes and page fragmentation.
Previous
What is database CDC (Change Data Capture)?
Next
What are common anti-patterns in database design?