索引组织表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