B、count(distinct),在数据量大的情况下,容易数据倾斜,因为count(distinct)是按 group by 字段分组,按 distinct 字段排序
C、 小表关联超大表 join
5、产生数据倾斜的原因
A:key 分布不均匀
B:业务数据本身的特性
C:建表考虑不周全
D:某些 HQL 语句本身就存在数据倾斜
6、业务场景
A:空值产生的数据倾斜
场景说明:在日志中,常会有信息丢失的问题,比如日志中的 user_id,如果取其中的
user_id 和用户表中的 user_id 相关联,就会碰到数据倾斜的问题。
解决方案 1:user_id 为空的不参与关联
select * from log a join user b on a.user_id is not null and a.user_id = b.user_id
union all
select * from log c where c.user_id is null;
解决方案 2:赋予空值新的 key 值
select * from log a left outer join user b on
case when a.user_id is null then concat(‘hive’,rand()) else a.user_id end = b.user_id