Script. 테스트 데이터 생성용
< ROWNUM_T1 >
■ 생성 요건
- 테이블의 전체 건수는 50,000 ROWS
- C1은 값의 종류가 100,000가지 즉, UNIQUE한 값을 갖음.
- C2는 값의 종류가 26가지.
■ 테이블 생성
DROP TABLE ROWNUM_T1;
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_T1_01 ON ROWNUM_T1(C2,C1);
BEGIN
dbms_stats.gather_table_stats(OWNNAME=>'SCOTT',
TABNAME=>'ROWNUM_T1',
ESTIMATE_PERCENT=>99,
METHOD_OPT=>'FOR ALL INDEXED COLUMNS',
GRANULARITY=>'ALL',
CASCADE=>TRUE,
NO_INVALIDATE=>FALSE) ;
END;
/
--SQL(1)
SELECT /*+ INDEX_DESC(T1 IDX_T1_01) */
C1
FROM ROWNUM_T1 T1
WHERE T1.C2='A'
AND T1.C1 >= 0
AND ROWNUM <= 1;
--SQL(2)
SELECT C1
FROM (
SELECT /*+ INDEX_DESC(T1 IDX_T1_01) */
C1
FROM ROWNUM_T1 T1
WHERE T1.C2='A'
AND T1.C1 >= 0
ORDER BY C2 DESC, C1 DESC
)
WHERE ROWNUM <= 1;
--SQL(3)
SELECT MAX(C1) AS C1
FROM ROWNUM_T1 T1
WHERE T1.C2='A'
AND T1.C1 >= 0
;