E
E
Evgeny Serdyukov2018-10-15 15:02:44
SQL Server
Evgeny Serdyukov, 2018-10-15 15:02:44

Why can SELECT slow down after some time, only rebuilding helps rebuilding the index?

There is an Orders table. In which there are now about 5 million records.
There are a lot of fields, indexes. Specifically, the RegistrationTime datetime field. It created the IX_RegistrationTime index with DESC sorting.
After some time, about 1 week, the request starts to fall by timeout, for 2 minutes it does not receive data. If this index is recreated (it takes about 3 minutes to recreate, WITH ONLINE=OFF), then the query starts to run in seconds (from 2 to 10 seconds). And before the re-creation, I looked at the SQL report on the physical statistics of the index, then this index did not have any recommended operation, neither rebuild nor reorganize.
Why this can happen, where to dig?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Andrey Skorzhinsky, 2018-10-15
@AndyKorg

Dig in the direction of checking the query plan, see how the optimizer decided to execute your query during "fast" work and during "slow" work

R
res2001, 2018-10-15
@res2001

As far as I remember, you need to update statistics regularly.
Here is a suitable database maintenance script.

D
d-stream, 2018-10-16
@d-stream

I suspect that it's not the index itself. The easiest thing to try is to specify option (recompile) in the request

E
Evgeny Serdyukov, 2018-10-16
@djonik1562

Well, now the same garbage. The request runs for 1 minute, I cancel it.
Updating statistics only indexes did not help.
After updating statistics on columns - the request began to be normally fulfilled.
Here is 99% of the entire request here. And I don’t know yet if it’s possible to somehow optimize the query here.
5bc5a0aed63f9647663573.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question