Indexes
Indexes are data structures that improve query performance. This chapter introduces how to create and use indexes.
Create Index
Drop Index
Index Types
- B-Tree Index (default) - For most queries
- Hash Index - For equality queries
- Full-text Index - For text search
- Spatial Index - For geographic data
When to Use Indexes
Should create index:
- Columns in WHERE clause
- JOIN condition columns
- ORDER BY columns
- Frequently queried columns
Should not create index:
- Small tables
- Frequently updated columns
- Low cardinality columns (like gender)
View Indexes
Performance Optimization
Summary
- Indexes improve query speed
- But slow down writes
- Use indexes wisely
- Maintain indexes regularly
Next Step: Learn TRANSACTIONS