급여순위 4위 추출 쿼리 튜닝(RANK, INDEX HINT비교)
myemp1은
1000만건... SAL 칼럼은 인덱스 있음
-- 급여순위 4위 추출
1. RANK 분석함수 이용, 8초
SQL> set linesize 130 SQL> SELECT 급여순위, EMPNO,ENAME,SAL
2 FROM ( 3 SELECT EMPNO, ENAME, SAL, RANK() OVER(ORDER BY
SAL DESC) "급여순위" 4 FROM MYEMP1 5 ) 6
WHERE 급여순위=4;
Execution Plan
---------------------------------------------------------- Plan hash
value: 2012555084
-------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost
(%CPU)| Time |
-------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 10M| 867M| | 95812 (2)|
00:19:10 | |* 1 | VIEW | | 10M| 867M| |
95812 (2)| 00:19:10 | |* 2 | WINDOW SORT PUSHED RANK| | 10M|
247M| 345M| 95812 (2)| 00:19:10 | | 3 | TABLE ACCESS FULL | MYEMP1
| 10M| 247M| | 21377 (1)| 00:04:17 |
-------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 -
filter("급여순위"=4) 2 - filter(RANK() OVER ( ORDER BY
INTERNAL_FUNCTION("SAL") DESC )<=4)
2. INDEX_DESC 힌트이용, 0초
SQL> SELECT RNUM, EMPNO,ENAME,SAL 2 FROM ( 3
SELECT /*+ index_desc(myemp1 idx_myemp1_sal) */ 4
ROWNUM rnum, EMPNO, ENAME, SAL 5 FROM MYEMP1 6
WHERE SAL > 0 7 AND ROWNUM <= 4 8
) 9 WHERE rnum = 4;
Execution Plan
---------------------------------------------------------- Plan hash
value: 1328080881
-------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |
Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 364 | 7
(0)| 00:00:01 | |* 1 | VIEW | |
4 | 364 | 7 (0)| 00:00:01 | |* 2 | COUNT STOPKEY |
| | | | | | 3 | TABLE ACCESS
BY INDEX ROWID | MYEMP1 | 5 | 130 | 7 (0)| 00:00:01 | |* 4
| INDEX RANGE SCAN DESCENDING| IDX_MYEMP1_SAL | 10M| | 3 (0)|
00:00:01 |
-------------------------------------------------------------------------------------------------
|
댓글 없음:
댓글 쓰기