hive sql的优化

1、count distinct 优化 

--优化前 
select count(distinct id )from tablename 
--优化后 
select count(1) from (select distinct id from tablename)tmp; 
select count(1) from (select id from tablename group by id)tmp;
--注意,如果id 存在空值,那么优化后的两条sql必须写为count(id),否者count会多一条。count(1)和cunt(字段)的区别。

猜你喜欢

转载自www.cnblogs.com/singsong-ss/p/12092922.html