First time running a select-statment is sooo slow, second time it goes fast

  • Hi!

    I have got problems with executing some sql-statements (select).

    The first time they are executed they take much longer time then the times after that. The first time after I´ve restarted the SQLserver service it takes a long time again.

    For example, first time: 0,493 sek, second time; 0,017 sek.

    I´ve looked at the indexes and I cant find any problems with theme. We have and also tried to add those that sql suggest but with the same result.

    Can anyone help me?

    Why is the first time soo slow???

  • That's because the proccache (execution plans) are flushed after a restart.  So sql server has to recompile the objects and it also has to reread the data from disk.  After that the data remains in memory so the 2nd execution is much faster (but I guess that this part applies more to a select than an insert).

  • You should be able to duplicate the behavior by using this (only for your personnal experience, and only if you have a low transactionnal environement)

    DBCC FREEPROCCACHE --flush compiled plans

    DBCC DROPCLEANBUFFERS --flush data in memory

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply