Top 20 Query Optimization Techniques

Some tips on query performance.
  1. Create an index on huge tables (>1.000.000 rows)
  2. Use EXISTS() instead of COUNT() to find an element in the table
  3. SELECT specific fields instead of using SELECT *
  4. Avoid subqueries in WHERE clause
  5. Avoid SELECT DISTINCT where possible
  6. Use WHERE clause instead of HAVING
  7. Create joins with INNER JOIN (not WHERE)
  8. Use LIMIT to sample query results
  9. Use UNION ALL instead of UNION wherever possible
  10. Use UNION where instead of WHERE ... OR ... query
  11. Run your query during off-peak hours
  12. Avoid using OR in join queries
  13. Choose GROUP BY over window functions
  14. Use derived and temporary tables
  15. Drop the index before loading bulk data
  16. Use materialized views instead of views
  17. Avoid != or <> (not equal) operator
  18. Minimize the number of subqueries
  19. Use INNER JOIN as little as possible when you can get the same output using LEFT/RIGHT JOIN
  20. Frequently try to use temporary sources to retrieve the same dataset

Popular posts from this blog

SharePoint PowerShell Quick Guide

Dependency Injection in .NET

Git Guide