I have a query that currently runs on two physical servers, in just about 7 seconds. The query is relatively complex because it joins several tables and is formed by the Entity Framework. Currently, I am moving the database to a virtual hosted environment and everything looks fine except for this one query. When querying a virtual instance of SQL Server, the query starts after 7 seconds, but after an hour or two it suddenly takes about 8 minutes.
Looking at the execution plan, while in a slow state, I found an unexpected scan of the full table. If I rebuild the index on this table, it will instantly return to 7 seconds. However, within an hour or so, it will switch to 8 minutes.
There are very few changes in the table in question, and often I was able to determine the zero change between how it works well and works slowly. After the index is restored, fragmentation drops to about 0.02%, but after an hour or two it jumps between 50% -60%.
- Page Completeness - 52.95%
- Total fragmentation - 54.19%
- Average row size - 338
- Depth - 3
- Forwarded entries - 0
- Ghost Records - 0
- Index Type - CLUSTERED INDEX
- Sheet Level Lines - 134900
- Maximum row size - 604
- The minimum row size is 239
- Pages - 10736
- Section ID - 1
- String Versions - 0
I donβt know for sure whether fragmentation is the cause of the problem, but I will completely lose why it can be fragmented so quickly. Can someone explain?
source share