MySQL & InnoDB (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
What is a Secondary Index in InnoDB and what does it store in leaf nodes?
junior LevelMost AskedCode ExampleMySQL
In Simple Words: A secondary index (non-clustered index) is built on any column other than the primary key:
- Unlike the clustered index, the leaf nodes of a secondary index do not store row data.
- Instead, leaf nodes store the Primary Key value corresponding to that row!
- Lookup Flow: When searching via a secondary index, MySQL finds the primary key in the secondary index, then performs a second lookup (Bookmark Lookup / Table Lookup) into the clustered index to fetch the actual columns.
text
Secondary Index to Clustered Index Traversal:
[Query: WHERE email = 'alex@example.com']
│
▼
[Secondary Index on email] ──► Leaf Node contains: PK = 42
│
▼
[Clustered Index on id] ──► Leaf Node contains full row data!