Indexes for Common Queries
Add indexes for the queries you'll run most: by user, by date, by foreign key, and measure the impact with EXPLAIN.
What Is an Index?
An index is a separate on-disk data structure that lets the database find rows by column value without scanning the table. The classic implementation is a B-tree.
Indexes Trade Writes for Reads
Every index makes INSERT/UPDATE/DELETE slightly slower (the index must be updated too). Don't add indexes you don't need.
All lessons in this course
- Modelling a Blog: Users Posts Comments
- Choosing Keys and Types
- Indexes for Common Queries
- Seeding the Database with Test Data