Reputation: 1143
I have an application whose first page after login presents the user with a lot of data. The query against the database takes a long time - let's say 10 seconds. The database is in SQL Server 2008, the query run is constructed as a prepared statement in Java. The data that needs to be displayed though will generally only change once per day. So - if I could have this result cached, and display a lot quicker that would be ideal.
However, I'm not really sure what I need to do to bring down this 10 second wait - every time I load the page the same delay happens. Is there something I need to do to make sure SQL Server caches the results to the query? It certainly doesn't seem to be any quicker on a second load at the minute - where should I start exploring?
All help is much appreciated!
Upvotes: 5
Views: 1977
Reputation: 539
If the data is only updated once a day, consider writing the results to a regular table and updating the table periodically (assuming you have the access necessary for that).
Upvotes: 1
Reputation: 65147
You should look into indexed views.
They let you store in an index the results of a query (in the form of the view) that the optimizer can access indirectly or directly (i.e. it "knows" it has the data and will pull it for queries besides those against that view).
There are a number of constraints as outlined in the link.
They are the only really viable way (besides creating and managing results tables) to cache complicated query results like aggregates.
I'm guessing your query is complicated and/or contains aggregated fields and grouping, which will ALWAYS entail processing overhead even if the data pages are already cached in memory.
Upvotes: 2