Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 sql server query performance

Author  Topic 

fqiao70
Yak Posting Veteran

52 Posts

Posted - 2011-06-02 : 15:44:11
i have a sql query first time run, returns in 4 mins. then i run it again it returns back in 10 seconds. after a few hours, i rerun it again it takes 4 mins again...seems like sql server forgets after some time how it optimized the query? how do i make it run in 10 secs or less??

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-02 : 16:47:24
How many rows does the query return? How much memory do you have? Have you checked the page life expectancy and the buffer cache hit ratio? Have you compared the execution plans for when it's fast and when it's slow?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-02 : 16:47:43
This is likely a caching issue, and it sounds like you don't have enough memory.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2011-06-03 : 15:05:17
Actually sql server "forgets" your data, by not having them in data cache, so next time it has to load them from the disk again.

Mirko

My blog: http://mirko-marovic-eng.blogspot.com/
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-03 : 15:28:40
SQL Server doesn't "forget" your data. It only moves things out of memory/cache as needed. If you have enough memory on your system, then this wouldn't happen.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -