Load SQL query result data into cache in advance
Posted
by Marc
on Stack Overflow
See other posts from Stack Overflow
or by Marc
Published on 2010-04-23T14:38:13Z
Indexed on
2010/04/28
7:33 UTC
Read the original article
Hit count: 295
I have the following situation:
- .net 3.5 WinForm client app accessing SQL Server 2008
- Some queries returning relatively big amount of data are used quite often by a form
- Users are using local SQL Express and restarting their machines at least daily
- Other users are working remotely over slow network connections
The problem is that after a restart, the first time users open this form the queries are extremely slow and take more or less 15s on a fast machine to execute. Afterwards the same queries take only 3s. Of course this comes from the fact that no data is cached and must be loaded from disk first.
My question:
Would it be possible to force the loading of the required data in advance into SQL Server cache?
Note
My first idea was to execute the queries in a background worker when the application starts, so that when the user starts the form the queries will already be cached and execute fast directly. I however don't want to load the result of the queries over to the client as some users are working remotely or have otherwise slow networks.
So I thought just executing the queries from a stored procedure and putting the results into temporary tables so that nothing would be returned.
Turned out that some of the result sets are using dynamic columns so I couldn't create the corresponding temp tables and thus this isn't a solution.
Do you happen to have any other idea?
© Stack Overflow or respective owner