10andB.userid<10andA." />

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

hive 優(yōu)化

系統(tǒng) 2860 0

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

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

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

?

基本原則:

1:盡量盡早地過濾數(shù)據(jù),減少每個階段的數(shù)據(jù)量,對于分區(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';

應(yīng)該改寫為:

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包含復(fù)雜邏輯

可以使用中間表來完成復(fù)雜的邏輯

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個數(shù)盡量控制在5個以下

?

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

否則會引起磁盤和內(nèi)存的大量消耗

?

5:寫SQL要先了解數(shù)據(jù)本身的特點(diǎn),如果有join ,group操作的話,要注意是否會有數(shù)據(jù)傾斜

如果出現(xiàn)數(shù)據(jù)傾斜,應(yīng)當(dāng)做如下處理:

set hive.exec.reducers.max=200;

set mapred.reduce.tasks= 200;---增大Reduce個數(shù)

set hive.groupby.mapaggr.checkinterval=100000 ;--這個是group的鍵對應(yīng)的記錄條數(shù)超過這個值則會進(jìn)行分拆,值根據(jù)具體數(shù)據(jù)量設(shè)置

set hive.groupby.skewindata=true; --如果是group by過程出現(xiàn)傾斜 應(yīng)該設(shè)置為true

set hive.skewjoin.key=100000; --這個是join的鍵對應(yīng)的記錄條數(shù)超過這個值則會進(jìn)行分拆,值根據(jù)具體數(shù)據(jù)量設(shè)置

set hive.optimize.skewjoin=true;--如果是join 過程出現(xiàn)傾斜 應(yīng)該設(shè)置為true

?

6:如果union all的部分個數(shù)大于2,或者每個union部分?jǐn)?shù)據(jù)量大,應(yīng)該拆成多個insert into 語句,實(shí)際測試過程中,執(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)化


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

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

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

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 雅江县| 焦作市| 河池市| 平潭县| 江阴市| 巨野县| 吴忠市| 辽宁省| 株洲县| 宜宾县| 栾川县| 鹤壁市| 包头市| 城步| 连州市| 河南省| 湘西| 霍山县| 正安县| 原平市| 新津县| 迁西县| 驻马店市| 桦甸市| 瑞安市| 札达县| 沁源县| 武义县| 兖州市| 雷波县| 罗江县| 龙川县| 钦州市| 化州市| 延安市| 华蓥市| 贵溪市| 时尚| 韶关市| 溆浦县| 滁州市|