What are the principles for writing an optimized sql query? [closed]
If somebody has best Practices for Query Optimization, please write it as an answer.
Last year I followed a series of videos by Andy Warren which I would highly recommend:
- Performance Tuning Puzzle - Part 1
- Performance Tuning Puzzle - Part 2
- Performance Tuning Puzzle - Part 3
Those are good, and he has a bunch more videos with great performance tips.
learn how to analyze the execution plan.
- Pull data from the smallest tables first, then join to the larger ones.
- Use INNER JOIN where you can.
- Put conditions into the JOIN where possible, rather than in the WHERE clause.
These are very rough, not exhaustive, but rules of thumb that help me day-to-day.
Check the MSDN blog of the Query optimization team and this list, both refers to SQL-Server
精彩评论