MySQL & InnoDB (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
Clustered Index vs Secondary Indexes in InnoDB.
senior LevelMost AskedMySQL
In Simple Words: In InnoDB, data storage is organized directly around the Primary Key:
- Clustered Index: The table itself is physically ordered and stored as a B+ Tree keyed by the Primary Key. Leaf nodes contain the complete row data.
- Secondary Index: Leaf nodes do not store full row data or physical disk pointers; they store the Primary Key value.
- Double Lookup: Searching by a secondary index looks up the Primary Key in the secondary index tree, then traverses the Clustered Index tree to fetch the full row (unless using a Covering Index).