Jump to content

Storing calculation results in database, or doing them on the fly?


Recommended Posts

This might be a loaded question, but if you have an application where a lot of calculations are done (simple calculations, but a lot of them), is it better to store calculation results in MySQL tables, or is it better to do the calculations on the fly each time a page loads?

 

For example, if you have an NCAA Bracket Pool Application that displays TOTAL POINTS for every participant in the pool (and TOTAL POINTS changes for each participant pretty much daily), is it better to run through the calculations for each user every time the "Standings" page is loaded, or should the calculation results be inputted into a MySQL table each time TOTAL POINTS change (i.e. each time a round of the tourney ends).

 

With the latter, the Standings page would just pull the TOTAL POINTS from a database for each user and easily display the standings (i.e. faster than if they calculations were being done on the fly for every participant as the page loaded), but of course updating the TOTAL POINTS in the mysql table every time the TOTAL POINTS change (which is a lot) would be lots of work.

 

Hope this question makes sense  :)

I am unfamiliar with NCAA but you would store all points a player has won during a round, at the end of the game you would sum all sub totals to a total for ranking.

 

round #1:

player_id, points

3, 5

..

 

round #2:

player_id, points

3, 2

...

 

SELECT sum(points) AS total_points FROM table GROUP BY player_id. You could store the total points in a separate rankings table so the calculation only has to be done once (the points in a rankings table should never change).

Fenway,  I am going to read up on data warehousing since I hadn't heard the term until you said it :)  If you know any good resources to learn more about that (or on caching, since I'm unfamiliar with that as well  :-\), please share.

 

Just to make sure, it sounds like you're saying the better bet is to store the calculation results in a "summary" table (rather than do the calcs on the fly every time), right?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.