Presentation is loading. Please wait.

Presentation is loading. Please wait.

Index An index is a performance-tuning method of allowing faster retrieval of records. An index creates an entry for each value that appears in the indexed.

Similar presentations


Presentation on theme: "Index An index is a performance-tuning method of allowing faster retrieval of records. An index creates an entry for each value that appears in the indexed."— Presentation transcript:

1 Index An index is a performance-tuning method of allowing faster retrieval of records. An index creates an entry for each value that appears in the indexed columns. By default, Oracle creates B-tree indexes.

2 Index An index is an optional structure, associated with a table, that can sometimes speed data access. Indexes are one of many means of reducing disk I/O.

3 Index Indexes are schema objects that are logically and physically independent of the data in the objects with which they are associated. Thus, an index can be dropped or created without physically affecting the table for the index.

4 Index If you drop an index, then applications still work. However, access of previously indexed data can be slower. The absence or presence of an index does not require a change in the wording of any SQL statement. An index is a fast access path to a single row of data. It affects only the speed of execution.

5 Index The database automatically maintains and uses indexes after they are created. The database also automatically reflects changes to data, such as adding, updating, and deleting rows, in all relevant indexes with no additional actions required by users.

6 Index Retrieval performance of indexed data remains almost constant, even as rows are inserted. However, the presence of many indexes on a table degrades DML performance because the database must also update the indexes.

7 Create an Index CREATE INDEX index_name
ON table_name (column1, column2, . column_n)

8 Examples CREATE INDEX supplier_idx ON supplier (supplier_name);
ON supplier (supplier_name, city); ON supplier (supplier_name, city)

9 Create a Function-Based Index
In Oracle, you are not restricted to creating indexes on only columns. You can create function-based indexes. CREATE INDEX index_name ON table_name (function1, function2, . function_n)

10 Create a Function-Based Index
CREATE INDEX supplier_idx ON supplier (UPPER(supplier_name)); In this example, we've created an index based on the uppercase evaluation of the supplier_name field.

11 B-Tree Index B-trees, short for balanced trees, are the most common type of database index. A B-tree index is an ordered list of values divided into ranges. A B-tree index has two types of blocks: branch blocks for searching and leaf blocks that store values.

12 Image Source : Oracle Inc.
A B-tree index has two types of blocks: branch blocks for searching and leaf blocks that store values.

13 B-Tree Index A B-tree index is balanced because all leaf blocks automatically stay at the same depth. Thus, retrieval of any record from anywhere in the index takes approximately the same amount of time. 

14 B-Tree Index The height of the index is the number of blocks required to go from the root block to a leaf block.  The branch level is the height minus 1. In Last Example, the index has a height of 3 and a branch level of 2.

15 B-Tree Index The leaf blocks contain every indexed data value and a corresponding rowid used to locate the actual row. Each entry is sorted by (key, rowid). Within a leaf block, a key and rowid is linked to its left and right sibling entries. The leaf blocks themselves are also doubly linked. In Last Example the leftmost leaf block (0-10) is linked to the second leaf block (11-19).

16 Bitmap Indexes Bitmap indexes use bitmaps to indicate the value of the column being indexed. This is an ideal index for a column with a low cardinality and a large table size. These indexes are not usually appropriate for tables with heavy updates. Bitmap Indexes are well suited for data warehouse applications. Source: Expert Oracle Database 11g Administration, By Sam R. A, APress

17 Bitmap Indexes Bitmap indexes consist of a bit stream (0 or 1) for each column in the index. Bitmap indexes are very compact compared to the normal B-tree indexes. B*Tree Bitmap Good for high-cardinality data Good for low-cardinality data Good for OLTP databases Good for data warehousing applications Use a large amount of space Use relatively little space Easy to update Difficult to update Source: Expert Oracle Database 11g Administration, By Sam R. A, APress

18 Bitmap Index CREATE BITMAP INDEX gender_idx ON employee(gender)
Bitmap index is not a smart alternative for tables that involve large numbers of inserts, deletes, and updates.

19 Bitmap Index High-cardinality refers to columns with values that contains very uncommon values: Customer Name Address ID User Name Source: Expert Oracle Database 11g Administration, By Sam R. A, APress

20 Bitmap Index Low-cardinality refers to columns with few unique values.
Examples are Gender Field Category IsPH IsActive Order Status

21 Create a Function-Based Index
However, to be sure that the Oracle optimizer uses this index when executing your SQL statements, be sure that UPPER(supplier_name) does not evaluate to a NULL value. To ensure this, add UPPER(supplier_name) IS NOT NULL to your WHERE clause as follows:

22 Create a Function-Based Index
SELECT supplier_id, supplier_name, UPPER(supplier_name) FROM supplier WHERE UPPER(supplier_name) IS NOT NULL ORDER BY UPPER(supplier_name);


Download ppt "Index An index is a performance-tuning method of allowing faster retrieval of records. An index creates an entry for each value that appears in the indexed."

Similar presentations


Ads by Google