Lab 12: Indexes Basics
Overview
Step 1: Why Indexes?
Full table scan: Read 1,000,000 rows → find 5 matches
B-tree index: Navigate ~20 comparisons → find 5 matches [50]
/ \
[25] [75]
/ \ / \
[10] [35] [60] [90]
/ \ / \ / \ / \
...leaves with row pointers...Step 2: Setup — Generate Test Data
Step 3: EXPLAIN Without Index
Step 4: CREATE INDEX
Step 5: CREATE UNIQUE INDEX
Step 6: SHOW INDEX (MySQL) and \d+ (PostgreSQL)
Step 7: EXPLAIN with Range Queries and Composite Indexes
Step 8: Capstone — Index Strategy
Summary
Concept
MySQL
PostgreSQL
Last updated
