Speed depends on the value
The same report is quick for some customers, stores, or dates and slow for others.
Fast for one customer, painfully slow for another? How to spot a parameter-sensitive query, test it, and choose a safe fix.
SQL Server builds a plan for a query the first time it runs and reuses it. The plan suits the values used that first time. If those were for a small customer with ten orders, the plan may be terrible for your largest customer with fifty thousand. The query is fine one day and slow the next, depending on who ran it first after a restart or plan change.
The same report is quick for some customers, stores, or dates and slow for others.
Performance changes after a restart, a statistics update, or an index rebuild.
Query Store shows the same query with very different plans and durations.
A few values account for a large share of rows, such as one big customer or one main warehouse.
Step 1 of 4
The smallest, a typical, and the largest value for each parameter.
Compare duration, reads, and the plan chosen for each value on a test copy.
See how badly each value does with a plan built for another.
Retest every value after the fix, not just the one that was slow.
Options range from recompiling the query each time it runs, to an optimisation hint for typical values, to splitting the query for large and small cases, to a better index that suits every value. For example: a recompile hint costs a little CPU on every run, which is fine for a report run a few times a day and not for a query run thousands of times a minute.
Tell us which reports or screens vary and for which values. A few lines are enough.