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
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步