-- 테이블 생성
CREATE TABLE ROWNUM_T1 AS
SELECT LEVEL AS C1, CHR(65+MOD(LEVEL,26)) AS c2
FROM DUAL CONNECT BY LEVEL <= 500000 ;
-- 인덱스 생성
CREATE INDEX IDX_01 ON ROWNUM_T1 ( C2, C1 ) ;
-- SQL(1)
SELECT /*+ INDEX_DESC(T1 IDX_01) */
c1
FROM ROWNUM_T1 t1
WHERE t1.c2 = 'A'
AND t1.c1 >= 0
ABD ROWNUM <= 1;
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 16 | 3 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
|* 2 | INDEX RANGE SCAN DESCENDING| IDX_01 | 23112 | 361K| 3 (0)| 00:00:01 |
---------------------------------------------------------------------------------------
-- SQL(2)
SELECT c1
FROM (SELECT /*+ INDEX_DESC(T1 IDX_01) */
c1
FROM ROWNUM_T1 t1
WHERE t1.c2 = 'A'
AND t1.c1 >= 0
ORDER BY c2 DESC, c1 DESC
)
WHERE ROWNUM <= 1;
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 13 | 3 (0)| 00:00:01 |
|* 1 | COUNT STOPKEY | | | | | |
| 2 | VIEW | | 23112 | 293K| 3 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN DESCENDING| IDX_01 | 23112 | 361K| 3 (0)| 00:00:01 |
----------------------------------------------------------------------------------------
-- SQL(3)
SELECT MAX(c1) AS c1
FROM ROWNUM_T1 t1
WHERE t1.c2 = 'A'
AND t1.c1 >= 0;
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 16 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 16 | | |
| 2 | FIRST ROW | | 1 | 16 | 3 (0)| 00:00:01 |
|* 3 | INDEX RANGE SCAN (MIN/MAX)| IDX_01 | 1 | 16 | 3 (0)| 00:00:01 |
---------------------------------------------------------------------------------------
- 강좌 URL : http://www.gurubee.net/lecture/3827
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.