hive数据库的索引解析

22 篇文章 0 订阅
17 篇文章 0 订阅

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;
    

总结:以上就是与索引相关的操作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值