关于hbase二级索引的描述 hbase的二级索引应用( 三 )


+------------+--------------+--------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----------------+-------------------+--------+| TABLE_CAT | TABLE_SCHEM | TABLE_NAME | COLUMN_NAME | DATA_TYPE | TYPE_NAME | COLUMN_SIZE | BUFFER_LENGTH | DECIMAL_DIGITS | NUM_PREC_RADIX | ABLE | REMARKS | COLUMN_DEF | SQL_DATA_TYPE | SQL_DATETIME_SUB | CHAR_O |
+------------+--------------+--------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----------------+-------------------+--------+
| | ns1000 | operate_log | pk | 12 | VARCHAR | | | | | 0 | | | | | |
| | ns1000 | operate_log | appVersion | 12 | VARCHAR | | | | | 1 | | | | | |
| | ns1000 | operate_log | city | 12 | VARCHAR | | | | | 1 | | | | | |
| | ns1000 | operate_log | lat | 12 | VARCHAR | | | | | 1 | | | | | |
| | ns1000 | operate_log | lon | 12 | VARCHAR | | | | | 1 | | | | | |
| | ns1000 | operate_log | memberType | 12 | VARCHAR | | | | | 1 | | | | | |
| | ns1000 | operate_log | time | 12 | VARCHAR | | | | | 1 | | | | | |
+------------+--------------+--------------+--------------+------------+------------+--------------+----------------+-----------------+-----------------+-----------+----------+-------------+----------------+-------------------+--------+0: jdbc:phoenix:> select * from "operate_log" limit 1;
+------------------------+-------------+-------+---------------------+---------------------+-------------+----------------+| pk | appVersion | city | lat | lon | memberType | time |
+------------------------+-------------+-------+---------------------+---------------------+-------------+----------------+1538216707720 | 2.22.0 | 重庆市 | 29.577587127685547 | 106.50493621826172 | 0 | 1538216707720 |
+------------------------+-------------+-------+---------------------+---------------------+-------------+----------------+
1 row selected (0.115 seconds)
0: jdbc:phoenix:> select count(*) from "operate_log";
+-----------+
| COUNT(1) |
+-----------+
| 2799827 |
+-----------+
1 row selected (3.848 seconds)(可左右滑动)
4. 根据字段 time 进行时间范围查询:0: jdbc:phoenix:> select count(*) from "operate_log" where "f"."time" between '1538216707720' and '1538223834000';
+-----------+
| COUNT(1) |
+-----------+
| 5883 |
+-----------+
1 row selected (5.241 seconds)
(可左右滑动)
这种情况下,基本上查询都在 5s 左右 。这里还要有两点说明:

  • Phoenix 会自动将表名、字段名都转成大写,如果要区分大小写使用双引号括起来即可 。
  • 这里我们创建的是视图,相当于外部表,也可以 create table 创建表,视图的特点是删除时不会删除 HBase 表,但是视图创建的二级索引不会自动更新,如果要实时更新的话,只能使用 create table,然后通过 Phoenix jdbc 的方式写入数据,只有通过 Phoenix 写,然后用 Phoenix 实现的协处理器才能实现实时更新的索引 。
使用 Phoenix 创建二级索引1. 使用 Phoenix 对 time 字段创建索引0: jdbc:phoenix:> create index index_operate_log_time on "operate_log" ("f"."time");
2,799,827 rows affected (95.814 seconds)
(可左右滑动)
2. 再次根据 time 字段做范围查询
00: jdbc:phoenix:> select count(*) from "operate_log" where "f"."time" between '1538216707720' and '1538223834000';
+-----------+
| COUNT(1) |
+-----------+
| 5883 |
+-----------+
1 row selected (0.049 seconds)
(可左右滑动)
这里基本上查询都在 50 ms 左右 。这就是通过 Phoenix 的二级索引带来的性能提升 。
Phoenix 索引类型介绍Phoenix 提供了多种索引类型,包括覆盖索引、函数索引,以及全局索引与本地索引等,具体介绍如下 。


以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!

「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助: