MySQL中的数学函数是否比PHP快? [英] Are mathematical functions in MySQL faster than PHP?

查看:60
本文介绍了MySQL中的数学函数是否比PHP快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MySQL已有一段时间了,但是我从未真正使用过受支持的

I've been working with MySQL for a while, but I've never really used the supported mathematical functions, such as FLOOR(), SQRT(), CRC32(), etc.

在查询中使用这些函数,而不是仅仅对PHP结果集进行处理是否更快/更好?

Is it faster / better to use these functions in queries rather than just doing the same on the result set with PHP?

编辑:我不认为这个问题是

EDIT: I don't think this question is a duplicate of this, as my question is about mathematical functions, listed on the page I linked, not CONCAT() or NOW() or any other function as in that question. Please consider this before flagging.

推荐答案

在PHP中执行此操作效率更高.

更快的速度取决于所涉及的计算机,如果您要为一个用户谈论更快的速度.如果您要谈论的是上百万用户访问网站的速度更快,那么使用PHP进行这些计算会更有效.

Faster depends on the machines involved, if you're talking about faster for one user. If you're talking about faster for a million users hitting a website, then it's more efficient to do these calculations in PHP.

运行PHP的Web服务器的负载很容易分布在大量计算机上.这些计算机可以并行运行,处理来自访客的请求并从数据库中获取必要的信息.但是,数据库很难并行运行.复制或分片之类的问题很复杂,可能需要专用软件和适当组织的数据才能正常运行.与将另一个PHP安装添加到服务器阵列相比,这些解决方案是昂贵的.

The load of a webserver running PHP is very easily distributed over a large number of machines. These machines can run in parallel, handling requests from visitors and fetching necessary information from the database. The database, however, is not easy to run in parallel. Issues such as replication or sharding are complex and can require specialty software and properly organized data to function well. These are expensive solutions compared to adding another PHP installation to a server array.

因此,数据库计算机上的CPU周期值比Web服务器上的CPU周期值要有价值得多.因此,您应该在CPU周期更便宜且并行化要容易得多的Web服务器上执行这些数学函数.

Because of this, the value of a CPU cycle on the database machine is far more valuable than one on the webserver. So you should perform these math functions on the webserver where CPU cycles are cheaper and significantly more easy to parallelize.

这篇关于MySQL中的数学函数是否比PHP快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆