Caused by: org.apache.hadoop.hbase.ipc.RemoteWithExtrasException(org.apache.hadoop.hbase.DoNotRetryIOException): org.apache.hadoop.hbase.DoNotRetryIOException: Error when adding cache: : java.sql.SQLException: ERROR 999 (50M01): Unable to allocate enough memory. Requested memory of 122633169 bytes is larger than global pool of 69343641 bytes.
at org.apache.phoenix.util.ServerUtil.createIOException(ServerUtil.java:114)
出现这个错误的sql:
select t1.seq_id from T_EXTENSION_ALL_DATAS_SHOW t1 where t1.show_date='2018-11-24' and exists(
select 1 from T_EXTENSION_ALL_DATAS_LOGIN t2
where t2.login_date='2018-11-24' and t2.country='China' and t1.email=t2.email
) limit 2;
0: jdbc:phoenix:192.168.199.154> select count(1) from T_EXTENSION_ALL_DATAS_LOGIN where login_date='2018-11-24' and country='China';
+-----------+
| COUNT(1) |
+-----------+
| 500000 |
+-----------+
子查询内容过多,数据大概是50W,内存不足。所以报错了。
解决方法是:
hbase的conf目录,hbase-site.xml增加配置:
<property>
<name>phoenix.query.maxGlobalMemoryPercentage</name>
<value>30</value>
</property>
默认是15,百分比。
phoenix 详细的configuration配置,详见官网:
https://phoenix.apache.org/tuning.html#
我觉得增加这种配置,意义不是很大:
0: jdbc:phoenix:192.168.199.154> select t1.seq_id from T_EXTENSION_ALL_DATAS_SHOW t1 where t1.show_date='2018-11-24' and exists(
. . . . . . . . . . . . . . . .> select 1 from T_EXTENSION_ALL_DATAS_LOGIN t2
. . . . . . . . . . . . . . . .> where t2.login_date='2018-11-24' and t2.country='China' and t1.email=t2.email
. . . . . . . . . . . . . . . .> ) limit 2;
+------------+
| T1.SEQ_ID |
+------------+
| 500000 |
| 639317 |
+------------+
2 rows selected (21.67 seconds)
当查询的结果集过大时,比如 in、exists、inner join 等操作都是会出现内存不足情况,就算是内存够了。
速度也太慢,不适合与页面做任何交互操作。
结论:
两个结果集过大的表,做inner join操作。where条件过滤后,结果集分别是100W,50W。
走二级索引,也快不起来的。速度是慢在关联上面。
phoenix表关联查询,要避免两个大结果集关联的情况。它更适合大表与小表的join。比如官方的5000万、1000条。
或者通过条件制造,大、小表的join查询。
补充:两个结果集都很大的表,关联。还可以使用 /*+ USE_SORT_MERGE_JOIN */ 处理。