hbase表映射Phoenix视图, 基于视图的二级索引是否实时更新
1. hbase shell
创建表
create 'MY_TABLE', 'CF1','CF2'
添加数据
put 'MY_TABLE','1' ,'CF1:V1', 'uwo1'
put 'MY_TABLE','1' ,'CF2:V2', '1'
put 'MY_TABLE','1' ,'CF1:V3', '10'
put 'MY_TABLE','2' ,'CF1:V1', 'uwo2'
put 'MY_TABLE','2' ,'CF2:V2', '2'
put 'MY_TABLE','2' ,'CF1:V3', '20'
查询hbase表数据
2. phoenix shell
创建视图, 视图名要和hbase表名一致
create view MY_TABLE (PK varchar primary key, CF1.V1 varchar, CF2.V2 varchar, CF1.V3 varchar);
创建二级索引
create index my_index2 on MY_TABLE(V1) include(v2);
查询视图
select * from MY_TABLE;
查询二级索引
select * from my_index2;
以上一切正常, 下面往hbase表中添加数据, 观察view和索引的情况
3. hbase shell
put 'MY_TABLE','3' ,'CF1:V1', 'uwo3'
put 'MY_TABLE','3' ,'CF2:V2', '3'
put 'MY_TABLE','3' ,'CF1:V3', '30'
put 'MY_TABLE','4' ,'CF1:V1', 'uwo4'
put 'MY_TABLE','4' ,'CF2:V2', '4'
put 'MY_TABLE','4' ,'CF1:V3', '40'
put 'MY_TABLE','6' ,'CF1:V1', 'uwo6'
put 'MY_TABLE','6' ,'CF2:V2', '6'
put 'MY_TABLE','6' ,'CF1:V3', '60'
查询hbase表
4. phoenix shell
查看视图
select * from MY_TABLE;
显示正常
查看索引
select * from my_index2;
可见, 索引并没有随着hbase表的更新而更新
结论
用视图view直接映射hbase表的时候, 并不能使用二级索引, 除非数据是永久的, 不会更新