hive数据库的索引
简要描述
- 注意:索引是数据库的标配技术,hive从0.7以后才开始支持索引。
- 索引的特点:索引文件本身有序,索引文件较小。
索引的优缺点
- hive索引的优点:避免全表扫描或者减少扫描的数量,提高查询效率。
- hive索引的缺点:将会有冗余存储:加载数据耗时。
创建索引
-
先创建表:
create table if not exists idx( id bigint, number bigint, name string ) row format delimited fields terminated by '\t' ;
-
加载数据
load data local inpath '/localpath/file' into table idx;
-
创建索引:名称的结构式:(idx_表名称_列名称)
create index idx_idx_id on table idx(id) as 'compact' with deferred rebuild ;
-
创建联合索引:名称的结构式:(idx_表名称_列1名称_列2名称)
create index idx_idx_id_number on table idx(id,dt) as 'compact' with deferred rebuild ;
-
修改索引:(相当于重建索引,不可以修改索引的名字??尝试是否可以修改)
alter index idx_idx_number on idx rebuild ;
-
显示索引:
show index on 表名;
-
删除索引:
drop index idx_idx_number on idx;