hive也是支持索引的使用,但是如果表中已經有數據的情況下,創建索引的過程不是特別快。
已經擁有表:
create table if not exists llcfpd_withgroupbykey(groupbykey string,lrp string,timestamp string,objid string,uid string)
row format delimited fields terminated by ',' stored as textfile;
創建索引:
create index idx_llcfpd_withgroupbykey on table llcfpd_withgroupbykey(groupbykey) as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' with deferred rebuild IN TABLE llcfpd_withgroupbykey_idx;
備注:需要注意這里邊創建索引實際上是插入了特定的數據到一個表。
原表更新數據:
ALTER INDEX idx_llcfpd_withgroupbykey on llcfpd_withgroupbykey REBUILD;
備注:當表中已經擁有數據的情況下,必須執行該語句,否則索引沒有起到效果。
刪除索引:
DROP INDEX idx_llcfpd_withgroupbykey on llcfpd_withgroupbykey;
查看索引:
SHOW INDEX on llcfpd_withgroupbykey;