SELECT *
FROM (
SELECT ROWNUM rnum ,
x.*
FROM (
SELECT * FROM ...
ORDER BY ...
) x
WHERE ROWNUM <= :b2
)
WHERE rnum >= :b1 ;
SELECT *
FROM (
SELECT ROWNUM rnum ,
x.*
FROM (
SELECT * FROM ...
ORDER BY ...
) x
)
WHERE rnum >= :b1 AND rnum <= :b2 ;
SELECT *
FROM (
SELECT ROWNUM rnum ,
x.*
FROM (
SELECT * FROM ...
ORDER BY ...
) x
)
WHERE rnum BETWEEN :b1 AND :b2 ;
DROP TABLE T1 PURGE;
< T1 >
> 생성 요건
- 테이블 데이터 건수는 1,000,000 Rows
- 컬럼 c1 은 값의 종류가 1,000,000 가지 즉, unique 성
> 테이블 생성
CREATE TABLE t1
AS
SELECT 1000000-(LEVEL-1) c1, TO_CHAR(SYSDATE-(LEVEL-1),'yyyymmdd') c2, LEVEL c3
FROM DUAL
CONNECT BY LEVEL <= 1000000 ;
> 각 컬럼에 인덱스 생성 및 통계정보 수집
CREATE INDEX idx_t1_01 ON t1(c2,c1);
BEGIN
dbms_stats.gather_table_stats(OWNNAME=>'SCOTT',
TABNAME=>'T1',
ESTIMATE_PERCENT=>99,
METHOD_OPT=>'FOR ALL INDEXED COLUMNS',
GRANULARITY=>'ALL', CASCADE=>TRUE,
NO_INVALIDATE=>FALSE) ;
END;
/
SELECT *
FROM t1
WHERE c2 <= TO_CHAR(SYSDATE,'yyyymmdd')
ORDER BY c2 DESC, c1 DESC ;
SELECT *
FROM (
SELECT ROWNUM rnum,
x.*
FROM (
SELECT *
FROM t1
WHERE c2 <= TO_CHAR(SYSDATE,'yyyymmdd'
)
ORDER BY c2 DESC, c1 DESC
) x
)
WHERE rnum >= :b1 AND rnum <= :b2 ;
call cou cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.01 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 5 0.76 0.77 0 535987 0 50
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 7 0.78 0.77 0 535987 0 50
Rows Row Source Operation
------- ---------------------------------------------------
50 FILTER (cr=535987 pr=0 pw=0 time=50 us)
50 VIEW (cr=535987 pr=0 pw=0 time=48 us)
1000000 COUNT (cr=535987 pr=0 pw=0 time=44 us)
1000000 VIEW (cr=535987 pr=0 pw=0 time=42 us)
1000000 TABLE ACCESS BY INDEX ROWID T1 (cr=535987 pr=0 pw=0 time=41 us)
1000000 INDEX RANGE SCAN DESCENDING IX_T1_2 (cr=3489 pr=0 pw=0 time=33 us)
SELECT *
FROM (
SELECT ROWNUM rnum ,
x.*
FROM (
SELECT /*+ index_desc(t1(c2)) */
*
FROM t1
WHERE c2 <= TO_CHAR(SYSDATE,'yyyymmdd')
ORDER BY c2 DESC, c1 DESC
) x
)
WHERE rnum BETWEEN :b1 AND :b2 ;
call cou cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.01 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 5 0.76 0.77 0 535987 0 50
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 7 0.78 0.77 0 535987 0 50
Rows Row Source Operation
------- ---------------------------------------------------
50 FILTER (cr=535987 pr=0 pw=0 time=50 us)
50 VIEW (cr=535987 pr=0 pw=0 time=48 us)
1000000 COUNT (cr=535987 pr=0 pw=0 time=44 us)
1000000 VIEW (cr=535987 pr=0 pw=0 time=42 us)
1000000 TABLE ACCESS BY INDEX ROWID T1 (cr=535987 pr=0 pw=0 time=41 us)
1000000 INDEX RANGE SCAN DESCENDING IX_T1_2 (cr=3489 pr=0 pw=0 time=33 us)
var b1 number
var b2 number
exec :b1 := 1
exec :b2 := 50 ---> 50 건
SELECT *
FROM (
SELECT ROWNUM rnum,
x.*
FROM ( SELECT /*+ INDEX_DESC(C2) */ *
FROM T1
WHERE c2 <= TO_CHAR(SYSDATE,'yyyymmdd')
ORDER BY c2 DESC, c1 DESC
) x
WHERE ROWNUM <= :b2
)
WHERE rnum >= :b1 ;
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.05 0 0 0 0
Fetch 5 0.00 0.00 0 12 0 50
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 7 0.00 0.05 0 12 0 50
Rows Row Source Operation
------- ---------------------------------------------------
50 VIEW (cr=12 pr=0 pw=0 time=93 us)
50 COUNT STOPKEY (cr=12 pr=0 pw=0 time=86 us)
50 VIEW (cr=12 pr=0 pw=0 time=83 us)
50 TABLE ACCESS BY INDEX ROWID T1 (cr=12 pr=0 pw=0 time=81 us)
50 INDEX RANGE SCAN DESCENDING IX_T1_2 (cr=7 pr=0 pw=0 time=49 us)
- 강좌 URL : http://www.gurubee.net/lecture/3831
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.