忙到現(xiàn)在才得空
馬不停蹄來(lái)更文啦~
成都今天好冷啊~即使躲在辦公室與電腦相依為命,依舊抵抗不住外界凌凌寒風(fēng)。
不得不說(shuō),
凜冬已至?。ù笮∨笥褌冇浀帽E甞_^)
時(shí)間關(guān)系,今天分享數(shù)據(jù)傾斜與優(yōu)化的解決方法
1、設(shè)置屬性來(lái)解決
set hive.optimize.skewjoin=true
set hive.skewjoin.key=100000
還有可能在group by 中設(shè)置
hive.groupby.skewindata=true
在回答優(yōu)化的時(shí)候,也可以說(shuō)map join的方式【對(duì)于小表的關(guān)聯(lián)查詢的時(shí)】
set hive.auto.convert.join=true
set hive.mapjoin.smalltable.fileszie 默認(rèn)為25M
注意在hive2中該項(xiàng)是默認(rèn)開(kāi)啟的。注意一下CDH中使用的版本。
從左到右,依次變大。
2、join語(yǔ)句的優(yōu)化
select m.cid,u.id from table1 m join table2 u on m.cid=u.cid where m.date='2019-12-12'
該條語(yǔ)句的問(wèn)題是,先join在去使用where條件。
優(yōu)化后:
select m.cid,u.id from (select cid from table1 where date='2019-12-12') m join table2 u on m.cid=u.cid
降低了計(jì)算量。
3、distinct優(yōu)化
前: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
4、對(duì)于關(guān)聯(lián)分桶的方式
兩個(gè)表以相同方式劃分桶,或者兩個(gè)表的桶個(gè)數(shù)是倍數(shù)關(guān)系。(分桶之段為關(guān)聯(lián)字段時(shí))
【關(guān)聯(lián)字段一定要是分桶字段】
后面還有其它的數(shù)據(jù)傾斜說(shuō)明:
https://www.cnblogs.com/ggjucheng/archive/2013/01/03/2842860.html
隨機(jī)數(shù)解決數(shù)據(jù)傾斜 ---- null值所產(chǎn)生的數(shù)據(jù)傾斜
https://blog.csdn.net/lpxuan151009/article/details/7980500? ?
END。。。
來(lái)源:成都科多大數(shù)據(jù)科技有限公司
PS:今天微博無(wú)意發(fā)現(xiàn)一個(gè)賬號(hào):笑出腹肌的狗哥。
心情不好或者瓶頸時(shí)刻,放松一下也是可以的。真的笑到流眼淚,很適合放松情緒
