SYS> drop table t1 purge ;
Table dropped.
SYS> create table t1 ( c1 number, c2 number ) ;
Table created.
SYS> create index xak1_t1 on t1 ( c1 ) ;
Index created.
SYS>begin
for i in 1 .. 12 loop
insert into t1 values ( i, i );
commit ;
end loop ;
end ;
/
PL/SQL procedure successfully completed.
SYS>execute dbms_stats.gather_table_stats(ownname => user , tabname =>'t1');
PL/SQL procedure successfully completed.
SYS> select /*+ gather_plan_statistics */ c1 from t1 where c1 >= 5 ;
C1
----------
5
6
7
8
9
10
11
12
8 rows selected.
SYS> select * from table(dbms_xplan.display_cursor(null,null,'allstats last'));
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------
SQL_ID a0kg1rkv32nfg, child number 0
-------------------------------------
select /*+ gather_plan_statistics */ c1 from t1 where c1 >= 5
Plan hash value: 3186761381
--------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------
|* 1 | INDEX RANGE SCAN| XAK1_T1 | 1 | 9 | 8 |00:00:00.01 | 2 |
--------------------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("C1">=5)
17 rows selected.
SYS> drop table t1 purge ;
Table dropped.
SYS> create table t1 ( c1 number, c2 number ) ;
Table created.
SYS> create index xak1_t1 on t1 ( c1 ) ;
Index created.
SYS> begin
for i in 1 .. 10000 loop
insert into t1 values ( i, i );
commit ;
end loop ;
end ;
/
SYS> exec dbms_stats.gather_table_stats(ownname => user, tabname =>'t1');
PL/SQL procedure successfully completed.
SYS> select /*+ gather_plan_statistics index(t1) */ c1 from t1 where c1 >= 5 ;
...
10000
9996 rows selected.
SYS>!more stat.sql
select * from table
(dbms_xplan.display_cursor(null,null,'allstats cost last'));
SYS>@stat.sql
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------
SQL_ID 4j0t2rwbwjdux, child number 0
-------------------------------------
select /*+ gather_plan_statistics index(t1) */ c1 from t1 where c1 >= 5
Plan hash value: 3186761381
---------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
---------------------------------------------------------------------------------------------------
|* 1 | INDEX RANGE SCAN| XAK1_T1 | 1 | 9997 | 20 (0)| 9996 |00:00:00.01 | 686 |
---------------------------------------------------------------------------------------------------
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("C1">=5)
17 rows selected.
SYS>@dic.sql
Enter value for 1: XAK1_T1
OWNER : SYS
INDEX_NAME : XAK1_T1
INDEX_TYPE : NORMAL
TABLE_OWNER : SYS
TABLE_NAME : T1
TABLE_TYPE : TABLE
UNIQUENESS : NONUNIQUE
COMPRESSION : DISABLED
PREFIX_LENGTH :
TABLESPACE_NAME : SYSTEM
INI_TRANS : 2
MAX_TRANS : 255
INITIAL_EXTENT : 65536
NEXT_EXTENT :
MIN_EXTENTS : 1
MAX_EXTENTS : 2147483645
PCT_INCREASE :
PCT_THRESHOLD :
INCLUDE_COLUMN :
FREELISTS : 1
FREELIST_GROUPS : 1
PCT_FREE : 10
LOGGING : YES
BLEVEL : 1
LEAF_BLOCKS : 19
DISTINCT_KEYS : 10000
AVG_LEAF_BLOCKS_PER_KEY : 1
AVG_DATA_BLOCKS_PER_KEY : 1
CLUSTERING_FACTOR : 18
STATUS : VALID
NUM_ROWS : 10000
SAMPLE_SIZE : 10000
LAST_ANALYZED : 08-MAR-09
DEGREE : 1
INSTANCES : 1
PARTITIONED : NO
TEMPORARY : N
GENERATED : N
SECONDARY : N
BUFFER_POOL : DEFAULT
USER_STATS : NO
DURATION :
PCT_DIRECT_ACCESS :
ITYP_OWNER :
ITYP_NAME :
PARAMETERS :
GLOBAL_STATS : YES
DOMIDX_STATUS :
DOMIDX_OPSTATUS :
FUNCIDX_STATUS :
JOIN_INDEX : NO
IOT_REDUNDANT_PKEY_ELIM : NO
DROPPED : NO
-----------------
PL/SQL procedure successfully completed.
SYS>select /*+ gather_plan_statistics index(t1) */ count(*) from t1 where c1 >= 5 ;
COUNT(*)
----------
9996
SYS>@stat.sql
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
SQL_ID 7s12nm5rtga08, child number 0
-------------------------------------
select /*+ gather_plan_statistics index(t1) */ count(*) from t1 where c1 >= 5
Plan hash value: 2215041688
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
----------------------------------------------------------------------------------------------------
| 1 | SORT AGGREGATE | | 1 | 1 | | 1 |00:00:00.01 | 20 |
|* 2 | INDEX RANGE SCAN| XAK1_T1 | 1 | 9997 | 20 (0)| 9996 |00:00:00.01 | 20 |
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("C1">=5)
18 rows selected.
SYS>show array
arraysize 15
Sets the number of rows, called a batch,
that SQL*Plus will fetch from the database at one time.
SYS> show array
arraysize 15
SYS> set arraysize 1
SYS> select /*+ gather_plan_statistics index(t1) */ c1 from t1 where c1 >= 5 ;
SYS> @stat
Plan hash value: 3186761381
---------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
---------------------------------------------------------------------------------------------------
|* 1 | INDEX RANGE SCAN| XAK1_T1 | 1 | 9997 | 20 (0)| 9996 |00:00:00.01 | 5009 |
---------------------------------------------------------------------------------------------------
SYS> set arraysize 10
SYS> select /*\+ gather_plan_statistics index(t1) \*/ c1 from t1 where c1 >= 5 ;
SYS> @stat
Plan hash value: 3186761381
\--------------------------------------------------------------------------------------------------\-
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU) | A-Rows | A-Time | Buffers |
\--------------------------------------------------------------------------------------------------\-
| * 1 | INDEX RANGE SCAN | XAK1_T1 | 1 | 9997 | 20 (0) | 9996 | 00:00:00.01 | 1018 |
\--------------------------------------------------------------------------------------------------\-
SYS>set arraysize 100
SYS>select /*+ gather_plan_statistics index(t1) */ c1 from t1 where c1 >= 5 ;
SYS> @stat
Plan hash value: 3186761381
---------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
---------------------------------------------------------------------------------------------------
|* 1 | INDEX RANGE SCAN| XAK1_T1 | 1 | 9997 | 20 (0)| 9996 |00:00:00.01 | 119 |
---------------------------------------------------------------------------------------------------
SYS>set arraysize 1000
SYS>select /*+ gather_plan_statistics index(t1) */ c1 from t1 where c1 >= 5 ;
SYS> @stat
Plan hash value: 3186761381
---------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
---------------------------------------------------------------------------------------------------
|* 1 | INDEX RANGE SCAN| XAK1_T1 | 1 | 9997 | 20 (0)| 9996 |00:00:00.01 | 30 |
---------------------------------------------------------------------------------------------------
SYS > @mon_init
SYS>@mysid
SID
----------
145
SYS>@mon_on &v_sid
SYS>@mon_show2
SYS>set arraysize 1
SYS>select /*+ gather_plan_statistics index(t1) */ c1 from t1 where c1 >= 5 ;
..
9996 rows selected.
SYS>@mon_off
SYS>set arraysize 1000
SYS>select /*+ gather_plna_statistics index(t1) */ c1 from t1 where c1 >= 5 ;
SYS>@mon_off2
SYS>@mon_show2
01. statistics
NAME DIFF VALUE2 VALUE1
----------------------------------------------- ------------ ------------ ------------
session pga memory max 1,441,792 528,072 1,969,864
session uga memory max 1,310,144 156,628 1,466,772
bytes sent via SQL*Net to client 700,423 2,511 702,934
session uga memory 65,464 91,164 156,628
bytes received via SQL*Net from client 56,541 1,462 58,003
sorts (rows) 10,090 0 10,090
=========================================================================================
session logical reads 5,077 5 5,082
user calls 5,008 16 5,024
=========================================================================================
consistent gets 5,018 4 5,022
consistent gets from cache 5,018 4 5,022
SQL*Net roundtrips to/from client 5,003 10 5,013
no work - consistent read gets 5,008 2 5,010
=========================================================================================
buffer is not pinned count 4,989 0 4,989
=========================================================================================
SYS>explain plan for
select c1, c2 from t1 where c1 >= 5 and c1 <= 9 ;
Explained.
SYS>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------
Plan hash value: 3393034826
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6 | 42 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 6 | 42 | 3 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | XAK1_T1 | 6 | | 2 (0)| 00:00:01 |
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------
2 - access("C1">=5 AND "C1"<=9)
14 rows selected.
SYS>set arraysize 1
SYS> select /*+ gather_plan_statistics index(t1) */ c2 from t1 where c1> 5 ;
SYS>@stat
Plan hash value: 3393034826
--------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------------------
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1 | 9996 | 39 (3)| 9995 |00:00:00.04 | 10014 |
|* 2 | INDEX RANGE SCAN | XAK1_T1 | 1 | 9996 | 20 (0)| 9995 |00:00:00.02 | 5008 |
SYS>set arraysize 1000
SYS>select /*+ gather_plan_statistics index(t1) */ c2 from t1 where c1> 5 ;
SYS>@stat
Plan hash value: 3393034826
--------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | Cost (%CPU)| A-Rows | A-Time | Buffers |
--------------------------------------------------------------------------------------------------------------
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1 | 9996 | 39 (3)| 9995 |00:00:00.04 | 58 |
|* 2 | INDEX RANGE SCAN | XAK1_T1 | 1 | 9996 | 20 (0)| 9995 |00:00:00.02 | 30 |
SYS> @dic.sql t1
OWNER : SYS
TABLE_NAME : T1
TABLESPACE_NAME : SYSTEM
CLUSTER_NAME :
IOT_NAME :
STATUS : VALID
PCT_FREE : 10
PCT_USED : 40
INI_TRANS : 1
MAX_TRANS : 255
INITIAL_EXTENT : 65536
NEXT_EXTENT :
MIN_EXTENTS : 1
MAX_EXTENTS : 2147483645
PCT_INCREASE :
FREELISTS : 1
FREELIST_GROUPS : 1
LOGGING : YES
BACKED_UP : N
NUM_ROWS : 10000 <=== Rows 수는 10,000
BLOCKS : 20 <=== Block 수는 20
EMPTY_BLOCKS : 0
AVG_SPACE : 0
CHAIN_CNT : 0
AVG_ROW_LEN : 7
AVG_SPACE_FREELIST_BLOCKS : 0
NUM_FREELIST_BLOCKS : 0
DEGREE : 1
INSTANCES : 1
CACHE : N
TABLE_LOCK : ENABLED
SAMPLE_SIZE : 10000
LAST_ANALYZED : 08-MAR-09
PARTITIONED : NO
IOT_TYPE :
TEMPORARY : N
SECONDARY : N
NESTED : NO
BUFFER_POOL : DEFAULT
ROW_MOVEMENT : DISABLED
GLOBAL_STATS : YES
USER_STATS : NO
DURATION :
SKIP_CORRUPT : DISABLED
MONITORING : YES
CLUSTER_OWNER :
DEPENDENCIES : DISABLED
COMPRESSION : DISABLED
DROPPED : NO
-----------------
PL/SQL procedure successfully completed.
SYS> select owner, table_name, BLOCKS from dba_tables where owner='SYS' and table_name ='T1';
OWNER TABLE_NAME BLOCKS
------------------------------ ------------------------------ ----------
SYS T1 20
SYS> select OWNER, SEGMENT_NAME, SEGMENT_TYPE, BLOCKS from dba_segments
where owner='SYS' and SEGMENT_NAME ='T1'
OWNER SEGMENT_NAME SEGMENT_TYPE BLOCKS
------------------------------ ---------------------------------------- ------------------ ----------
SYS T1 TABLE 24
- 강좌 URL : http://www.gurubee.net/lecture/4428
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.