• Phoenix创建Hbase二级索引_尚硅谷大数据培训


    配置Hbase支持Phoenix创建二级索引

    1 添加如下配置到Hbase的Hregionserver节点的hbase-site.xml

    hbase.regionserver.wal.codec

    org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec

    hbase.region.server.rpc.scheduler.factory.class

    org.apache.hadoop.hbase.ipc.PhoenixRpcSchedulerFactory

    Factory to create the Phoenix RPC Scheduler that uses separate queues for index and metadata updates

    hbase.rpc.controllerfactory.class

    org.apache.hadoop.hbase.ipc.controller.ServerRpcControllerFactory

    Factory to create the Phoenix RPC Scheduler that uses separate queues for index and metadata updates

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

    hbase.master.loadbalancer.class

    org.apache.phoenix.hbase.index.balancer.IndexLoadBalancer

    hbase.coprocessor.master.classes

    org.apache.phoenix.hbase.index.master.IndexMasterObserver

    3 常见问题汇总:

    1)注意:网上配置文档里有这一条,但在实际测试中(测试环境hbase-1.3.1,网上0.98.6),加入该条的regionserver会在hbase启动时失败,对应节点上没有HregionServer进程,去掉该配置后正常启动,且能正常创建local index。

    hbase.coprocessor.regionserver.classes

    org.apache.hadoop.hbase.regionserver.LocalIndexMerger

    2hbase-site.xml的zookeeeper的配置信息不能加2181,否则在创建local index的时候会报以下异常:

    正常配置:

            hbase.zookeeper.quorum

            hadoop101,hadoop102,hadoop103

    创建索引

    1 phoenix的索引分类

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

    CREATE INDEX my_index ON my_table (my_index)

    2)Local index适用于写操作频繁的场景。索引数据和数据表的数据是存放在相同的服务器中的,避免了在写操作的时候往不同服务器的索引表中写索引带来的额外开销。查询的字段不是索引字段索引表也会被使用,这会带来查询速度的提升。

    CREATE LOCAL INDEX my_index ON my_table (my_index)

    2 三种提升效率查询方式

    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)

    3 如何删除索引

    DROP INDEX my_index ON my_table

     

  • 相关阅读:
    24、Spring5
    【iOS开发-AFNetWorking下的POST和GET】
    第二章第二节:字符串 索引和切片
    mysql请求阻塞
    【Linux】安装Hbase
    ctfshow-nodejs
    【YOLOv5】手把手教你使用LabVIEW ONNX Runtime部署 TensorRT加速,实现YOLOv5实时物体识别(含源码)
    LaTeX 调整行距、列宽,以及表格的整体大小和字体大小
    IDEA自定义代码快捷指令
    怎样用读写锁快速实现一个缓存?
  • 原文地址:https://blog.csdn.net/zjjcchina/article/details/125890772