Index
ELI5 — The Vibe Check
A database index is like the index in the back of a book. Without it, the database reads every single row to find what you want. With it, it jumps straight to the answer. Slow queries? Add an index. Magic.
Real Talk
An index is a data structure (usually a B-tree or hash) that improves the speed of data retrieval operations on a table. It stores pointers to rows sorted by the indexed column(s). Indexes speed up SELECT queries but add overhead to INSERT, UPDATE, and DELETE operations.
Show Me The Code
-- Slow without index, fast with it
CREATE INDEX idx_users_email ON users(email);
SELECT * FROM users WHERE email = 'alex@example.com';
When You'll Hear This
"Add an index on the email column to speed up lookups." / "Too many indexes slow down writes."
Related Terms
Explain Plan
EXPLAIN shows you exactly how the database plans to execute your query — which indexes it uses, how many rows it scans, where it is slow.
Primary Key
A primary key is the unique ID that every row in a table must have. Like a social security number for your data — no two rows can have the same one.
Query Optimization
Query optimization is the art of making slow database queries fast. Add an index here, rewrite that subquery as a JOIN, fetch only the columns you need.
Table
A database table is exactly like a spreadsheet tab. It has columns across the top (name, email, age) and rows going down (one per person).