B-Tree索引性能优于BitMap索引实例(一)

2014-11-24 17:12:35 · 作者: · 浏览: 0

一、实验说明:


操作系统:rhel 5.4 x86


实验说明:该实验是为了说明B-Tree索引性能优于BitMap索引的情况。


二、实验操作:


首先创建一张t_btree表,并建立B-Tree索引,索引键是object_id:


SQL> create table t_btree as select * from dba_objects;


Table created.


SQL> create index ind_tree on t_btree(object_id);


Index created.


执行两次下面的查询语句,并显示执行计划:


SQL> set autotrace traceonly;
SQL> select * from t_btree where object_id=9899;



Execution Plan
----------------------------------------------------------
Plan hash value: 447474086


----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 207 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_BTREE | 1 | 207 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IND_TREE | 1 | | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


2 - access("OBJECT_ID"=9899)


Note
-----
- dynamic sampling used for this statement (level=2)



Statistics
----------------------------------------------------------
312 recursive calls
0 db block gets
108 consistent gets
289 physical reads
0 redo size
1404 bytes sent via SQL*Net to client
419 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed


SQL> select * from t_btree where object_id=9899;



Execution Plan
----------------------------------------------------------
Plan hash value: 447474086


----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 207 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T_BTREE | 1 | 207 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IND_TREE | 1 | | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


2 - access("OBJECT_ID"=9899)


Note
-----
- dynamic sampling used for this statement (level=2)



Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
4 consistent gets
0 physical reads
0 redo size
1404 bytes sent via SQL*Net to client
419 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed


同样执行之前的语句两次:


SQL> select * from t_bmap where object_id=9899;



Execution Plan
----------------------------------------------------------
Plan hash value: 3763176822


----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 207 | 110 (0)| 00:00:02 |
| 1 | TABLE ACCESS B