HBase 用phoenix创建二级索引

 

配置HBase支持Phoenix二级索引

 

<property> 
  <name>hbase.regionserver.wal.codec</name> 
  <value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value> 
</property>
 
image

 

网上说要配置很多,但我测试下来配置这2 个就可以了。

 

 

测试:

 

--hbase table:

 
create 'ncallrecords',{NAME => 'call', VERSIONS => 1, DATA_BLOCK_ENCODING => 'PREFIX_TREE',BLOOMFILTER=>'ROW',BLOCKCACHE=>true}, {SPLITS => ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']}

 

 

--phoenix table

 

create table "ncallrecords"(
"pk" varchar primary key,
"call"."user_id" varchar,
"call"."calltime" varchar,
"call"."duration" varchar,
"call"."phone" varchar,
"call"."name" varchar,
"call"."querytime" varchar
);

--创建2级索引
create index USERS_TEST_IDX0 on "ncallrecords"("call"."querytime");

 

--索引测试
explain select "pk","querytime" from "ncallrecords" where "querytime"='0';
select count(*) from "ncallrecords" where "querytime"='0';
--先查rowkey,在关联查询,这样才用到了索引。
select * from "ncallrecords" where "pk" in (select "pk" from "ncallrecords" where "querytime"='1487904241000');

 

说明 : 可以通过explain命令来查看查询是否用到二级索引

注意:查询的字段必须是rowkey或者索引,只是在where条件里用索引是没有用的

 

 

image

 

 

参考  https://blog.csdn.net/lifuxiangcaohui/article/details/55518390

您可以选择一种方式赞助本站