开发者

Reduce SQL Query by storing into a variable?

This might be a s开发者_StackOverflowilly question? but are you able to perform a SQL query to the database to get all record items for X, store it into a local variable "myRecords" and then filter our the results contained in "myRecords" variable? (Saves you making multiple rounds/queries to the database).

Is this even a good idea? or a bad idea?


I believe you referring to classic case of caching, there are plenty of resources to guide you though the implementation of such approach. To get more specific answer you will need to give more details of the problem you are trying to solve. The topic is huge and could be very complex depending on the parameters of your environment.


Definitely!! Its called caching.. but so many different ways to do it.. check out this great article http://wiki.asp.net/page.aspx/655/caching-in-aspnet/


I agree with K Ivanov. Just wanted to add a few things.

This can be a huge performance improvement or a complete disaster. Rarely is it in the middle of the two.

I think you might want to do a few things before pursuing this topic. First, profile your database and queries. Look for any areas such as new or changed indexes or even a slightly different table design that might lead to performance improvements first.

There are several problems. The first deals with memory requirements on the machine that will cache this. If your database server is already memory constrained then adding some intermediary cache ON it is not advisable.

If you cache the data in the web server then you might be radically increasing the memory footprint of your application. Further, depending on the caching strategy and the nature of your data it can quickly become stale leading to bad results.

Point is, before you try and go a different path make sure you completely understand the problem you have. It might be as simple as tweaking indexes and/or adding RAM to your DB server. These are relatively easy to implement whereas a solid caching mechanism can either be a boon or lead to even larger problems.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜