1

Is there much in the way of a performance difference between having a SUM calculation inside a SQL query vs calculating it in a variable after the query?

Not the greatest example but:

IFNULL(AVG((service + value + quality)/3),0) AS business_average

vs

$average_rating = ($value + $quality + $service) / 3;

Only the calculation I'm using is pretty damn extensive - I prefer the variable method as it's more readable, not I can put that aside if the performance is greater via the SQL query

potts
  • 155
  • 1
  • 14
  • Have you tried what is faster? – Daan Mar 16 '15 at 14:40
  • 1
    Some insight here: http://stackoverflow.com/questions/24425756/are-mathematical-functions-in-mysql-faster-than-php – n-dru Mar 16 '15 at 14:41
  • How would I go about testing? Or do you know of any tutorials I can read up on to find out? :/ – potts Mar 16 '15 at 14:41
  • You really need to test it - I've seen more than twenty fold improvements by using SQL math functions over processing in PHP, there is some overhead in processing in PHP and as datasets get larger, that can come into play more and more. – OddEssay Mar 16 '15 at 14:58
  • You mentioned that the example wasn't the greatest. One reason for that is that the two candidates do different things. Make sure that your real candidates have the same functionality. – Dan Bracuk Mar 16 '15 at 16:20
  • @DanBracuk, that example was solely given to elaborate what I meant by SQL / PHP variable - If I paste in my actual code the question would be dwarfed by the code – potts Mar 16 '15 at 16:25

0 Answers0