Databases store tables using a hierarchical structure of pages and heap files. Data is organized in fixed-size pages (typically 8KB-16KB) that contain multiple rows, with databases reading entire pages rather than individual rows for efficiency. Tables are stored in heap files where pages can be unordered, making full table scans expensive. Indexes solve this by creating separate B-tree structures that point to specific pages in the heap, dramatically reducing I/O operations. Clustered indexes physically organize table data based on the index key, with databases like MySQL's InnoDB storing all tables as clustered indexes by default. The choice of primary key affects performance significantly, as random values like UUIDs can cause page splits and fragmentation.
6 Comments
Sort: