Fixing Slow Reports
Reading a Query Plan
Stop Guessing, Look at the Plan
When a report is slow, don't ask AI "make this faster" yet. Ask SQL Server what it's doing. In SSMS, press Ctrl+M (Include Actual Execution Plan) and turn on the page counts:
SET STATISTICS IO ON;
Here's the slow report:
SELECT c.Region,
COUNT(DISTINCT o.OrderId) AS Orders,
SUM(l.Quantity * l.UnitPrice) AS Revenue
FROM dbo.Orders AS o
JOIN dbo.Customers AS c ON c.CustomerId = o.CustomerId
JOIN dbo.OrderLines AS l ON l.OrderId = o.OrderId
WHERE YEAR(o.OrderDate) = 2025
AND MONTH(o.OrderDate) = 3
AND o.Status = 'Shipped'
GROUP BY c.Region
ORDER BY c.Region;
And what it read:
Table 'OrderLines'. Scan count 1, logical reads 6328
Table 'Orders'. Scan count 1, logical reads 8442
Table 'Customers'. Scan count 1, logical reads 96
Logical reads are pages. Use them to compare before and after. Seconds jump around with whatever else the server is doing; reads stay put. Here the report needs 9,542 orders out of 500,000, and it read the entire Orders table to find them.
Five Things to Look For
Read a plan from right to left. Data starts on the right. Follow the fat arrows, because fat means more rows.
| You see | It means | Worry when |
|---|---|---|
| Index Seek | jumped to the rows | it still returns a huge number of rows |
| Index Scan or Clustered Index Scan | read the whole thing | you only needed a small piece |
| Key Lookup | went back to the table, once per row | it runs thousands of times |
| Sort or Hash Match with a yellow warning | ran out of memory and used disk | always worth a look |
| Actual rows far from estimated rows | SQL Server guessed wrong | it's off by 10 times or more |
A scan isn't automatically bad. If you need most of the table, reading all of it is the right move.
The Wrong Guess
That last row in the table explains the classic complaint: "it's fast when I run it and slow in the app." SQL Server builds a plan for the first value it sees and keeps reusing it. In a test database, a stored procedure ran first for a rare status (200 orders), then for a common one:
| Run | Estimated rows | Actual rows | Pages read |
|---|---|---|---|
'Disputed' first |
200 | 200 | 625 |
then 'Shipped', same plan |
200 | 450,000 | 1,379,301 |
'Shipped' with its own plan |
450,000 | 8,442 |
A key lookup is fine 200 times and a disaster 450,000 times. It's called parameter sniffing, and you spot it by comparing estimated to actual. One fix is OPTION (RECOMPILE) at the end of the query. It builds a fresh plan every run, which costs a little CPU each time: fine for a report, not for something that runs a thousand times a second.
Plans are just XML text, so AI can read them. In SSMS, right-click the plan, choose Show Execution Plan XML, and paste it in. Look first: a plan can contain table names and real values, so treat it like data.
The plan estimated 200 rows and actually got 450,000. What does that tell you?