Create Index
An index is a lookup list. CREATE INDEX idx_city ON students(city); makes WHERE city = 'Pune' and JOIN … ON city faster. PRIMARY KEY is already an index.
Indexes speed reads and slow writes (INSERT/UPDATE/DELETE must maintain the index). Don’t index every column. Low-cardinality flags (yes/no) often help little.
EXPLAIN SELECT …; shows whether MySQL uses the index (key column). If type=ALL, it scanned the table.
Trap: indexing a column you never filter on. Trap: functions on the column (WHERE YEAR(dob)=2004) that ignore the index.
On the example next to this theory — Create Index — keys and constraints protect data integrity; indexes speed lookups.
CREATE INDEX idx_city ON students(city); EXPLAIN the SELECT.