hive 创建索引

hive索引

索引是hive0.7之后才有的功能,创建索引需要评估其合理性,因为创建索引也是要磁盘空间,维护起来也是需要代价的

创建索引

create index idx_user_phone on table user_phone_with_phone_message(user_phone)
as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler'
with deferred rebuild
IN TABLE idx_user_phone_with_phone_message;
idx_user_phone: 索引名字
user_phone_with_phone_message:要创建索引的原始表
user_phone:索引字段
idx_user_phone_with_phone_message:创建索引后的表
org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler :创建索引需要的实现类

加载索引数据

alter index idx_user_phone on user_phone_with_phone_message rebuild;
idx_user_phone:创建索引后的表
user_phone_with_phone_message:要创建索引的原始表

查看索引表中数据

select * from  idx_user_phone_with_phone_message;

删除索引

drop index idx_user_phone on  user_phone_with_phone_message;

查看索引

show index on user_phone_with_phone_message

参考

创建索引

posted @ 2019-11-28 15:34  sowhat1412  阅读(273)  评论(0)    收藏  举报