|
An index is, typically, a tree structure that allows a query to directly access a row in a table. Indexes can be classified based on their logical design or on the physical implementation. Logical Index ClassificationsThe logical classification groups indexes together based on an application perspective of the index. The following list describes the various logical classification indexes:
Physical Index ClassificationsThe physical classification of an index is based on the way the indexes are stored. The next few sections cover physical index classifications in more detail. PartitionedPartitioned indexes are used for large tables as a means to store the index entries corresponding to an index in several segments. Partitioning of indexes allows an index to be spread across several different tablespaces, thereby decreasing contention for index lookup and increasing manageability. An index partition can be created on a one-to-one basis with a table partition. NonpartitionedNonpartitioned indexes are the norm and are created in a single tablespace. They are covered in the remainder of this chapter. B-TreeAlthough the vast majority of indexes use a B-tree structure, the term B-tree (short for binary tree) is typically associated with indexes that store a list of ROWIDs for each key. The top of the B-tree index is the root, which contains entries that point to the next level in the index. One level farther down are branch blocks that in turn point to blocks at the next level in the index. This continues until the lowest level is reached, where there are leaf nodes, each containing index entries that point to rows in the table. Leaf blocks are doubly linked to facilitate scanning the index in an ascending or descending fashion. Ascending is the typical means of storing and accessing. Figure 13.1 shows, graphically, what a B-tree structure would look like. Although this is a simple example, you can see how each leaf is doubly linked in order, so you can traverse the tree in obverse and inverse order. Figure 13.1. A typical B-tree structure.Leaves contain the index entries that have the following components:
Oracle maintains all the indexes whenever DML operations are carried out on the table. Whenever there is an insertion of an index due to an insertion of a new index value in the table, the index entry is inserted into the appropriate block. If deletions occur in the table that result in a deletion in the index, the index entry is logically deleted. The space consumed by the index entry will not be available for reuse until all the entries in the given block have been deleted. Updates that occur to key columns result in a logical delete and a physical insert to the index. PCTFREE for dictionary managed tablespaces has no effect on the index except at the time of creation. New entries may be added to index blocks even if the amount of space remaining is less than that specified by PCTFREE. B-tree indexes are highly suited for high cardinality columns. Updates on B-tree indexes are relatively inexpensive; however, they are somewhat inefficient for queries that use the OR operator in the predicate. B-tree indexes are useful for OLTP environments. BitmapIt is often the case that bitmap indexes are more advantageous than B-tree indexes, depending on the situation. If a table has millions of rows but the key columns have a low cardinality (very few distinct values in relation to the number of rows), bitmap indexes may be preferable to B-tree indexes. For example, values such as gender, marital status, or region of the country may all be good candidates for bitmap indexes. Examples of times when bitmap indexes are appropriate are as follows:
The structure of a bitmap index is organized in a B-tree fashion; however, the leaf nodes each store a bitmap for each key value instead of a listing of ROWIDs. Each bit in the bitmap corresponds to one possible ROWID, and if the bit corresponding to the ROWID is set, the row with that ROWID contains the key value. Each leaf node contains an entry header that contains the number of columns and lock information. It also contains key values consisting of length and value pairs for each key column; a start ROWID, which contains a file number, a block number, and a row number; and an end ROWID with similar information. Finally, it contains a bitmap segment consisting of a string of bits with the corresponding bit being set whenever the corresponding row contains a key value for that bit and unset when the row does not contain a key value. Oracle has patented the compression algorithm used to store these bitmaps. The bitmap's B-tree is used to locate the leaf nodes that contain bitmap segments for a given value of the key. The start ROWID and the bitmap segments are used together to locate the rows that contain the given key value. Whenever changes are made to the key columns of the table, the associated bitmaps must be altered correspondingly. These alterations result in the relevant bitmap segments being locked. These locks are acquired on the entire bitmap segment, and that means that any row that happens to be covered by any segment in the bitmap cannot be updated by any other transactions until the locking transaction ends. Bitmap indexes are useful for low cardinality columns. Updates to key columns are expensive; however, bitmap indexes are efficient for queries that use the OR operator in the predicate. Oracle can use two bitmap segments to facilitate a bitwise Boolean comparison and get a resulting bitmap; this means that Oracle can use bitmaps efficiently in queries that use Boolean in the predicate. They are useful for data warehouse environments because the update of the bitmap occurs so infrequently. Now that we have covered the kinds of indexes, it is time to look at what is involved in creating them. |
|