How it works
Without an index, finding orders by customer means scanning the whole table. With an index on customer_id the database jumps straight to the matching rows. A composite index covers several columns in a set order, and a unique index doubles as a rule that no two rows may share a value.
Indexes are not free: each one takes storage and slows inserts and updates a little. The EXPLAIN command shows whether a query actually uses one. Adding the right index is often the single biggest speed-up for a slow page.
Related terms
More in Databases and storage
Keeping data correct