예제) 인덱스의 구조
INDEX NAME | COLUMN_LIST |
---|---|
INDEX_MBOX_STATUS | USERID, STATUS |
INDEX_MBOX_SENDDATA | USERID, SENDDATE |
SELECT *
FROM (SELECT /*+ INDEX_DESC(A IDX_MBOX_SENDDATA) */
A.*,
ROWNUM AS RNUM
FROM TBS_MBOX A
WHERE USERID = :B1
AND STATUS = :B2
AND ROWNUM <= :B3
)
WHERE RNUM >= :B4;
VIEW
COUNT STOPKEY
TABLE ACCESS (BY INDEX ROWID) OF 'TBS_MBOX' (TABLE)
INDEX (RANGE SCAN DESCENDING) OF 'IDX_MBOX_SENDDATE' (INDEX)
위의 쿼리를 아래와 같이 변경할 수 있다.
SELECT X.*
FROM (SELECT A.*,
ROWNUM AS RNUM
FROM (SELECT A.*
FROM TBS_MBOX A
WHERE USERID = :B1
AND STATUS = :B2
ORDER BY A.USERID DESC, A.SENDDATE DESC
) A
WHERE ROWNUM <= :B3
) X
WHERE RNUM >= :B4;