(3)Phoenix建立Hbase二级索引


文章目录


3.1 配置Hbase支持Phoenix建立二级索引
3.1.1 添加以下配置到Hbase的Hregionserver节点的hbase-site.xmlhtml


<!-- phoenix regionserver 配置参数 --><property><name>hbase.regionserver.wal.codec</name><value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value></property><property><name>hbase.region.server.rpc.scheduler.factory.class</name><value>org.apache.hadoop.hbase.ipc.PhoenixRpcSchedulerFactory</value><description>Factory to create the Phoenix RPC Scheduler that uses separate queues for index and metadata updates</description></property><property><name>hbase.rpc.controllerfactory.class</name><value>org.apache.hadoop.hbase.ipc.controller.ServerRpcControllerFactory</value><description>Factory to create the Phoenix RPC Scheduler that uses separate queues for index and metadata updates</description></property>

添加以下配置到Hbase中Hmaster节点的hbase-site.xml中apache

<!-- phoenix master 配置参数 --><property><name>hbase.master.loadbalancer.class</name><value>org.apache.phoenix.hbase.index.balancer.IndexLoadBalancer</value></property><property><name>hbase.coprocessor.master.classes</name><value>org.apache.phoenix.hbase.index.master.IndexMasterObserver</value></property>

对于cdh配置,须要配置hbase-site.xml高级代码段客户端配置增长如下段,支持hbase的命名空间服务器

<property>
  <name>phoenix.schema.isNamespaceMappingEnabled</name>
  <value>true</value></property><property>
  <name>phoenix.schema.mapSystemTablesToNamespace</name>
  <value>true</value></property>

3.1.3 验证效果:app

3.2 建立索引
3.2.1 phoenix的索引分类
1)global index是默认的索引格式。适用于多读少写的业务场景。写数据的时候会消耗大量开销,由于索引表也要更新,而索引表是分布在不一样的数据节点上的,跨节点的数据传输带来了较大的性能消耗。在读数据的时候Phoenix会选择索引表来下降查询消耗的时间。若是想查询的字段不是索引字段的话索引表不会被使用,也就是说不会带来查询速度的提高。分布式

CREATE INDEX my_index ON my_table (my_col)

在这里插入图片描述
2)Local index适用于写操做频繁的场景。索引数据和数据表的数据是存放在相同的服务器中的,避免了在写操做的时候往不一样服务器的索引表中写索引带来的额外开销。查询的字段不是索引字段索引表也会被使用,这会带来查询速度的提高。
创建local index可能出现的问题
hbase-site.xml的zookeeeper的配置信息不能加2181,不然在建立local index的时候
在这里插入图片描述
正常配置:

hbase.zookeeper.quorum
hadoop101,hadoop102,hadoop103

Local index 和 Global index区别:ide

Local index 和 Global index区别:
Local index 因为是数据与索引在同一服务器上,因此要查询的数据在哪台服务器的哪一个region是没法定位的,只能先找到region而后在利用索引。
Global index 是一种分布式索引,能够直接利用索引定位服务器和region,速度更快,可是因为分布式的缘由,数据一旦出现新增变化,分布式的索引要进行跨服务的同步操做,带来大量的通讯消耗。因此在写操做频繁的字段上不适合创建Global index。oop

三种提高效率查询方式
1) CREATE INDEX my_index ON my_table (v1) INCLUDE (v2)
2) SELECT /*+ INDEX(my_table my_index) */ v2 FROM my_table WHERE v1 = ‘foo’
3) CREATE LOCAL INDEX my_index ON my_table (v1)
如何删除索引
DROP INDEX my_index ON my_table性能

相关文章
相关标签/搜索