Guided Notes

Indexes & Views

Speeding up queries with indexes, reading EXPLAIN, composite and unique indexes, and saving queries as views.

What an index is

Slide 1 / 5

An index is a sorted lookup structure (a B-tree) that lets MySQL find rows without scanning the whole table — like a book's index.

CREATE INDEX idx_orders_customer ON orders (customer_id);

• Primary keys and UNIQUE constraints are indexed automatically. • Index the columns you search, join, and sort on most. • Indexes speed up reads but slow writes slightly and use disk space — don't index everything.

← Constraints & AUTO_INCREMENT