文章目录
1、Introduction
- 低延时场景的OLAP
- 用户借助Phoenix,可以使用SQL语法来操作HBase
- Secondary Indexing加速查询
2、Deploy
1、下载(注意要对准HBase版本):http://phoenix.apache.org/
2、环境变量
# Phoenix
export PHOENIX_HOME=$B_HOME/phoenix
export PHOENIX_CLASSPATH=$PHOENIX_HOME
export PATH=$PATH:$PHOENIX_HOME/bin
3、解压
tar -zxvf phoenix-hbase-2.4-5.1.2-bin.tar.gz -C $B_HOME/
cd $B_HOME
mv phoenix-hbase-2.4-5.1.2-bin phoenix
ll
4、复制Phoenix的phoenix-server-hbase.jar到HBase的lib下
cp $PHOENIX_HOME/phoenix-server-hbase-2.4-5.1.2.jar $HBASE_HOME/lib/
5、分发上面的jar(也可以分发整个lib)
rsync.py $HBASE_HOME/lib
6、重启HBase
stop-hbase.sh
start-hbase.sh
3、Phoenix Shell
sqlline.py进入Phoenix Shell
$PHOENIX_HOME/bin/sqlline.py
查看所有表
!tables
建表(在Phoenix中,表名等会自动转大写,若要小写,就用双引号,如"student")
create table if not exists student(
id varchar primary key,
name varchar
);
HBase浏览器界面
16010可以看到
有则更新没则插入数据(update+insert)
upsert into student values('1001','Paladin');
upsert into student values('1001','Muradin');
upsert into student values('1002','Jaina');
HBase Shell 界面
查询
select * from student where id='1001';
删值
delete from student where id='1001';
select * from student;
Phoenix Shell 界面
删表
drop table student;
退出
!quit
4、Secondary Indexing
先看个例子(创个表,插些数据)
drop table if exists student;
create table student(
id varchar primary key,
name varchar,
age integer
)COLUMN_ENCODE_BYTES=0;
upsert into student values('1001','Paladin',5);
upsert into student values('1002','Muradin',6);
upsert into student values('1003','Jaina',5);
upsert into student values('1004','Jaina',6);
select * from student;
Explain Plan(执行计划)
explain select * from student;
explain select * from student where id='1001';
explain select * from student where id='1001' or age=5;
explain select * from student where id='1001' and age=5;
explain select * from student where name='Jaina';
如图示:用主键查询不用全表扫描,而用非主键查询要
由此引入Secondary Indexing来为name字段创建索引,加速where name='Jaina'查询
4.1、Configuration
编辑hbase-site.xml
vim $HBASE_HOME/conf/hbase-site.xml
<property>
<name>hbase.regionserver.wal.codec</name>
<value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value>
</property>
同步配置
rsync.py $HBASE_HOME/conf/hbase-site.xml
重启HBase
4.2、Global Indexes
适用场景:经常读
创建Global Indexes
create index student_name on student(name);
大概逻辑展示:
hbase shell可以看到多了个表STUDENT_NAME
查看执行计划
删除Global Indexes
drop index student_name on student;
4.3、Local Indexes
适用场景:经常写,空间有限
create local index student_name on student(name);
hbase shell可以看到STUDENT表里多了新数据
查看执行计划
删除Local Indexes
drop index student_name on student;
5、Appendix
| en | 🔉 | cn |
|---|---|---|
| phoenix | ˈfiːnɪks | n. 凤凰;死而复生的人 |
| secondary | ˈsekənderi | adj. 第二的;中等的;次要的;中级的;n. 副手;代理人 |
| parallel | ˈpærəlel | n. 平行线;vt. 使…与…平行;adj. 平行的 |
| chunk | tʃʌŋk | n. 厚块,大块; |








444



被折叠的 条评论
为什么被折叠?



