ORACLE数据索引使用---官方文档理解

http://docs.oracle.com/cd/E05554_01/books/AnyTuning/AnyTuning_DBservers6.html

B-Tree Indexes


Generally speaking, in an online transaction processing environment, a B-tree is most effective when it is highly selective. When this is the case, the index is said to have "high selectivity" because a low percentage of rows in the table have the same index key value.

General Guidelines

With high selectivity in mind, evaluate creating B-tree indexes on columns that:

§     Occur frequently in WHERE clauses//经常出现在where语句当中

§     Often used to join tables (include aggregate tables)//通常用于表的连接操作(包括表的聚合操作)

§     Occur in ORDER BY clauses (the index can facilitate ordering)//经常用来进行排序(该索引通常会被使用)

§     Occur in a foreign key reference constraint//被用来做为外键约束

§     Used to enforce PRIMARY KEY and UNIQUENESS constraints//做为主键或是唯一约束

You can also look at your query workload and identify families of queries that include tight table constraints on tables (point, multi-point, and range queries).

When you have star schemas, both DB2 and Oracle database servers can exploit multi-column B-Tree indexes to accelerate join processing when they are created over the foreign key reference columns of "fact" tables. DB2 and Oracle can also accelerate star join operations when single column indexes are created on the fact table's foreign key reference columns. In the Oracle case, these indexes are specialized Bitmap indexes which are used by the server's star transformation algorithm. See Bitmap Indexes.

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.// 只有几个不同的值供选择。例如,一个“类型”列中四个不同的值ABCD该索引是一个低效的选择。如果你有一个Oracle数据库,那么为这些选择范围小的的列建立位图索引是更好的选择。

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

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

Siebel Recommended Methodology

You can follow the methodology described in the following example procedure to create new indexes to speed up a slow running report. The slow running report used in this example is "Abandoned Carts Detail."

http://docs.oracle.com/cd/E05554_01/books/AnyTuning/AnyTuning_DBservers7.html#wp132447

Bitmap Indexes


Oracle supports bitmap indexes which are often useful in many situations where B-tree indexes are not optimal. Namely, for columns which have a large number of duplicate values. For example, a Size column that contains only five distinct values (tiny, small, medium, large, grand).

Oracle's "star transformation algorithm" uses bitmap indexes to join a fact table to its dimensions when they exist on the foreign key constraint columns in a fact table. Actually, this algorithm is robust enough to use a combination of bitmap and B-tree indexes. IBM DB2 takes advantage of this technology in selected situations by dynamically building bitmaps from a single-column B-tree to join tables. Unlike Oracle, however, these are highly specialized cases.

Entries in a bitmap index consist of a search key value and a bitmap which describes rows that contain the search key value. Each bit in the map corresponds with a row in the table, and a bit on signals a row that contains the value in the search key. key value.

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. //被引用的表包含了非常多的行。

Given this kind of scenario, the server can evaluate the constraints by ANDing the bitmaps and potentially eliminate a large number of rows without ever accessing a row in the table.

The Oracle database server can also generate query execution plans to join a fact table to its dimensions using its star transformation algorithm when bitmap indexes exist on the fact table foreign key reference columns. When this execution plan is the least costly, the server joins the tables using the bitmap indexes.

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

Also, the Oracle optimizer generates query plans only when the cost-based optimizer has been enabled.

To create a bitmap index, use the "bitmap" keyword:

create bitmap index w_srvreq_d_m2 on w_srvreq(area_I)
nologging tablespace idx pctfree 0 ;

You can analyze a bitmap index just like you do any other index:

analyze index w_srvreq_d_m2 compute statistics ;

你可能感兴趣的:(oracle 索引)