您好,欢迎来到年旅网。
搜索
您的当前位置:首页B树索引和位图索引

B树索引和位图索引

来源:年旅网

转自:http://wengn.iteye.com/blog/1840377


前言

众所周知建立索引是为了提高数据库查询效率。正解的索引确实能够数倍的提高数据库查询效率,但一个错误的索引将会把数据库拖慢,甚至拖死。

本文意在探讨如何选择索引类型。

正文

Oracle常用的有两种索引类型:B树索引和位图索引。

一、      B树索引

 

(B树索引结构图)

B树索引适用对象:

(1)        适合高基数的列(唯一值多);

(2)        适合与大量的增、删、改(OLTP);

(3)        不能用包含OR操作符的查询;

什么时候不适合创建B树索引:引用一下oracle官方文档

Where B-Trees Should Not Be Created

Several situations are worth noting where you should not create B-Tree indexes on columns. These cases include columns which:

§ Have only a few distinct values in their domains. For example, a Type column that has only four distinct values (A, B, C, and D). The index would be said to have "low selectivity." If you have an Oracle database, then these columns of low selectivity are ideal candidates for Bitmap indexes.// 只有几个不同的值供选择。例如,一个“类型”列中,只有四个不同的值(A,B,C,和D)。该索引是一个低效的选择。如果你有一个Oracle数据库,那么为这些选择范围小的的列建立位图索引是更好的选择。

§ Occur in WHERE clauses but within functions other than MIN or MAX.//当在where 条件中使用了除了MIN和MAX以外的函数。

Indexes in these cases waste space and slow down the load process.

小结:

B树索引经过大量的插入删除操作以后一个是容易使树不平衡,再一个是删除后空间不回收。所以定期重建索引非常有必要。

二、      位图索引

位图索引:

(位图索引结构图)

 

位图索引优点:

(1)        用一个位来表示一个索引的键值,节省了存储空间;

(2)        对and,or或=的查询条件,位图索引查询效率很高,计算机善于处理0,1数据。

什么时候适合使用位图索引:引用一下oracle官方文档

Candidates for Bitmap Indexes

Bitmap indexes are most advantageous whenever the cardinality of the index is less than one percent, or lowly-selective. This criterion is nearly the opposite of the guideline for B-Tree indexes.

Look for cases where:

§ A query constrains multiple columns which have few distinct values in their domains (large number of duplicate values).// 一个查询条件包含多个列,并且要创建索引的列只有几个不同的值(拥有大量重复值)。

§ A large number of rows satisfy the constraints on these columns.//大量的数据符合这些列上的约束条件。

§ Bitmap indexes have been created on some or all of these columns. //位图索引可以创建在一个、多个或全部列上。

§ The referenced table contains a large number of rows. //被引用的表包含了非常多的行。

注意:

CAUTION: Bitmap indexes should be used only for static tables and are not suited for highly volatile tables in online transaction processing systems.//位图索引只能用在相对稳定的表,不适合用在表数据频繁变化的联机系统中。

什么时候不适合创建位图树索引:

(1)        频繁进行插入或更新的表;

(2)        列值很多,可选范围很大的表;


因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务