-- create partition table T1
DROP TABLE T1 PURGE;
CREATE TABLE T1(C1 INT,
C2 INT)
PARTITION BY LIST(C1)
(PARTITION P1 VALUES (1),
PARTITION P2 VALUES (2),
PARTITION P3 VALUES (3),
PARTITION P4 VALUES (4),
PARTITION P5 VALUES (5)
);
-- create data
INSERT INTO T1
SELECT 1, LEVEL FROM DUAL CONNECT BY LEVEL <= 10000 UNION ALL
SELECT 2, LEVEL FROM DUAL CONNECT BY LEVEL <= 1000 UNION ALL
SELECT 3, LEVEL FROM DUAL CONNECT BY LEVEL <= 100 UNION ALL
SELECT 4, LEVEL FROM DUAL CONNECT BY LEVEL <= 10 UNION ALL
SELECT 5, LEVEL FROM DUAL CONNECT BY LEVEL <= 1
;
COMMIT;
-- gather stats "without" histogram
EXEC DBMS_STATS.GATHER_TABLE_STATS(USER, 'T1', METHOD_OPT => 'FOR ALL COLUMNS SIZE 1', NO_INVALIDATE => FALSE);
-- create table T4
DROP TABLE T4 PURGE;
CREATE TABLE T4(C1 INT,
C2 INT)
;
-- create data
INSERT INTO T4
SELECT 1, LEVEL FROM DUAL CONNECT BY LEVEL <= 10000 UNION ALL
SELECT 2, LEVEL FROM DUAL CONNECT BY LEVEL <= 1000 UNION ALL
SELECT 3, LEVEL FROM DUAL CONNECT BY LEVEL <= 100 UNION ALL
SELECT 4, LEVEL FROM DUAL CONNECT BY LEVEL <= 10 UNION ALL
SELECT 5, LEVEL FROM DUAL CONNECT BY LEVEL <= 1
;
COMMIT;
-- gather stats "without" histogram
EXEC DBMS_STATS.GATHER_TABLE_STATS(USER, 'T4', METHOD_OPT => 'FOR ALL COLUMNS SIZE 1', NO_INVALIDATE => FALSE);
-- disable bind peeking
ALTER SYSTEM SET "_OPTIM_PEEK_USER_BINDS" = FALSE;
-- Table
SELECT TABLE_NAME,
NUM_ROWS,
BLOCKS,
SAMPLE_SIZE,
TO_CHAR(LAST_ANALYZED, 'YYYY/MM/DD HH24:MI:SS') AS LAST_ANAL
FROM USER_TAB_STATISTICS
WHERE TABLE_NAME IN ('T1', 'T4')
;
TABLE_NAME | NUM_ROWS | BLOCKS | SAMPLE_SIZE | LAST_ANAL |
---|---|---|---|---|
T1 | 11111 | 80 | 11111 | 2009-03-15 12:54 |
T1 | 1000 | 13 | 1000 | 2009-03-15 12:54 |
T1 | 100 | 13 | 100 | 2009-03-15 12:54 |
T1 | 10 | 13 | 10 | 2009-03-15 12:54 |
T1 | 1 | 13 | 1 | 2009-03-15 12:54 |
T1 | 10000 | 28 | 10000 | 2009-03-15 12:54 |
T4 | 11111 | 28 | 11111 | 2009-03-15 12:54 |
-- Column
SELECT S.TABLE_NAME,
S.COLUMN_NAME,
S.NUM_DISTINCT,
S.NUM_NULLS,
S.DENSITY,
S.LOW_VALUE,
S.HIGH_VALUE,
S.HISTOGRAM
FROM USER_TAB_COLS S
WHERE S.TABLE_NAME IN ('T1', 'T4')
;
TABLE_NAME | COLUMN_NAME | NUM_DISTINCT | NUM_NULLS | DENSITY | LOW_VALUE | HIGH_VALUE | HISTOGRAM |
---|---|---|---|---|---|---|---|
T1 | C2 | 10000 | 0 | 0.0001 | C102 | C302 | NONE |
T1 | C1 | 5 | 0 | 0.2 | C102 | C106 | NONE |
T4 | C2 | 10000 | 0 | 0.0001 | C102 | C302 | NONE |
T4 | C1 | 5 | 0 | 0.2 | C102 | C106 | NONE |
-- Histogram
SELECT TABLE_NAME,
COLUMN_NAME,
ENDPOINT_NUMBER,
ENDPOINT_VALUE || '(' || ENDPOINT_ACTUAL_VALUE || ')' AS ENDPOINT_VALUE
FROM USER_TAB_HISTOGRAMS
WHERE TABLE_NAME IN ('T1', 'T4')
ORDER BY COLUMN_NAME,
ENDPOINT_NUMBER
;
TABLE_NAME | COLUMN_NAME | ENDPOINT_NUMBER | ENDPOINT_VALUE |
---|---|---|---|
T1 | C1 | 0 | 1() |
T1 | C1 | 1 | 5() |
T1 | C2 | 0 | 1() |
T1 | C2 | 1 | 10000() |
T4 | C1 | 0 | 1() |
T4 | C1 | 1 | 5() |
T4 | C2 | 0 | 1() |
T4 | C2 | 1 | 10000() |
VAR B1 NUMBER;
VAR B2 NUMBER;
EXEC :B1 := 1;
EXEC :B2 := 3;
SELECT /*+ GATHER_PLAN_STATISTICS */
COUNT(*)
FROM T1
WHERE C1 = :B1
;
select * from table(dbms_xplan.display_cursor(null, null, 'iostats cost last'));
------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
------------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | | 1 |00:00:00.01 | 31 |
| 2 | PARTITION LIST SINGLE| | 1 | 2222 | 6 (0)| 10000 |00:00:00.01 | 31 |
| 3 | TABLE ACCESS FULL | T1 | 1 | 2222 | 6 (0)| 10000 |00:00:00.01 | 31 |
------------------------------------------------------------------------------------------------------
SELECT /*+ GATHER_PLAN_STATISTICS */
COUNT(*)
FROM T4
WHERE C1 = :B1
;
select * from table(dbms_xplan.display_cursor(null, null, 'iostats cost last'));
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | | 1 |00:00:00.01 | 31 |
|* 2 | TABLE ACCESS FULL| T4 | 1 | 2222 | 9 (0)| 10000 |00:00:00.01 | 31 |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("C1"=:B1)
;
SELECT /*+ GATHER_PLAN_STATISTICS */
COUNT(*)
FROM T1
WHERE C1 = 1
;
select * from table(dbms_xplan.display_cursor(null, null, 'iostats cost last'));
------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
------------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | | 1 |00:00:00.01 | 31 |
| 2 | PARTITION LIST SINGLE| | 1 | 10000 | 9 (0)| 10000 |00:00:00.01 | 31 |
| 3 | TABLE ACCESS FULL | T1 | 1 | 10000 | 9 (0)| 10000 |00:00:00.01 | 31 |
------------------------------------------------------------------------------------------------------
SELECT /*+ GATHER_PLAN_STATISTICS */
COUNT(*)
FROM T4
WHERE C1 = 1
;
select * from table(dbms_xplan.display_cursor(null, null, 'iostats cost last'));
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | | 1 |00:00:00.01 | 31 |
|* 2 | TABLE ACCESS FULL| T4 | 1 | 2222 | 9 (0)| 10000 |00:00:00.01 | 31 |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("C1"=1)
;
SELECT /*+ GATHER_PLAN_STATISTICS */
COUNT(*)
FROM T1
WHERE C1 BETWEEN 1
AND 3
;
select * from table(dbms_xplan.display_cursor(null, null, 'iostats cost last'));
--------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | | 1 |00:00:00.01 | 61 |
| 2 | PARTITION LIST ITERATOR| | 1 | 7778 | 16 (0)| 11100 |00:00:00.01 | 61 |
| 3 | TABLE ACCESS FULL | T1 | 3 | 7778 | 16 (0)| 11100 |00:00:00.01 | 61 |
--------------------------------------------------------------------------------------------------------
SELECT /*+ GATHER_PLAN_STATISTICS */
COUNT(*)
FROM T4
WHERE C1 BETWEEN 1
AND 3
;
select * from table(dbms_xplan.display_cursor(null, null, 'iostats cost last'));
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | | 1 |00:00:00.01 | 31 |
|* 2 | TABLE ACCESS FULL| T4 | 1 | 7778 | 9 (0)| 11100 |00:00:00.01 | 31 |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(("C1"<=3 AND "C1">=1))
;
SELECT /*+ GATHER_PLAN_STATISTICS */
COUNT(*)
FROM T1
WHERE C1 BETWEEN :B1
AND :B2
;
select * from table(dbms_xplan.display_cursor(null, null, 'iostats cost last'));
---------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
---------------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | | 1 |00:00:00.01 | 61 |
|* 2 | FILTER | | 1 | | | 11100 |00:00:00.01 | 61 |
| 3 | PARTITION LIST ITERATOR| | 1 | 445 | 23 (0)| 11100 |00:00:00.01 | 61 |
| 4 | TABLE ACCESS FULL | T1 | 3 | 445 | 23 (0)| 11100 |00:00:00.01 | 61 |
---------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(:B1<=:B2)
- 강좌 URL : http://www.gurubee.net/lecture/4427
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.