phoenix 정렬 최적화,order by

7691 단어 Phoenix
0: jdbc:phoenix:192.168.199.154> select email from T_EXTENSION_ALL_DATAS_LOGIN where login_date='2018-11-24' order by email desc limit 1;
+-----------------+
|      EMAIL      |
+-----------------+
| [email protected]  |
+-----------------+
1 row selected (0.018 seconds)



0: jdbc:phoenix:192.168.199.154> explain select email from T_EXTENSION_ALL_DATAS_LOGIN where login_date='2018-11-24' order by email desc limit 1;
+------------------------------------------------------------------------------------------------------------------+-----------------+----------------+--------------+
|                                                       PLAN                                                       | EST_BYTES_READ  | EST_ROWS_READ  | EST_INFO_TS  |
+------------------------------------------------------------------------------------------------------------------+-----------------+----------------+--------------+
| CLIENT 1-CHUNK 1 ROWS 634 BYTES SERIAL 1-WAY REVERSE RANGE SCAN OVER T_EXTENSION_ALL_DATAS_LOGIN ['2018-11-24']  | 634             | 1              | 0            |
|     SERVER FILTER BY FIRST KEY ONLY                                                                              | 634             | 1              | 0            |
|     SERVER 1 ROW LIMIT                                                                                           | 634             | 1              | 0            |
| CLIENT 1 ROW LIMIT                                                                                               | 634             | 1              | 0            |
+------------------------------------------------------------------------------------------------------------------+-----------------+----------------+--------------+
4 rows selected (0.022 seconds)

역순으로 정렬하기: SERVER FILTER BY FIRST KEY ONLY, 곧 시작됩니다.
왜냐하면 이 시계의 로우키는,login_date + email, 따라서login_날짜 조건, 게다가 이메일 정렬은 매우 빠르다.
 
 
예를 들어 나는 시간 필드에 따라 역순으로 정렬하고 싶은데, 어떻게 처리합니까?
select login_date,email,created_date from T_EXTENSION_ALL_DATAS_LOGIN where login_date='2018-11-24' and country='China' order by created_date desc limit 1;

실행 결과:
Error: org.apache.phoenix.exception.PhoenixIOException: org.apache.hadoop.hbase.DoNotRetryIOException: T_EXTENSION_ALL_DATAS_LOGIN,,1543044197700.fcde65017c2514f6502514900dba5fe2.: null     at org.apache.phoenix.util.ServerUtil.createIOException(ServerUtil.java:114)     at org.apache.phoenix.util.ServerUtil.throwIOException(ServerUtil.java:80)     at org.apache.phoenix.iterate.RegionScannerFactory$1.nextRaw(RegionScannerFactory.java:213)     at org.apache.phoenix.iterate.RegionScannerResultIterator.next(RegionScannerResultIterator.java:61)     at org.apache.phoenix.iterate.OrderedResultIterator.getResultIterator(OrderedResultIterator.java:255)     at org.apache.phoenix.iterate.OrderedResultIterator.next(OrderedResultIterator.java:199)     at org.apache.phoenix.iterate.NonAggregateRegionScannerFactory.getTopNScanner(NonAggregateRegionScannerFactory.java:322)     at org.apache.phoenix.iterate.NonAggregateRegionScannerFactory.getRegionScanner(NonAggregateRegionScannerFactory.java:168)     at org.apache.phoenix.coprocessor.ScanRegionObserver.doPostScannerOpen(ScanRegionObserver.java:81)     at org.apache.phoenix.coprocessor.BaseScannerRegionObserver$RegionScannerHolder.overrideDelegate(BaseScannerRegionObserver.java:225)     at org.apache.phoenix.coprocessor.BaseScannerRegionObserver$RegionScannerHolder.nextRaw(BaseScannerRegionObserver.java:273)     at org.apache.hadoop.hbase.regionserver.RSRpcServices.scan(RSRpcServices.java:3119)     at org.apache.hadoop.hbase.regionserver.RSRpcServices.scan(RSRpcServices.java:3356)     at org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos$ClientService$2.callBlockingMethod(ClientProtos.java:42002)     at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:409)     at org.apache.hadoop.hbase.ipc.CallRunner.run(CallRunner.java:130)     at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:324)     at org.apache.hadoop.hbase.ipc.RpcExecutor$Handler.run(RpcExecutor.java:304) Caused by: java.lang.NullPointerException     at org.apache.phoenix.execute.TupleProjector.projectResults(TupleProjector.java:282)     at org.apache.phoenix.iterate.RegionScannerFactory$1.nextRaw(RegionScannerFactory.java:203)     ... 15 more (state=08000,code=101)
 
우리는 그를 위해 정렬된 색인을 만들 것이다.
CREATE INDEX IDX_T_EXTENSION_ALL_DATAS_LOGIN_DATE_COUNTRY_CREATED ON T_EXTENSION_ALL_DATAS_LOGIN(LOGIN_DATE,COUNTRY,CREATED_DATE DESC);

 
0: jdbc:phoenix:192.168.199.154> select login_date,email,created_date from T_EXTENSION_ALL_DATAS_LOGIN where login_date='2018-11-24' and country='China' order by created_date desc limit 1;
+-------------+-----------------+----------------------+
| LOGIN_DATE  |      EMAIL      |     CREATED_DATE     |
+-------------+-----------------+----------------------+
| 2018-11-24  | [email protected]  | 2018-11-24 15:26:57  |
+-------------+-----------------+----------------------+
1 row selected (0.032 seconds)



0: jdbc:phoenix:192.168.199.154> explain select login_date,email,created_date from T_EXTENSION_ALL_DATAS_LOGIN where login_date='2018-11-24' and country='China' order by created_date desc limit 1;
+------------------------------------------------------------------------------------------------------------------------------------------+-----------------+----------------+--------------+
|                                                                   PLAN                                                                   | EST_BYTES_READ  | EST_ROWS_READ  | EST_INFO_TS  |
+------------------------------------------------------------------------------------------------------------------------------------------+-----------------+----------------+--------------+
| CLIENT 1-CHUNK 1 ROWS 65 BYTES SERIAL 1-WAY RANGE SCAN OVER IDX_T_EXTENSION_ALL_DATAS_LOGIN_DATE_COUNTRY_CREATED ['2018-11-24','China']  | 65              | 1              | 0            |
|     SERVER FILTER BY FIRST KEY ONLY                                                                                                      | 65              | 1              | 0            |
|     SERVER 1 ROW LIMIT                                                                                                                   | 65              | 1              | 0            |
| CLIENT 1 ROW LIMIT                                                                                                                       | 65              | 1              | 0            |
+------------------------------------------------------------------------------------------------------------------------------------------+-----------------+----------------+--------------+
4 rows selected (0.018 seconds)

정렬된 인덱스를 만든 후에도 First Key Only로 SERVER FILTER BY FIRST KEY ONLY를 사용하면 속도가 빠릅니다~
 
참고:
order by 필드desc limit 10;
orderby 필드는 숫자나 시간을 요구해야 합니다.
0: jdbc:phoenix:192.168.199.154> select email from T_EXTENSION_ALL_DATAS_LOGIN where login_date='2018-11-24' order by email asc limit 10;
+-----------------+
|      EMAIL      |
+-----------------+
| [email protected]       |
| [email protected]      |
| [email protected]     |
| [email protected]    |
| [email protected]   |
| [email protected]  |
| [email protected]  |
| [email protected]  |
| [email protected]  |
| [email protected]  |
+-----------------+

 
 
 
 

좋은 웹페이지 즐겨찾기