2

I have a query that has been working fine for ages (2+ years).

All of a sudden it went from taking 3 secs to 30+ to execute. The table indexes have minimal fragmentation, but rebuilding the indexes "fixes" it for about a day.

When I go to check the fragmentation it is around .5 (not bad). The table only sees about 100 inserts and another 100 updates a day.

There are no locks on the table when it happens. Any ideas of what to check?

Mark Henderson
  • 68,823
  • 31
  • 180
  • 259
KellCOMnet
  • 245
  • 2
  • 11

3 Answers3

1

Check if your Statistics is Out-of-date and update it accordingly.

DaniSQL
  • 1,107
  • 7
  • 12
1

What does the execution plan look like when it is fine, vs when it isn't working correctly?

Are you rebuilding the indexes or defragging the indexes? How big is the table? When was the last time you updated stats on the table?

mrdenny
  • 27,174
  • 4
  • 41
  • 69
1

It's probably parameter sniffing (StackOverflow search).

The index rebuild implicitly rebuilds index statistics which invalidates the cached plan which "fixes" it.

gbn
  • 6,079
  • 1
  • 18
  • 21