📑 Data & Database Design · Data & Databases
Indexing
Create structures that help the database find data faster.
An index is like a book index: it avoids scanning every page.
Index Email when users frequently search customers by email.
💡 An index is the alphabetical tab list at the side of an address book — you jump straight to "S" instead of reading every name.
💡 Why it matters
As tables grow, searching every row for a match gets painfully slow. An index lets the database jump near the answer instead of scanning everything. Good indexes turn slow queries into fast ones, but each index costs a little extra work on every write, so they are chosen, not sprinkled everywhere.
🛠️ How to achieve it
⚠️ Signs of trouble
- •Searches crawl as the table gets bigger.
- •The database scans the whole table for a single row.
- •Writes slow down because of too many unused indexes.
- •Common lookups have no index backing them.
🎯 Quick check
Score: 0/3Three questions to test the idea.
1. What does an index help the database do?
Answer: Find matching rows without scanning every row
An index lets the database jump near the answer, avoiding a slow scan of the whole table.
2. What is a cost of adding many indexes?
Answer: Each one slows inserts and updates a little
Every index must be kept up to date on each write, so too many indexes slow down inserts and updates.
3. When should you index a column like Email?
Answer: When users frequently search by it
Index the columns real queries filter or join on. If users often search by email, an index on Email pays off.
