我偶然发现我的一位同事写了一个脚本,并找到了如下一行
SELECT SUM(A) + SUM(B) FROM TABLE我提出了一种不同的方法
SELECT SUM( A + B ) FROM TABLE哪条线最有效率?
发布于 2017-07-28 21:30:25
对于带有30M+行的InnoDB/MySQL5.6表,下面是FLOATs结果。
select SUM(x + y) from points;
/* Affected rows: 0 Found rows: 1 Warnings: 0 Duration for 1 query: 8,596 sec. */
select SUM(x + y) from points;
/* Affected rows: 0 Found rows: 1 Warnings: 0 Duration for 1 query: 8,799 sec. */
select SUM(x) + SUM(y) from points;
/* Affected rows: 0 Found rows: 1 Warnings: 0 Duration for 2 queries: 8,720 sec. */
select SUM(x) + SUM(y) from points;
/* Affected rows: 0 Found rows: 1 Warnings: 0 Duration for 2 queries: 8,580 sec. */
select SUM(x + y) from points;
/* Affected rows: 0 Found rows: 1 Warnings: 0 Duration for 1 query: 8,642 sec. */一般来说,时间的范围是相同的,所以我认为这种差异是没有意义的。
https://dba.stackexchange.com/questions/182149
复制相似问题