hive 索引

hive 有限的支持索引,不支持主键外键,可以对表添加索引,也可以为某个分区添加索引.维护索引也要额外的存储空间和计算资源。

创建索引需要指定索引处理器 如 as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler'

in table 用于指定索引存放的表

hive> create index ix_accid on table account(accid)  as 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' with deferred rebuild in table account_ix_accid;
OK
Time taken: 0.458 seconds

hive> show tables like 'acc.*';
OK
tab_name
account
account_ix_accid
Time taken: 0.102 seconds, Fetched: 2 row(s)

如果指定了deferred rebuild,那么新建的索引就是空的

hive> select * from account_ix_accid;
OK
Time taken: 0.478 seconds

重建索引,加载索引数据

hive> alter index ix_accid on account rebuild;

查看索引

hive> show index on account;
OK
ix_accid                account                 accid                   account_ix_accid        compact            
Time taken: 0.102 seconds, Fetched: 1 row(s)

删除索引

hive> drop index if exists ix_accid on account;
OK
Time taken: 3.448 seconds

原文地址:https://www.cnblogs.com/playforever/p/9667440.html