04 - Indexing Deep Dive
What is an Index?
An index is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional storage and slower writes.
Analogy: Book Index vs Database Index
Plain text
Without Book Index:
┌─────────────────────────────────────┐
│ Chapter 1: Introduction............│ ▲
│ Chapter 2: Setup...................│ │
│ ... (300 pages) ...................│ │
│ Topic X on page 285................│ │ Must scan
│ ... (more pages) ..................│ │ everything
│ Chapter 10: Conclusion.............│ ▼
└─────────────────────────────────────┘
With Book Index:
┌─────────────────────────────────────┐
│ Index: │
│ Topic A ............. page 12 │ ┌─────────────┐
│ Topic B ............. page 45 │──►│ Page 285 │
│ ... │ │ Topic X │
│ Topic X ............. page 285 ◄────│ └─────────────┘
│ Topic Y ............. page 300 │
└─────────────────────────────────────┘