HIVE常用命令之ANALYZE TABLE命令簡述

上次講過HIVE 的一個常用命令 MSCK REPAIR TABLE , 這次講講HIVE的ANALYZE TABLE命令卵皂,接下來還會講下Impala的 COMPUTE STATS 命令。這幾個命令都是用來統(tǒng)計表的信息的,用于加速查詢。

HIVE的 ANALYZE TABLE 命令是做啥的

Statistics such as the number of rows of a table or partition and the histograms of a particular interesting column are important in many ways. One of the key use cases of statistics is query optimization. Statistics serve as the input to the cost functions of the optimizer so that it can compare different plans and choose among them. Statistics may sometimes meet the purpose of the users' queries. Users can quickly get the answers for some of their queries by only querying stored statistics rather than firing long-running execution plans. Some examples are getting the quantile of the users' age distribution, the top 10 apps that are used by people, and the number of distinct sessions.

其實主要就是為了優(yōu)化查詢,加快查詢的速度式撼。

HIVE的主要統(tǒng)計數(shù)據(jù)
1. 表和分區(qū)的統(tǒng)計數(shù)據(jù) (Table and Partition Statistics):
  • 行數(shù) (Number of rows)
  • 文件數(shù) (Number of files)
  • 文件大小 (Size in Bytes)
2. 列的統(tǒng)計數(shù)據(jù) (Column Statistics): 這是Hive 0.10.0后加入的
3. Top K Statistics
語法

analyze table t [partition p] compute statistics for [columns c,...];

例子1 對hive進(jìn)行表和分區(qū)的分析
#執(zhí)行語句
ANALYZE TABLE dw_wy_srvcc_customized_drilldown_table_daily PARTITION(date_time='20190228') COMPUTE STATISTICS;
#查看結(jié)果
DESCRIBE extended dw_wy_srvcc_customized_drilldown_table_daily PARTITION(date_time='20190228');
image.png

結(jié)果如下 numRows=12552, totalSize=1564884, rawDataSize=1552332

Partition(values:[20190228], dbName:coordinator_test, tableName:dw_wy_srvcc_customized_drilldown_table_daily, createTime:1551344149, lastAccessTime:0, sd:StorageDescriptor(cols:[FieldSchema(name:level, type:bigint, comment:null), FieldSchema(name:pi_name, type:string, comment:null), FieldSchema(name:dimension_type, type:string, comment:null), FieldSchema(name:demension_item, type:string, comment:null), FieldSchema(name:numerator_value, type:double, comment:null), FieldSchema(name:denominator_value, type:double, comment:null), FieldSchema(name:pi_value, type:double, comment:null), FieldSchema(name:degrad_weight, type:double, comment:null), FieldSchema(name:date_time, type:string, comment:null)], location:hdfs://dlbdn3:8020/user/hive/warehouse/coordinator_test.db/dw_wy_srvcc_customized_drilldown_table_daily/date_time=20190228, inputFormat:org.apache.hadoop.mapred.TextInputFormat, outputFormat:org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat, compressed:false, numBuckets:-1, serdeInfo:SerDeInfo(name:null, serializationLib:org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe, parameters:{serialization.format=,, field.delim=,}), bucketCols:[], sortCols:[], parameters:{}, skewedInfo:SkewedInfo(skewedColNames:[], skewedColValues:[], skewedColValueLocationMaps:{}), storedAsSubDirectories:false), parameters:{numFiles=20, COLUMN_STATS_ACCURATE=true, transient_lastDdlTime=1551408396, numRows=12552, totalSize=1564884, rawDataSize=1552332})

例子2 對hive進(jìn)行列的分析
#執(zhí)行語句
analyze table dw_wy_srvcc_customized_drilldown_table_daily compute statistics for columns level;
#查看結(jié)果
describe formatted dw_wy_srvcc_customized_drilldown_table_daily level;
image.png
我這面就不造大量數(shù)據(jù)了童社,有興趣的可以試下,對比下使用analyze table前后的查詢速度著隆,會快很多的扰楼。其實如果是IMPALA和HIVE結(jié)合的話,用IMPALA的COMPUTE STAT會更好美浦。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末弦赖,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子浦辨,更是在濱河造成了極大的恐慌蹬竖,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,496評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件流酬,死亡現(xiàn)場離奇詭異币厕,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)芽腾,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,407評論 3 392
  • 文/潘曉璐 我一進(jìn)店門旦装,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人摊滔,你說我怎么就攤上這事阴绢。” “怎么了艰躺?”我有些...
    開封第一講書人閱讀 162,632評論 0 353
  • 文/不壞的土叔 我叫張陵呻袭,是天一觀的道長。 經(jīng)常有香客問我腺兴,道長棒妨,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,180評論 1 292
  • 正文 為了忘掉前任含长,我火速辦了婚禮券腔,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘拘泞。我一直安慰自己,他們只是感情好陪腌,可當(dāng)我...
    茶點故事閱讀 67,198評論 6 388
  • 文/花漫 我一把揭開白布烟瞧。 她就那樣靜靜地躺著,像睡著了一般染簇。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上锻弓,一...
    開封第一講書人閱讀 51,165評論 1 299
  • 那天,我揣著相機(jī)與錄音青灼,去河邊找鬼。 笑死杂拨,一個胖子當(dāng)著我的面吹牛专普,可吹牛的內(nèi)容都是我干的弹沽。 我是一名探鬼主播,決...
    沈念sama閱讀 40,052評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼策橘,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了役纹?” 一聲冷哼從身側(cè)響起偶摔,我...
    開封第一講書人閱讀 38,910評論 0 274
  • 序言:老撾萬榮一對情侶失蹤促脉,失蹤者是張志新(化名)和其女友劉穎辰斋,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體瘸味,經(jīng)...
    沈念sama閱讀 45,324評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡宫仗,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,542評論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了旁仿。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片藕夫。...
    茶點故事閱讀 39,711評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖枯冈,靈堂內(nèi)的尸體忽然破棺而出毅贮,到底是詐尸還是另有隱情,我是刑警寧澤尘奏,帶...
    沈念sama閱讀 35,424評論 5 343
  • 正文 年R本政府宣布滩褥,位于F島的核電站,受9級特大地震影響炫加,放射性物質(zhì)發(fā)生泄漏瑰煎。R本人自食惡果不足惜铺然,卻給世界環(huán)境...
    茶點故事閱讀 41,017評論 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望酒甸。 院中可真熱鬧魄健,春花似錦、人聲如沸插勤。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,668評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽饮六。三九已至其垄,卻和暖如春苛蒲,著一層夾襖步出監(jiān)牢的瞬間卤橄,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,823評論 1 269
  • 我被黑心中介騙來泰國打工臂外, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留窟扑,地道東北人。 一個月前我還...
    沈念sama閱讀 47,722評論 2 368
  • 正文 我出身青樓漏健,卻偏偏與公主長得像嚎货,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子蔫浆,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,611評論 2 353

推薦閱讀更多精彩內(nèi)容