Index Types (Clustered, Non-Clustered, Composite, Covering)
Master database index structures: Clustered Indexes vs Secondary Indexes, Index Double-Lookups, Covering Indexes (Index-Only Scans), and GIN/GiST for full-text.
01.1. Clustered vs Non-Clustered (Secondary) Indexes
Understanding the physical layout of indexes is crucial for eliminating query latency bottlenecks:
1. Clustered Index (Table IS the Index)
- In a Clustered Index (default Primary Key in MySQL InnoDB, SQL Server), the leaf pages of the B+ Tree contain the actual physical row data (all columns).
- Because physical disk blocks can only be sorted in one physical order, there can be only ONE Clustered Index per table.
- Advantage: A Primary Key point lookup (
WHERE id = 1042) reaches the leaf node and immediately has all columns in hand with zero additional disk lookups.
2. Non-Clustered (Secondary) Index
- A Secondary Index is an auxiliary B+ Tree created on non-primary columns (e.g.,
CREATE INDEX idx_email ON users(email)). - The leaf nodes of a secondary index do not contain full row data. In MySQL InnoDB, secondary index leaf nodes store the Primary Key value; in PostgreSQL, they store a Tuple ID (TID / Block Pointer) pointing to the row in the heap table file.
- The Double-Lookup Penalty: Searching by email requires two sequential index lookups:
- Traverse the
emailB+ Tree to find the Primary Key (id: 1042). - Traverse the Clustered Primary Key B+ Tree (or Heap File) to fetch the actual row columns (
name, balance, created_at).
- Traverse the
Clustered Index vs Secondary Index Double-Lookup vs Covering Index π―
Clustered Index vs Secondary Index Double-Lookup vs Covering Index π―
How Clustered Indexes store table rows directly in leaf pages, why Secondary Indexes incur a double-lookup penalty, and how Covering Indexes achieve ultra-fast Index-Only Scans.
Unlock Topic #46: Index Types (Clustered, Non-Clustered, Composite, Covering)
You are viewing a preview. The full in-depth engineering deep dive, interactive simulators, architecture flowcharts, and self-assessment quizzes for this topic are available with Pro or Lifetime Access.
Failure modes, high-throughput bottlenecks, and real FAANG implementation decisions.
Interactive system topology diagrams, live parameter simulators, and downloadable SVG charts.
Staff-level multiple-choice quiz questions with instant feedback and answer explanations.
Firebase Google authentication automatically syncs your completed topics and quiz scores.
How clear and staff-actionable was this system breakdown?