Analyze SQL queries and get intelligent index recommendations to improve query performance.
Database indexes are data structures that improve the speed of data retrieval operations. Like an index in a book, they allow the database to find data without scanning every row.
Index on a single column, useful for simple queries.
CREATE INDEX idx_users_email ON users(email);
Index on multiple columns, useful for queries that filter on multiple columns.
CREATE INDEX idx_orders_user_date ON orders(user_id, order_date);
Ensures all values in the indexed column are unique.
CREATE UNIQUE INDEX idx_users_username ON users(username);
Optimized for text search queries.
CREATE FULLTEXT INDEX idx_posts_content ON posts(title, content);
| Operation | Without Index | With Index |
|---|---|---|
| SELECT with WHERE | Slow (Full table scan) | Fast (Index lookup) |
| JOIN operations | Slow (Nested loops) | Fast (Index joins) |
| ORDER BY | Slow (Sort required) | Fast (Pre-sorted) |
| INSERT/UPDATE/DELETE | Fast | Slower (Index maintenance) |
-- Check if index is being used
EXPLAIN SELECT * FROM users WHERE email = 'user@example.com';
-- Results show:
-- type: ref (using index)
-- key: idx_users_email
-- rows: 1 (instead of 100,000)