- HBase通过rowkey来查询,否则就必须逐行地比较每一列的值,即全表扫瞄
- 数据量较大的表,全表扫描的性能很差
- 如果需要从多个角度查询数据,不可能使用 rowkey 来实现查询。此时可使用secondary index(二级索引)来完成这件事
- Phoenix提供了对HBase secondary index的支持
配置HBase支持Phoenix二级索引
- 1、在每一个 HRegionServce的 hbase-site.xml 加入以下属性
<property>
<name>hbase.regionserver.wal.codec</name>
<value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value>
</property>
使用Phoenix创建二级索引
create local index "idx_tel" on "employee"("family"."tel");
explain select * from "employee" where "name" = 'ted';
explain select * from "employee" where "tel" = '13600912345';
drop index "idx_tel" on "employee";
!indexes "employee"