10andB.userid<10andA." />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

hive 優(yōu)化

系統(tǒng) 2691 0

Hive是將符合SQL語法的字符串解析生成可以在Hadoop上執(zhí)行的MapReduce的工具。

使用Hive盡量按照分布式計算的一些特點來設計sql,和傳統(tǒng)關系型數據庫有區(qū)別,

所以需要去掉原有關系型數據庫下開發(fā)的一些固有思維。

?

基本原則:

1:盡量盡早地過濾數據,減少每個階段的數據量,對于分區(qū)表要加分區(qū),同時只選擇需要使用到的字段

select ... from A

join B

on A.key = B.key

where A.userid>10

?????and B.userid<10

?????? ?and A.dt='20120417'

?????? ?and B.dt='20120417';

應該改寫為:

select .... from (select .... from A

??????????????????where dt='201200417'

??????????????????????????? ??????? and userid>10

??????????????????????????? ? ) a

join ( select .... from B

???????where dt='201200417'

???????????????????? and userid < 10???

?????) b

on a.key = b.key;

2:盡量原子化操作,盡量避免一個SQL包含復雜邏輯

可以使用中間表來完成復雜的邏輯

drop table if exists tmp_table_1;

create table if not exists tmp_table_1 as

select ......;

?

drop table if exists tmp_table_2;

create table if not exists tmp_table_2 as

select ......;

?

drop table if exists result_table;

create table if not exists result_table as

select ......;

?

drop table if exists tmp_table_1;

drop table if exists tmp_table_2;

?

?

3:單個SQL所起的JOB個數盡量控制在5個以下

?

4:慎重使用mapjoin,一般行數小于2000行,大小小于1M(擴容后可以適當放大)的表才能使用,小表要注意放在join的左邊(目前TCL里面很多都小表放在join的右邊)。

否則會引起磁盤和內存的大量消耗

?

5:寫SQL要先了解數據本身的特點,如果有join ,group操作的話,要注意是否會有數據傾斜

如果出現數據傾斜,應當做如下處理:

set hive.exec.reducers.max=200;

set mapred.reduce.tasks= 200;---增大Reduce個數

set hive.groupby.mapaggr.checkinterval=100000 ;--這個是group的鍵對應的記錄條數超過這個值則會進行分拆,值根據具體數據量設置

set hive.groupby.skewindata=true; --如果是group by過程出現傾斜 應該設置為true

set hive.skewjoin.key=100000; --這個是join的鍵對應的記錄條數超過這個值則會進行分拆,值根據具體數據量設置

set hive.optimize.skewjoin=true;--如果是join 過程出現傾斜 應該設置為true

?

6:如果union all的部分個數大于2,或者每個union部分數據量大,應該拆成多個insert into 語句,實際測試過程中,執(zhí)行時間能提升50%

insert overwite table tablename partition (dt= ....)

select ..... from (

???????????????????select ... from A

???????????????????union all

???????????????????select ... from B

?????????????????? union all

???????????????????select ... from C

??????????????????????????? ???) R

where ...;

?

可以改寫為:

insert into table tablename partition (dt= ....)

select .... from A

WHERE ...;

?

insert into table tablename partition (dt= ....)

select .... from B

WHERE ...;

?

insert into table tablename partition (dt= ....)

select .... from C

WHERE ...;

?

原文地址:http://hbase.iteye.com/blog/1488745

hive 優(yōu)化


更多文章、技術交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 凭祥市| 襄垣县| 米泉市| 香河县| 皋兰县| 彝良县| 尉犁县| 陆丰市| 南陵县| 南安市| 临汾市| 甘谷县| 肇源县| 望谟县| 青田县| 海晏县| 闸北区| 巴南区| 兴文县| 曲靖市| 鹿泉市| 平南县| 务川| 天台县| 黑龙江省| 卫辉市| 永兴县| 顺平县| 汉沽区| 淮南市| 西乌珠穆沁旗| 浦县| 沂南县| 贵溪市| 昌乐县| 晴隆县| 新津县| 石首市| 阿图什市| 九龙坡区| 任丘市|