Hive和MYSQL 傳統資料庫 的區別

2021-10-06 04:22:47 字數 2013 閱讀 9824

hive和mysql(傳統資料庫)的區別

1、查詢語言不同:hql/sql

2、資料儲存位置不同:hdfs/資料庫系統

3、資料格式:可自定義/資料庫系統定義格式

4、資料更新:hive不支援資料更新/mysql支援資料更新update

5、索引:沒有索引,使用mapreduce/mysql有索引

6、延遲性:高/低

7、資料規模:大/小

8、底層執行原理: mapreaduce/excutor執行器

9、可擴充套件性:hadoop/資料庫由於 acid 語義的嚴格限制,擴充套件行非常有限

hive索引原理(0.8版本後加入了點陣圖索引)

hive裡的2維座標系統(第一步定位行鍵 -> 第二步定位列修飾符)

hbase裡的4維座標系統(第一步定位行鍵   ->   第二步定位列簇  ->  第三步定位列修飾符   ->  第四步定位時間戳)

建索引表的步驟:

1、建表,儲存格式為textfile

use dw_htldatadb;

drop table tablename;

create table tablename(aa string comment 'asd',bb int  comment 'asd') 

partitioned by(d string comment 'date')  comment 'table comment' 

row format delimited fields terminated by ',' stored as textfile;

2、建立索引,對錶table的aa列建立索引

use database;

create index idx_table on table tablename(aa)

as 'org.apache.hadoop.hive.ql.index.compact.compactindexhandler' 

with deferred rebuildin table tablen_index;

分割槽建立索引

use database;

create index idx_table on table table(eid)

as 'org.apache.hadoop.hive.ql.index.compact.compactindexhandler' 

with deferred rebuildin table table_index partitioned by (d,eid);

3、重建索引

use database;

alter index idx_table rebuild;

對錶的分割槽重建建索引:

use database;

alter index idx_table partition (d = '2019-04-01') rebuild ;

4、檢視索引

show formatted index on table;

注意:索引在查詢時生效,需要設定引數,預設情況下不使用索引。

set hive.input.format=org.apache.hadoop.hive.ql.io.hiveinputformat;

set hive.optimize.index.filter=true;

set hive.optimize.index.filter.compact.minsize=0;

缺點:

從以上過程可以看出,hive索引的使用過程比較繁瑣: 

每次查詢時候都要先用乙個job掃瞄索引表,如果索引列的值非常稀疏,那麼索引表本身也會非常大; 

索引表不會自動rebuild,如果表有資料新增或刪除,那麼必須手動rebuild索引表資料;

hive和mysql(傳統資料庫)的區別

一 hive是什麼 簡單來說,hive就是在hadoop上架了一層sql介面,可以將sql翻譯成mapreduce去hadoop上執行,這樣使得資料開發和分析人員很方便的使用sql來完成海量資料統計與分析,二不必使用程式語言開發mapreduce那麼麻煩 二 hive與mysql的區別 1.查詢語言...

Hive與傳統資料庫對比

由於 hive 採用了sql 的查詢語言 hql,因此很容易將 hive 理解為資料庫。其實 從結構上來看,hive 和資料庫除了擁有類似的查詢語言,再無類似之處。本文將從多個方面來闡述 hive 和資料庫的差異。資料庫可以用在 online 的應用中,但是 hive 是為資料倉儲而設計的,清楚這一...

Hive與傳統資料庫對比

由於hive採用了sql的查詢語言hql,因此很容易將hive理解為資料庫。其實從結構上來看,hive和資料庫除了擁有類似的查詢語言,再無類似之處。資料庫可以用在online的應用中,但是hive是為資料倉儲而設計的,清楚這一點,有助於從應用角度理解hive的特性。hive 傳統資料庫 查詢語言 h...