数据倾斜处理

公司博客地址:

http://conf.ctripcorp.com/download/attachments/54464460/Hive%E4%BC%98%E5%8C%96%E4%BB%A5%E5%8F%8A%E6%89%A7%E8%A1%8C%E5%8E%9F%E7%90%86.pdf?version=1&modificationDate=1407835496000&api=v2


(一)count distinct数据倾斜

• Select count(distinct id) from acorn_3g.iplogwhere log_date like ‘2013-12%’;

– 耗时:1600S

• Select count(1) from (select distinct id fromacorn_3g.iplog where log_date like ‘2013-12%’and id>0) tmp;

– 耗时:260s


亲自实验:

找了张公司较大数据量的表--携程hotel表

//数据倾斜未处理
select count(distinct hotel) from hotel where bookable like 'T'
 SQL Server Execution Times:
   CPU time = 3401 ms,  elapsed time = 3501 ms.
 
//数据倾斜处理
select count(1) from (select distinct hotel from hotel where bookable like 'T' and hotel>0 ) tmp
 SQL Server Execution Times:
   CPU time = 3510 ms,  elapsed time = 3550 ms.

结果反而慢了?开始怀疑人生了好吗。。。


我想了想,我们的hotel应该是均匀分布的。

找了apply表--申请单表。(不同模块使用人数数量超级倾斜)

//数据倾斜未处理

后台数据查询时间:5.682s
 select count(distinct applyid) from apply where applytypeid=1

//数据倾斜处理
后台数据查询时间:2.491s

select count(1) from (select distinct applyid from apply where applytypeid=1 and applyid>0) tmp


(二)common join倾斜

• select m.uid asuser_id,m.from_id,m.app_id,m.is_auto,u.stage fromacorn_3g.mcs_access m join user u on m.uid = u.id wherem.log_date='2013-12-12’;

– 耗时:最起码2个小时

• select m.uid,m.from_id,m.app_id,m.is_auto,u.stage fromuser u join (select m.uid,m.from_id,m.app_id,m.is_autofrom acorn_3g.mcs_access m where log_date='2013-12-12'and uid>0 group by m.uid,m.from_id,m.app_id,m.is_auto)m on m.uid = u.id

– 耗时:600s

你可能感兴趣的:(BI)