你好,游客 登录 注册 搜索
背景:
阅读新闻

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

[日期:2014-10-08] 来源:Linux社区  作者:Linux [字体: ]

一、实验说明:

     操作系统:rhel 5.4 x86

    数据库:Oracle 11g R2

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

Oracle B树索引简介(B-Tree Index)  http://www.linuxidc.com/Linux/2013-03/80754.htm

浅析Oracle B-Tree index搜索原理 http://www.linuxidc.com/Linux/2012-08/68578.htm

Oracle索引之B-Tree和Bitmap索引对比 http://www.linuxidc.com/Linux/2012-03/57460.htm

从平衡树到oracle B-Tree索引的原理探索 http://www.linuxidc.com/Linux/2012-08/67524.htm

二、实验操作:

  首先创建一张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 BY INDEX ROWID | T_BMAP  |    1 |  207 |  110    (0)| 00:00:02 |
|  2 |  BITMAP CONVERSION TO ROWIDS|          |      |      |        |          |
|*  3 |    BITMAP INDEX SINGLE VALUE | IND_MAP |      |      |        |          |
----------------------------------------------------------------------------------------

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

  3 - access("OBJECT_ID"=9899)

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


Statistics
----------------------------------------------------------
    312  recursive calls
      0  db block gets
    98  consistent gets
    266  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 BY INDEX ROWID | T_BMAP  |    1 |  207 |  110    (0)| 00:00:02 |
|  2 |  BITMAP CONVERSION TO ROWIDS|          |      |      |        |          |
|*  3 |    BITMAP INDEX SINGLE VALUE | IND_MAP |      |      |        |          |
----------------------------------------------------------------------------------------

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

  3 - access("OBJECT_ID"=9899)

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


Statistics
----------------------------------------------------------
      7  recursive calls
      0  db block gets
    68  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

从上面的查询中,我们可以得到,分别给两张内容一样的表做查询的时候,在执行第二次的时候是属于软解析:

从一致性读上比较,B-Tree索引的consistent gets是4,BitMap的是68;

从Cost的消耗上看,B-Tree索引的COST是2,而BitMap的是110。

在索引键是主键或者唯一性约束的情况下B-Tree索引的效率要优于BitMap索引。

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址http://www.linuxidc.com/Linux/2014-10/107731.htm

linux
相关资讯       B-Tree索引  BitMap索引 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款