cancel
Showing results for 
Search instead for 
Did you mean: 

Query time switches between 1x and 2x

Former Member
0 Kudos
2,336

I know this sounds weird but this is a SELECT query and it only happens on the deployment site, I cannot reproduce it on my local machine.

First time I run the query against database, it takes 25 to 30secs and the second time ~13secs (±2secs), the third time 25secs again, so the cycle goes on. It's exactly the same query every time.

Do you have any idea how or why this could happen? Maybe because of disk fragmentation? Or for some reason the cache "invalidates" itself after the second run? (this was a wild one) Unfortunately I cannot expose the full query but its format is like this:

WITH SubQuery (...) as (SELECT ..., row_number() over (...) FROM ....) WHERE .... 
SELECT ... FROM SubQuery WHERE ...

Note: No other processes were interacting with the db at the time of test.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

You haven't posted enough details for us to help you. Some ideas:

  • Cache contents may be impacting elapsed time. The server does take the in-cache proportion of table pages into account during optimization, but if you are memory constrained then the proportion cached may be the "wrong" set of pages.
  • A selectivity estimate may be on the threshold of switching from one plan to another, and with each query execution the statistics may be updated that is resulting in hysteresis.

Attaching graphical plans with statistics for the problem query (for both cases) would be a good idea.

Former Member
0 Kudos

Thank you for the answer and pointers. I'll gather more information in this direction and edit my post.

Former Member
0 Kudos

The computer was on the site and offline so it was not possible to collect further data. But looking at other different problems it was most probably due to harddisk or RAID-related.

Breck_Carter
Participant
0 Kudos

How does one attach a graphical plan without exposing the query? ...I suppose one could manually edit the XML but that might not be sufficient to satisfy auditors etcetera.

Answers (0)