1. Indexes
- Use appropriate indexes for frequently queried columns
- Be mindful of index overhead - too many indexes can slow down writes
- Consider covering indexes for queries that only need indexed columns
- Use composite indexes effectively based on query patterns
2. Query Structure
- Avoid SELECT * when you only need specific columns
- Use JOINs efficiently and minimize unnecessary joins
- Consider query execution order (FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY)
- Use EXISTS instead of IN for better performance with subqueries
- Minimize the use of DISTINCT when possible
3. WHERE Clause Optimization
- Place most restrictive conditions first
- Avoid functions on indexed columns as they prevent index usage
- Use appropriate operators (=, IN, BETWEEN rather than OR when possible)
- Consider index usage when using wildcards in LIKE conditions
4. Data Types
- Use appropriate data types for columns
- Keep consistent data types in JOIN conditions
- Consider storage and performance implications of chosen data types
5. Database Design
- Proper normalization/denormalization based on use case
- Partitioning for large tables when appropriate
- Efficient primary key design
6. Query Analysis
- Use EXPLAIN/EXPLAIN ANALYZE to understand query execution plans
- Monitor query performance metrics
- Look for table scans vs index scans
7. Caching
- Implement appropriate caching strategies
- Consider materialized views for complex queries
- Use temp tables or CTEs for complex intermediate results