Common SQL Performance Issues AND HOW TO AVOID OR FIX THEM
Common SQL Performance Issues End users writing poor queries Power users writing poor queries Junior developers writing poor queries Senior developers writing poor queries Software architects writing poor queries.
Query related issues Transact-SQL Performance Issues SR0004: Avoid using columns that do not have indexes as test expressions in IN predicates Missing indexes are the most common problem. SR0005: Avoid using patterns that start with “%” in LIKE predicates Avoid these or use full-text indexes for these fields. SR0006: Move a column reference to one side of a comparison operator to use a column index Do not do calculations on table column values if you can help it to avoid table scans SR0007: Use ISNULL(column, default value) on nullable columns in expressions Always provide a default in a comparison on a nullable field, unless specifically checking for NULL. SR0015: Extract deterministic function calls from WHERE predicates Basically calculate your variables before adding them to the WHERE clause. Think in sets and remove extra calculations from each loop of the set. If you only run it once, then build your set it will be a lot faster.
Query related issues Chapter 14 — Improving SQL Server Performance (outdated but still good to know) SQL Magazine article on perf tuning common-sql-server-problems common-sql-server-problems
SQLCop SQLCop is a little test app. I have most of the tests as sql files so you can run them in a CI build, or you can use the free tool from here:
Entity Framework Issues Troubleshooting Performance Problems in Entity Framework Applications problems-entity-framework-applications problems-entity-framework-applications Performance Considerations for Entity Framework 4, 5, and EF6 Performance Issues performance-issues.aspx performance-issues.aspx Use.AsNoTracking() when you are not going to update the object. performance-issue performance-issue
The Top 5 Most Common SQL Server Performance Problems 1. Memory Pressure 2. Query Timeout Misunderstood "Timeout expired prior to the completion of..." 3. CXPACKET Wait Type 4. Expecting Auto Update Statistics to Keep Statistics Updated 5. TempDb PAGELATCH Contention common-sql-server-performance-problems/ server-performance-problems/
How To… How to troubleshoot SQL Server performance issues with simple tools (Part 1: How to collect a detailed Perfmon trace) to-troubleshoot-sql-server-performance-issues-with-simple-tools-part- 1-how-to-collect-a-detailed-perfmon-trace.aspx to-troubleshoot-sql-server-performance-issues-with-simple-tools-part- 1-how-to-collect-a-detailed-perfmon-trace.aspx How to use SQL tests in your builds with TeamCity or similar CI tools unit-testing-with-teamcity-continuous-integration/ unit-testing-with-teamcity-continuous-integration/