Creating and Using Composite Indexes in MySQL
📖 Scenario: You are managing a small online bookstore database. You want to speed up searches that filter books by both author and publication year.
🎯 Goal: Create a table called books with columns for id, title, author, and year. Then add a composite index on author and year to improve search speed.
📋 What You'll Learn
Create a table named
books with columns id (integer primary key), title (varchar 100), author (varchar 50), and year (integer).Add a composite index named
idx_author_year on the author and year columns.Write a query that uses the composite index to find all books by author 'Jane Austen' published in 1813.
Ensure the final table and index creation statements are correct and the query uses the index.
💡 Why This Matters
🌍 Real World
Composite indexes are used in real databases to speed up searches that filter on multiple columns, such as finding books by author and year.
💼 Career
Database administrators and backend developers often create composite indexes to optimize query performance in applications.
Progress0 / 4 steps