分享

HIVE Indexex 索引

本帖最后由 nettman 于 2014-7-18 21:31 编辑
问题导读

1、Hive可以创建哪些索引?
2、Hive如何创建分区索引、唯一性索引?



Creating an Index -- 创建一个索引
[sql]
  1. CREATE TABLE employees (  
  2.   name         STRING,  
  3.   salary       FLOAT,  
  4.   subordinates ARRAY<STRING>,  
  5.   deductions   MAP<STRING, FLOAT>,  
  6.   address      STRUCT<street:STRING, city:STRING, state:STRING, zip:INT>  
  7. )  
  8. PARTITIONED BY (country STRING, state STRING);
复制代码


Let’s index on the country partition only:(让我们唯一分区索引)
[sql]
  1. CREATE INDEX employees_index  
  2. ON TABLE employees (country)  
  3. AS 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler'  
  4. WITH DEFERRED REBUILD  
  5. IDXPROPERTIES ('creator = 'me', 'created_at' = 'some_time')  
  6. IN TABLE employees_index_table  
  7. PARTITIONED BY (country, name)  
  8. COMMENT 'Employees indexed by country and name.';  
复制代码

Bitmap Indexes
Hive v0.8.0 adds a built-in bitmap index handler. Bitmap indexes are commonly used
for columns with few distinct values. Here is our previous example rewritten to use the
bitmap index handler:
(Hive 0.8.0添加了一个内置的位图索引处理程序。位图索引是常用的具有几个不同值的列。这是我们的前一个例子重写使用,位图索引处理程序:)
[sql]
  1. CREATE INDEX employees_index  
  2. ON TABLE employees (country)  
  3. AS 'BITMAP'  
  4. WITH DEFERRED REBUILD  
  5. IDXPROPERTIES ('creator = 'me', 'created_at' = 'some_time')  
  6. IN TABLE employees_index_table  
  7. PARTITIONED BY (country, name)  
  8. COMMENT 'Employees indexed by country and name.';
复制代码


Rebuilding the Index
(重建索引)
[sql]
  1. ALTER INDEX employees_index  
  2. ON TABLE employees  
  3. PARTITION (country = 'US')  
  4. REBUILD;  
复制代码


Showing an Index
(查看索引)
[sql]
  1. SHOW FORMATTED INDEX ON employees;  
复制代码


Dropping an Index
(删除索引)
[sql]
  1. DROP INDEX IF EXISTS employees_index ON TABLE employees;
复制代码







已有(3)人评论

跳转到指定楼层
june_fu 发表于 2015-3-11 23:26:08
IN TABLE employees_index_table    这句是表达啥意思呢?
回复

使用道具 举报

77925978 发表于 2017-7-28 09:56:53
内置的位图索引处理程序
回复

使用道具 举报

a530491093 发表于 2018-12-5 15:52:52
创建索引有什么意义呢?对性能没影响吧
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条