Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7685361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:14:02+00:00 2026-05-31T19:14:02+00:00

I have come across a few questions on the same lines but none exactly

  • 0

I have come across a few questions on the same lines but none exactly the same.

Which one is better, performing some basic calculations in PHP after getting results from MySql (by joining a few tables) or physically having another column in MySql which stores the total while inserting a new row and then retrieving it.

E.g: A product sold:

Item         Price       Quantity      Discount
Item 1        55           100           10%

The above is a sales table, the price column is joint from the items table. Based on the above question either we can use PHP to fetch results, perform Price X Quantity X 0.10 or we our table can look like the following:

Item         Price       Quantity      Discount   Amount
Item 1        55           100           10%        4950

Now which is the better way of doing such a simple task?

Similar Question:
Doing Calculations in MySql vs PHP

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:14:03+00:00Added an answer on May 31, 2026 at 7:14 pm

    There is no blanket rule for all situations. Many factors affect the performance and efficiency of websites. So there’s no single ‘Best’.

    If you look at something like Magento, it does it both ways. On the one hand it has a full EAV structure with every piece of data abstracted out and normalised to the nth degree. On the other hand, it also aggregates pre-calculated values in flat tables for performance reasons. This includes discount amounts, base prices, tax quantities (in base and chosen currency), etc. The former situation is best in terms of flexibility and robustness, the flat table is better in terms of performance.

    A flat table obviously makes it faster when dealing with bulk calculations, as everything has already been worked out. But it does, as kernelpanic pointed out, mean that any changes to settings may require a bulk recalculation of every value. In the case of historical data such as order history, you probably won’t want to recalculate the actual amounts people ended up paying, but the possibility of having to do so does need to be taken into consideration when determining the best solution.

    If performance is paramount and the calculations are expensive to run, then knowing that you may have to refresh the values in bulk from time-to-time allows you to make an informed decision to cache it or not.

    But if it’s not a performance critical aspect, or the calculations are expensive but not run often, it’s cleaner to leave them out of the database as they really belong in the business logic processing part of an application i.e. the code.

    Again there is more than one way of defining “best”, so it depends on the circumstances. It is really just a matter of balancing requirements – speed, cleanliness, memory usage, processor requirements, disk space usage, the need to fit into some arbitrary data structure defined by development managers – your decision will need to account for these factors.

    Without a real-world problem to address, speculation is really all that can be given. If you do have a more complex situation, I’d be happy to take a look and offer my thoughts.

    edit: From my own observations, a Magento catalog page with flat data and over 200k products loads in about 10 – 20 seconds with no page caching enabled. When flat data was disabled and the EAV structure was used, it would take minutes. I’m not at work right now so I don’t have my profiling data handy, but it’s a testament to the fact that in real world applications there is no single best solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across a situation (which I think is weird but is possibly
I have been reading a few questions previously asked and I haven't come across
I've come across a few other questions that describe a similar, but not identical
I have come across a few lines of coding I do not understand, and
I have come across a lot of optimization tips which say that you should
I have come across some strange behaviour, and I'm assuming a bug in Firefox,
I have come across a website that appears to use Ajax but does not
Maybe some of you have come across this before.... I am opening files for
This is a really broad question, but I have come across it a couple
I have come across a few references regarding the JVM/JIT activity where there appears

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.