Jump to content

Which is the best way?


LooieENG

Recommended Posts

I think it would be better in the session so that you aren't making an extra query to your DB every time a page is loaded. If the session variables were stored in memory, it would be quite a bit more efficient (relatively), but for some reason, I think the info is actually stored in the session file and read every time it is accessed. In either case, there is much less "looking" to do if you use the session.

Just query it on each page load.  If you leave it in the session or memory or anywhere else, then it can be changed and your session (or whatever it is) may become stale.  In order to determine if the data is stale, you will have to run a query to determine if the data in the database is newer than the data you have stored anyways.

 

So since you have to hit the DB with a query and process the results anyways, it might as well be a select query with a proper index that gets the data you need.

 

Here's a helpful hint, database indexes are a compromise between size and speed.  IF all of the data in the select query happens to be stored in the index, then the DB engine will only use the index for your select; this is the best possible case.  If the select statement has columns that are not part of the index, then the DB will use the index to prune the rows and then pull the remaining columns from the actual table file on disk.  So my suggestion is to keep the amount of information you need on each page down to the bare minimum and create an index on those columns.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.