hive中的索引創建


1、在hive中創建索引所在表

create table if not exists h_odse.hxy(
id int,
name string,
hobby array<string>,
add map<string,string>
)
partitioned by (age int,sex string)
row format delimited
fields terminated by ','
collection items terminated by '-'
map keys terminated by ':'
lines terminated by '\n'

2、在服務器內創建數據文件並導入數據

load data local inpath '/home/hetl/data' into table h_odse.hxy partition (age=10,sex='f');

3、從其他表中導入數據

load data local inpath '/home/hetl/data' into table h_odse.hxy partition(age=10,sex='boy') ;

from h_odse.hxy1
insert into h_odse.hxy partition(age,sex)
select id,name,hobby,add,age,sex distribute by age,sex;

4、創建指定索引表的索引

create index hxy_ind on table h_odse.hxy(id) as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' with deferred rebuild in table h_odse.h_ind_table;

-----當in table h_odse.h_ind_table不加時  系統會自動創建一個索引表

5,使索引生效的話,必須執行

alter index hxy_ind on  h_odse.hxy rebuild; 

6,測試索引效果

select * from h_odse.hxy where id=1

未加索引時:

Time taken: 0.676 seconds, Fetched: 24 row(s)

添加索引后:

Time taken: 0.494 seconds, Fetched: 24 row(s)

7,、查詢當前表中有哪些索引

use h_odse;

show index on hxy;

8、刪除索引

drop index hxy_ind on h_odse.hxy;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM