Types of Oracle database indexes and their applicable scenarios

The choice of index type, the choice of index column, and the type of connection between tables are of great importance for achieving optimal performance.

From the perspective of the algorithm dimension , the index can be broadly divided into: B-tree index (the structure used by the oracle index) , bitmap index , and index organization table .

  • B-tree index : implements a tree structure similar to inverted, including root nodes, branch nodes, and leaf nodes, and uses a tree traversal algorithm to search for column values. The leaf node contains a pair of values ​​(index value, row number rowid), the index value corresponds to the index key column, and the row number indicates the memory address of the row in the data block in the table; the branch node contains the directory of the leaf and the leaf node stored in it The value range of; the root node contains the branch node directory and the value range contained in these branch nodes.

  • Bitmap index : suitable for columns that are not frequently updated, inserted, or deleted. It is more suitable for data warehouse tables that have fewer unique values ​​for read-only operations (for example, the gender column is a good example, and there are only fewer unique values ​​such as men and women).

  • Index-organized table : The table itself is organized as an index (column value, logical row number), all columns are stored in the index tree itself, data rows accessed using the primary key will only include index access; all columns can be indexed Structure to obtain, thus avoiding table access and minimizing the number of accesses. It is suitable for the following characteristics: 1. The length of the data row is short; 2. Most of the tables that use the primary key column for access


From the perspective of partition , the index can be divided into: range partition ( local index and global index ) and hash partition

  • Local partition index : Use the local keyword to build, and its partition boundary is the same as the table. Simply put, there is an index partition connected to each table partition. If the SQL statement declares the predicate on the partition key column, the execution plan only needs to access one or a few index partitions; if the execution plan searches in the least partition, the performance will be improved.

  • Global partition index : Use the global keyword to create, the index partition and the table partition boundary do not have to match, and the partition key of the table and index can also be different. The maintenance of the global partition index needs to obtain a higher-level lock of the table, thereby reducing the availability of the application. On the contrary, the maintenance of the local index can only be done on the partition, only affecting the corresponding table partition.

    Note: Range partitioning requires the creation of new partitions on a regular basis.

  • Hash index : Use a hash algorithm to hash the value of the partition index key column to determine the partition where the data row is stored. This scheme is suitable for columns of sequentially generated values, because the hash values ​​are relatively evenly distributed, and the total number of data rows in each partition is basically the same.

    Note:
    1. Hash partitioning does not need to create new partitions regularly. The total number of partitions is determined at the beginning, and the subsequent new data will be hash partitioned to each partition.

    2. Hash partitioned tables and indexes are very effective in coping with performance problems related to concurrency caused by unique indexes and primary key indexes. Because basically, the current rightmost leaf block of the index will be the main resource contention point. Through the hash partition, the latest data is hashed to each partition.
    3. Partition key function: ora_hash(column_name, 31, 0) will return the partition ID.

Guess you like

Origin blog.csdn.net/WziH_CSDN/article/details/115019510