Why plans change
A query that ran in seconds for a year and now runs for twenty minutes has rarely been rewritten. The plan changed. The optimiser made a different decision because the statistics describing the data changed, or because they failed to change when the data did, and the estimate it was working from stopped resembling the table in front of it. Chasing the query text in that situation wastes days. The question worth asking first is what the plan used to be, when it changed, and what else changed around it.
Common causes repeat across estates. Statistics gathered while a table was empty between a truncate and a load. A column with heavily skewed values where the optimiser assumes even distribution. A date range predicate reaching past the highest value the statistics know about, so the estimated row count collapses and a nested loop gets chosen for a large result. Bind variable peeking producing a plan that suits the first value and nothing after it. Each of these leaves a recognisable signature.
The fix depends entirely on the cause, which is why identifying it first is not a formality. Sometimes the answer is a change to how and when statistics are gathered. Sometimes it is a histogram, or the removal of one that is misleading. Occasionally it is stabilising a plan deliberately, which we treat as a considered decision rather than a first response, because a frozen plan will not improve when the data changes again. That trade needs recording somewhere visible.
- Plan history examined to establish when the plan changed and what it changed to
- Statistics gathering strategy reviewed, including its timing relative to bulk loads
- Skew and histogram handling checked on the columns that appear in predicates
- Bind variable sensitivity considered where one plan suits some values and not others
- Plan stabilisation used deliberately and recorded, never reached for as a first response