在 ORDER BY 中使用聚合函数与已经聚合的列之间是否存在性能差异?
Is there a performance difference between using an aggregate function vs an already aggregated column in the ORDER BY?
理想情况下,我想了解 hive 的这一点,但也非常欢迎其他观点。
select a, sum(b) as c
from x
group by a
order by sum(b);
对
select a, sum(b) as c
from x
group by a
order by c;
深入阅读 mysql https://dev.mysql.com/doc/refman/5.7/en/statement-optimization.html
的语句优化
应该没有明显的差异。查询优化器认为这两个查询是相同的
https://dev.mysql.com/doc/refman/5.7/en/order-by-optimization.html
https://dev.mysql.com/doc/refman/5.7/en/group-by-optimization.html
请记住,本质上这两个查询的不同之处仅在于别名的使用,我已通过查询优化器明确解决了这个问题
理想情况下,我想了解 hive 的这一点,但也非常欢迎其他观点。
select a, sum(b) as c
from x
group by a
order by sum(b);
对
select a, sum(b) as c
from x
group by a
order by c;
深入阅读 mysql https://dev.mysql.com/doc/refman/5.7/en/statement-optimization.html
的语句优化应该没有明显的差异。查询优化器认为这两个查询是相同的
https://dev.mysql.com/doc/refman/5.7/en/order-by-optimization.html https://dev.mysql.com/doc/refman/5.7/en/group-by-optimization.html
请记住,本质上这两个查询的不同之处仅在于别名的使用,我已通过查询优化器明确解决了这个问题