Index Best Practices
Tips to use indexes correctly.
Rule 1: Index Columns You Search Often
-- If you often search by email
CREATE INDEX idx_email ON users(email);
-- If you often filter by category
CREATE INDEX idx_category ON products(category);Rule 2: Do Not Index Everything
Too many indexes slow down INSERT/UPDATE.
Bad: Index on every column Good: Index only frequently searched columns
Rule 3: Index Foreign Keys
CREATE INDEX idx_customer_id ON orders(customer_id);Makes JOIN operations faster.
Summary
- Index what you search
- Do not over-index
- Index foreign keys