Most database performance problems can be solved with the right indexes. You don't need to be a DBA — you just need to understand a few patterns.
The basics
An index is like a book's table of contents. Without it, the database has to read every row to find what you're looking for. With it, it can jump straight to the right page.
Pattern 1: Index your WHERE clauses
If you're querying WHERE email = ?, you need an index on email. This is the most common missing index I see.
Pattern 2: Composite indexes for multi-column queries
If you're querying WHERE user_id = ? AND created_at > ?, you need a composite index on (user_id, created_at). Order matters — put the equality column first.
Pattern 3: Covering indexes
If your query only needs a few columns, include them in the index. The database can satisfy the query entirely from the index, without touching the table.
What to avoid
- Don't index everything. Indexes slow down writes.
- Don't index low-cardinality columns (like
is_active). - Don't forget to analyze your queries. Use
EXPLAIN ANALYZE.
The best index is the one you add after measuring, not before.
If your database is slow, and you're not sure why — reach out. We can help you find the missing indexes (and the ones you don't need).