Maison > base de données > tutoriel mysql > le corps du texte

BitMap索引的效率要优于B-Tree索引实例

WBOY
Libérer: 2016-06-07 16:44:37
original
941 Les gens l'ont consulté

一、实验说明: 操作系统:rhel 5.4 x86 数据库:Oracle 11g R2 二、操作步骤: 首先创建一张t_btree表,并建立B-Tr

一、实验说明:

    操作系统:rhel 5.4 x86

    数据库:Oracle 11g R2

二、操作步骤:

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

SQL> create table t_btree as select * from dba_objects;

Table created.

SQL> create index status_btree on t_btree(status);

Index created.

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

SQL> set autotrace traceonly;
SQL> select count(*) from t_btree where status='VALID';


Execution Plan
----------------------------------------------------------
Plan hash value: 2400455617

--------------------------------------------------------------------------------------
| Id  | Operation          | Name        | Rows  | Bytes | Cost (%CPU)| Time    |
--------------------------------------------------------------------------------------
|  0 | SELECT STATEMENT      |          |      1 |      5 |      49  (0)| 00:00:01 |
|  1 |  SORT AGGREGATE      |          |      1 |      5 |          |        |
|*  2 |  INDEX FAST FULL SCAN| STATUS_BTREE | 74307 |    362K|      49  (0)| 00:00:01 |
--------------------------------------------------------------------------------------

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

  2 - filter("STATUS"='VALID')

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


Statistics
----------------------------------------------------------
    32  recursive calls
      0  db block gets
    261  consistent gets
    458  physical reads
      0  redo size
    424  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 count(*) from t_btree where status='VALID';


Execution Plan
----------------------------------------------------------
Plan hash value: 2400455617

--------------------------------------------------------------------------------------
| Id  | Operation          | Name        | Rows  | Bytes | Cost (%CPU)| Time    |
--------------------------------------------------------------------------------------
|  0 | SELECT STATEMENT      |          |      1 |      5 |      49  (0)| 00:00:01 |
|  1 |  SORT AGGREGATE      |          |      1 |      5 |          |        |
|*  2 |  INDEX FAST FULL SCAN| STATUS_BTREE | 74307 |    362K|      49  (0)| 00:00:01 |
--------------------------------------------------------------------------------------

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

  2 - filter("STATUS"='VALID')

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


Statistics
----------------------------------------------------------
      0  recursive calls
      0  db block gets
    180  consistent gets
      0  physical reads
      0  redo size
    424  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

接着创建跟t_btree一样的表t_bmap,并创建BitMap索引。

SQL> create table t_bmap as select * from dba_objects;

Table created.

SQL> create bitmap index status_bmap on t_bmap(status);

Index created.

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

SQL> select count(*) from t_bmap where status='VALID';


Execution Plan
----------------------------------------------------------
Plan hash value: 516980546

---------------------------------------------------------------------------------------------
| Id  | Operation              | Name        | Rows  | Bytes | Cost (%CPU)| Time    |
---------------------------------------------------------------------------------------------
|  0 | SELECT STATEMENT          |        |      1 |      5 |      3  (0)| 00:00:01 |
|  1 |  SORT AGGREGATE          |        |      1 |      5 |        |        |
|  2 |  BITMAP CONVERSION COUNT    |        | 62928 |    307K|      3  (0)| 00:00:01 |
|*  3 |    BITMAP INDEX FAST FULL SCAN| STATUS_BMAP |        |        |        |        |
---------------------------------------------------------------------------------------------

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

  3 - filter("STATUS"='VALID')

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

source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!