Unstoppable Domains โ€” Expired Auctions

Math using MySQL or PHP

SpaceshipSpaceship
Watch

eagle12

Established Member
Impact
8
I was wondering if anyone knows is it better to perform math functions in PHP or using SQL? Please include reasons.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Inline SQL math operations are very speedy.

Depends if you're doing math directly related to the database or if you're compiling the information first and then doing math.
 
0
•••
This is a good question and it would depend on a few considerations,
For most general use, the times would be negligible. SQL code would be faster when math operations have to be done repeatedly to large datasets, and for processing data and adding it back into the database. Part of this involves the fact that large datasets dont need to be transferred to the application/application memory. MySQL i optimized to process data on the db like this, other db's have procedures, etc.
Operations that involve storing the results for further processing, and that need to be really dynamic would be best in PHP code, things such as integrals, fatorials, amortization tables etc.
The caveat to SQL code is that its sometimes more complex than just using PHP, and unless you're beyond needing to process tens of thousands of rows, you probably wont see any speed gains.
+1 for PHP
 
0
•••
Thanks for the responses. Here is the SQL I am working with:

Code:
select country.name, IFNULL(unverified,0) as unverified, IFNULL(verified,0) as verified, IFNULL(format(verified/(IFNULL(unverified,0)+verified)*100,2),'N/A') as average, IFNULL(verified + IFNULL(unverified,0),'N/A') as total from country left join  
(select count(*) as verified,country.countryID from school 
left join city using(cityID)
left join province using(provinceID)
left join country using(countryID)
where status = 1
group by country.name
order by country.name) as t1 using(countryID)
left join (select count(*) as unverified,country.countryID from school 
left join city using(cityID)
left join province using(provinceID)
left join country using(countryID)
where status = 0
group by country.name
order by country.name) as t2 using(countryID)
 
0
•••
I wouldn't run math in sql, it is speedy, but it taxes your resources as well.
 
0
•••
IMO the performance hit will be the multiple joins. I hope you have good indexes.
Perhaps the whole statement could be optimized.
 
0
•••
I would try to combine tables if possible so you don't have to use joins. I try to avoid them at all costs.
 
0
•••
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back