Common Query Tuning Techniques - One Pager Cheat Sheet
1. Use Indexing
- Add indexes to columns in WHERE, JOIN, ORDER BY.
- Use execution plans to verify index usage.
2. Avoid SELECT *
- Fetch only needed columns to reduce load.
3. Write SARGable Queries
- Avoid functions on columns in WHERE.
- Use range-based filtering for dates.
4. Optimize Joins
- Join on indexed columns.
- Use INNER JOIN when possible.
5. Avoid Correlated Subqueries
- Replace with joins or CTEs for better performance.
6. Update Statistics & Rebuild Indexes
- Keeps query optimizer accurate.
7. Use TOP/LIMIT
- Restrict result sets to reduce memory and CPU.
8. Use Proper Data Types
- Choose the smallest data type that fits.
Bonus Tip: Always analyze the execution plan to find scans, lookups, and cost.