I have a scheduled api call that fires off some sql. It's a Select with a couple of joins. It's been timing out. It has a TOP 5. Running the query locally it returned instantly. Then I noticed locally it was TOP 10. Changing to TOP 5 means it runs for 40+ seconds. What on merry earth would be the cause of that? Worried the db is getting unstable in someway.
SiempreSteve
04/26/2024, 1:31 PM
I know MS-SQL likes to be a bit mystical some times and try different ways of running queries but usually after the first query it will optimise. This is bizarre.
s
Sven Geusens
05/14/2024, 11:27 AM
That sound super weird indeed, any order by on complex compound or joined columns?
m
Matt Wise
05/14/2024, 12:10 PM
Have you looked at the execution plans SQL can give you?
Sorry - lost in holidays, then the usual too much work (pre and post holiday working hard to try to make up for the "lost time"!) I lost track of this thread. Great tips all. If I get time to look at this again I'll update you on what it is / was / any more mystery.