上云无忧 > 文档中心 > 天翼云云HBASE数据库-创建二级索引
云HBASE数据库
天翼云云HBASE数据库-创建二级索引

文档简介:
创建二级索引 功能简介 使用Phoenix创建二级索引。 示例代码 以下代码片段在cn.chinatelecom.hbase.sample.PhoenixSample.sampleCreateIndex方法中。
*产品来源:中国电信天翼云。免费试用 咨询热线:400-826-7010,为您提供专业的售前咨询,让您快速了解云产品,助您轻松上云! 微信咨询
  免费试用、价格特惠

创建二级索引


功能简介
使用Phoenix创建二级索引。

示例代码
以下代码片段在cn.chinatelecom.hbase.sample.PhoenixSample.sampleCreateIndex方法中。
    /**
     * Create Index
     */
    public static boolean sampleCreateIndex(Configuration conf) {
        log.info("Entering sampleCreateIndex.");
        int result = -1;
        //default assume zookeeper is stand-alone, and phoenix query server is same as zookeeper
        String url = "jdbc:phoenix:thin:url=http://" + conf.get("hbase.zookeeper.quorum") + ":" +
                conf.get("phoenix.queryserver.http.port", "8765") +
                ";serialization=" + conf.get("phoenix.queryserver.serialization", "PROTOBUF");
        String sql = "CREATE INDEX IF NOT EXISTS IDX_PHOENIX_SAMPLE_AGE ON PHOENIX_SAMPLE (age)";
        try (Connection conn = DriverManager.getConnection(url); Statement stat = conn.createStatement()) {
            result = stat.executeUpdate(sql);
            log.info("Create index successfully.");
        } catch (Exception e) {
            log.error("Create index failed.", e);
        }
        log.info("Exiting sampleCreateIndex.");
        return result >= 0;
}
注意事项
需要先创建Phoenix表再创建二级索引。
二级索引包含全局索引和本地索引两大类,又有函数索引、覆盖索引和联合索引等多种实现。本样例仅展示创建二级索引的基本代码结构,不同索引SQL语法上的差异请查阅Phoenix官方文档。

相似文档
  • 删除索引 功能简介 使用Phoenix删除二级索引。 示例代码 以下代码片段在cn.chinatelecom.hbase.sample.PhoenixSample.sampleDropIndex方法中。 /** * Drop Index */ public static boolean sampleDropIndex(Configuration conf) {
  • 二级索引查询 功能简介 针对添加了二级索引的用户表,其数据查询性能高于针对无二级索引用户表的数据查询。 样例:使用二级索引查找数据 以下代码片段在cn.chinatelecom.hbase.sample包的“PhoenixSample”类的
  • 写MOB表 功能介绍 HBase MOB数据读出与普通HBase数据的读出没有什么区别,对客户来说是透明的。 为了使用HBase MOB功能需要在web控制台配置管理添加HBase MOB相关的配置项
  • Region 预分区 功能简介 本例使用多点分割将HBase表按照“-∞~A”、“A~C”、“C~G”、 “G~I”、“I~+∞”分为五个Region。 以下代码片段在cn.chinatelecom.hbase.sample包的“MOBSample”类的 createTableBySplitKeys方法中。
  • Q:云HBASE适用什么场景? A:云HBASE是基于开源 HBase引擎支持NOSQL和二级索引,提供高性能、低延迟、易运营实时分析云服务,适合上百TB,百万级QPS的分布式计算应用场景。单节点定位开发和测试场景, 集群版定位于企业生产。
官方微信
联系客服
400-826-7010
7x24小时客服热线
分享
  • QQ好友
  • QQ空间
  • 微信
  • 微博
返回顶部