索引組織表IOT表的數據是以已經按主鍵字段排好序後存放在B-tree索引中的,而堆表的數據則是無序的存放在表段的數據塊中。
#############索引回表讀開銷大
索引組織表
(1)建立表
//建立普通的表
create table heap_add(empno number(10),addr_type varchar2(10),street varchar(10),city varchar2(10),state varchar2(10),primary key(empno));
//索引組織表
create table iot_add(empno number(10),addr_type varchar2(10),street vrchar(10),city varchar2(10),state varchar2(10),primary key(empno)) organizationindex;
(2)插入數據
//普通表插入數據
insert into heap_add select object_id,'teah','louyang','henan,cn',44 from all_objects;
//索引組織表插入數據
insert into iot_add select object_id,'teah','louyang','henan,cn',44 from all_objects;
//必定要commit
commit;
(3)開啓執行計劃
set autotrace traceonly;
(4)查詢一下
普通表:
LISN@orcl>select * from heap_add where empno=22;
select * from heap_add where empno=22;
Execution Plan
----------------------------------------------------------
Plan hash value: 3026474701
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 41 | 1 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| HEAP_ADD | 1 | 41 | 1 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | SYS_C0011151 | 1 | | 1 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("EMPNO"=22)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
688 bytes sent via SQL*Net to client
512 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
索引組織表:
LISN@orcl>select * from iot_add where empno=22;
select * from iot_add where empno=22;
Execution Plan
----------------------------------------------------------
Plan hash value: 2557813697
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 41 | 1 (0)| 00:00:01 |
|* 1 | INDEX UNIQUE SCAN| SYS_IOT_TOP_74712 | 1 | 41 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("EMPNO"=22)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
2 consistent gets
0 physical reads
0 redo size
820 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
ide