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] |
+-----------------+
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
「함수형으로 데이터 사이언스 #2」로 넘어간 부분7/30 에 가입했습니다. 의 함수형으로 데이터 과학을 #1에서 구현해 갔습니다. 순조롭게 진행되고 있었습니다만, 의 정규화로 에러가 나와 버렸습니다. 모쿠모쿠 모임에서 해결할 수 없었기 때문에 다시 살펴 보았습니다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.