-- 0. Oracle Version
SELECT *
FROM V$VERSION
;
BANNER
------------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
NLSRTL Version 10.2.0.3.0 - Production
;
-- 1. 테이블 T1 생성
DROP TABLE T1;
DROP TABLE GENERATOR;
CREATE TABLE GENERATOR AS
SELECT ROWNUM ID
FROM ALL_OBJECTS
WHERE ROWNUM <= 2000
;
CREATE TABLE T1 (SKEW NOT NULL,
PADDING)
AS
SELECT /*+ ORDERED USE_NL(V2) */
V1.ID,
RPAD('X',400)
FROM GENERATOR V1,
GENERATOR V2
WHERE V1.ID <= 80
AND V2.ID <= 80
AND V2.ID <= V1.ID
ORDER BY V2.ID,V1.ID
;
CREATE INDEX T1_I1 ON T1(SKEW);
-- 2. 테이블 T1 데이터 조회
SELECT COUNT(*)
FROM T1
;
COUNT(*)
----------
3240
SELECT SKEW,
COUNT(*)
FROM T1
GROUP BY SKEW
ORDER BY SKEW
;
SKEW COUNT(*)
---------- ----------
1 1
2 2
.....................
79 79
80 80
-- 3. 테이블 T1 Height-Balance Histogram 포함된 통계정보 생성
-- Height-Balance Histogram 생성 시 Rows가 80개인 생태에서 Bucket을 120개 요청했지만 결과는 80개 로우만 생성
BEGIN
DBMS_STATS.GATHER_TABLE_STATS(USER,
'T1',
CASCADE => TRUE,
ESTIMATE_PERCENT => NULL,
METHOD_OPT => 'FOR ALL COLUMNS SIZE 120');
END;
/
SELECT ROWNUM,
ENDPOINT_NUMBER,
ENDPOINT_VALUE
FROM USER_TAB_HISTOGRAMS
WHERE COLUMN_NAME = 'SKEW'
AND TABLE_NAME = 'T1'
ORDER BY ENDPOINT_NUMBER
;
ROWNUM ENDPOINT_NUMBER ENDPOINT_VALUE
------ --------------- --------------
1 1 1
2 3 2
.....................................
79 3160 79
80 3240 80
;
-- 4. USER_TAB_HISTOGRAMS 조회하여 분포도 확인
SELECT ENDPOINT_VALUE ROW_VALUE,
CURR_NUM - NVL(PREV_NUM, 0) ROW_COUNT
FROM (SELECT ENDPOINT_VALUE,
ENDPOINT_NUMBER CURR_NUM,
LAG(ENDPOINT_NUMBER, 1) OVER(ORDER BY ENDPOINT_NUMBER) PREV_NUM
FROM USER_TAB_HISTOGRAMS
WHERE COLUMN_NAME = 'SKEW'
AND TABLE_NAME = 'T1')
ORDER BY ENDPOINT_VALUE
;
ROW_VALUE ROW_COUNT
---------- ----------
1 1
2 2
.....................
79 79
80 80
;
조건절 | 설명 | CBO | 사람 |
---|---|---|---|
SKEW = 40 | 상수 값 | 40 | 40 |
SKEW = 40.5 | 존재하기는 않지만 범위에 포함 | 1 | 0 |
SKEW BETWEEN 21 AND 24 | 범위 내에 포함되는 BETWEEN 조건 | 90 | 90 |
SKEW BETWEEN 20.5 AND 24.5 | 범위 내에 포함되는 BETWEEN 조건 | 90 | 90 |
SKEW BETWEEN 1 AND 2 | 시작점을 포함한 BETWEEN 조건 | 3 | 3 |
SKEW BETWEEN 79 AND 80 | 종료점을 포함한 BETWEEN 조건 | 159 | 159 |
SKEW > 4 AND SKEW < 8 | ">" AND "<" 범위 조건 | 18 | 18 |
SKEW = -10 | 최소값 미만 | 1 | 0 |
SKEW = 100 | 최대값 미만 | 1 | 0 |
SKEW BETWEEN -5 AND -3 | 최소값 미만의 범위 조건 | 1 | 0 |
SKEW BETWEEN 92 AND 94 | 최대값 미만의 범위 조건 | 1 | 0 |
SKEW BETWEEN 79 AND 82 | 경계 값에 걸치는 범위 조건 | 159 | 159 |
SKEW = :B1 | 바인드 변수 | 41 | ??? |
SKEW BETWEEN :B1 AND :B2 | 바인드 변수의 BETWEEN 조건 | 8 | ??? |
-- 0. Oracle Version
SELECT *
FROM V$VERSION
;
BANNER
------------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
NLSRTL Version 10.2.0.3.0 - Production
;
-- 1. SKEW = 40
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW = 40
;
@xplan
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 40 | 16160 | 56 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 40 | 16160 | 56 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SKEW"=40)
;
-- 2. SKEW = 40.5
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW = 40.5
;
@xplan
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 404 | 56 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 1 | 404 | 56 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SKEW"=40.5)
;
-- 3. SKEW BETWEEN 21 AND 24
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW BETWEEN 21 AND 24
;
@xplan
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 90 | 36360 | 56 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 90 | 36360 | 56 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SKEW"<=24 AND "SKEW">=21)
;
-- 4. SKEW BETWEEN 20.5 AND 24.5
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW BETWEEN 20.5 AND 24.5
;
@xplan
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 90 | 36360 | 56 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 90 | 36360 | 56 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SKEW"<=24.5 AND "SKEW">=20.5)
;
-- 5. SKEW BETWEEN 1 AND 2
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW BETWEEN 1 AND 2
;
@xplan
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 90 | 36360 | 56 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 90 | 36360 | 56 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SKEW"<=24.5 AND "SKEW">=20.5)
;
-- 6. SKEW BETWEEN 79 AND 80
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW BETWEEN 79 AND 80
;
@xplan
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 158 | 63832 | 56 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 158 | 63832 | 56 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SKEW">=79 AND "SKEW"<=80)
;
-- 7. SKEW > 4 AND SKEW < 8
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW > 4 AND SKEW < 8
;
@xplan
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 18 | 7272 | 56 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 18 | 7272 | 56 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SKEW"<8 AND "SKEW">4)
;
-- 8. SKEW = -10
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW = -10
;
@xplan
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 404 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1 | 404 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T1_I1 | 1 | | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("SKEW"=(-10))
;
-- 9. SKEW= 100
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW = 100
;
@xplan
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 404 | 56 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 1 | 404 | 56 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SKEW"=100)
;
-- 10. SKEW BETWEEN -5 AND -3
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW BETWEEN -5 AND -3
;
@xplan
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 404 | 56 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 1 | 404 | 56 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SKEW"<=(-3) AND "SKEW">=(-5))
;
-- 11. SKEW BETWEEN 92 AND 94
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW BETWEEN 92 AND 94
;
@xplan
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 404 | 56 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 1 | 404 | 56 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SKEW">=92 AND "SKEW"<=94)
;
-- 12. SKEW BETWEEN 79 AND 82
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW BETWEEN 79 AND 82
;
@xplan
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 158 | 63832 | 56 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 158 | 63832 | 56 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SKEW">=79 AND "SKEW"<=82)
;
-- 13. SKEW = :B1
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW = :B1
;
@xplan
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 41 | 16564 | 56 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| T1 | 41 | 16564 | 56 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("SKEW"=TO_NUMBER(:B1))
;
-- 14. SKEW BETWEEN :B1 AND :B2
EXPLAIN PLAN FOR
SELECT *
FROM T1
WHERE SKEW BETWEEN :B1 AND :B2
;
@xplan
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 8 | 3232 | 56 (0)| 00:00:01 |
|* 1 | FILTER | | | | | |
|* 2 | TABLE ACCESS FULL| T1 | 8 | 3232 | 56 (0)| 00:00:01 |
---------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(TO_NUMBER(:B1)<=TO_NUMBER(:B2))
2 - filter("SKEW">=TO_NUMBER(:B1) AND "SKEW"<=TO_NUMBER(:B2))
;
- 강좌 URL : http://www.gurubee.net/lecture/4415
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.