Domanda

I have a doubt, is best, in term of performance, retrieving from a large database (50k+ rows growing) on MySQL a "calculated" data or perform the calculus on the fly?

The calculus are simply division and multiplication of some data yet retrieved from DB, but a lot of data (minimum ~300 calculus per load).

Another note, this "page" can be loaded multiple times (it's not an only one-load).

I think that calculate the value (e.g. using a background task) and then only retrieving from a DB is the best solution in term of performance, right?

There is a lot of difference in the two approach?

È stato utile?

Soluzione

I'd play to the strengths of each system.

Aggregating, joining and filtering logic obviously belongs on the data layer. It's faster, not only because most DB engines have 10+ years of optimisation for doing just that, but you minimise the data shifted between your DB and web server.

On the other hand, most DB platforms i've used have very poor functionality for working with individual values. Things likes date formatting and string manipulation just suck in SQL, you're better doing that work in PHP.

Basically, use each system for what it's built to do.

In terms of maintainability, as long as the division between what happens where is clear, separating these to types of logic shouldn't cause much problem and certainly not enough to out way the benefits. In my opinion code clarity and maintainability are more about consistency than about putting all the logic in one place.

TO SUM UP: I'll defenetly use Database for your problem.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top