Introduction to Oracle B Tree Index
B-Tree is also called as bitmap indexes and it is function based. The function-based index can be created by the user that means it index includes columns or we can say that upper function or included expression. Basically B tree is a balanced tree and it is not a binary tree, once we created B tree index then database automatically maintained index. In this type of tree we need to maintain a balance tree so that every insert, update and delete operation we keep the index of B tree. In oracle by default oracle creates B tree index, in oracle database management B tree starts with only two nodes such as one for header and one for leaf.
create index specified index name on specified table name (colm name1, colm name2, ……..colm N);
In the above syntax we use create index statement to create new index, here specified index name means new index name that we need to create , on is the keyword to gives the reference to database table, specified table name means actual table name in database and last part of syntax contain column names from specified table
How does B Tree index work in Oracle?
B Tree index is a top down approach, the height of the tree is used as an index that should change when we perform different operations such as insert, update and delete. Basically index is maintained in sequence of key value and there is no any storage clause used with index. If there is no room in an index lead node for an additional key value then we need to go sequentially at that time leaf node is split into two sections that one for leaf and remaining node is inserted into the sequence.
The node address is called DBS or we can also call the database block address. Basically DBS files resides in physical location and that file contain the File# and Block#, where File# is used for physical database file and Block# is used for data that is in file. The lead node is connected to the next node in proper sequence and that gives the index in logical order, that logical index stored on the assigned disk. This allows oracle to scan and search in descending order.
In a unique lookup passes through the branch levels to the leaf node and finds the individual value and each key value ROWID, the ROWID is a unique id and it also has a physical location. In oracle scan operation pass through the branch levels to find the first value in a given range then it reads across the leaf nodes until the range is satisfied.
ROWID contains the following parameters as follows.
- File# is used for physical database files.
- Block# data in blocks or we can say nodes.
- Row# it pointer within the specified table.
This is an important feature of oracle and it is helpful to find blocks or nodes in the oracle database in a very effective manner.
The following diagram shows the internal structure of the B Tree index.
B Tree Index Split
See insertion operation indexes are maintained in a sequential manner if there is no node in leaf node for a newly inserted row at that time leaf node or block are split into two leaf nodes for either insert or update operation. The half part of row one leaf node and remaining part of row put into new leaf node and top side of tree operation required extra transaction to archive this work for oracle RDBMS. Downsides of the tree split are not good for performance because of the physical I/O process.
Now let’s see the different examples of B Tree index as follows.
First, see how we can create indexes as follows.
create index emp_index on empp (emp_id, salary);
In the above example, we created emp_index by using the create index statement as shown. The end output of the above query we illustrate by using the following snapshot.
We have already created table names as empp and now we implement Full Index Scan as follows.
select emp_id, emp_dept, salary from empp where salary > 10000 order by emp_dept, emp_id;
In the above example we use select, where and order by clause to implement Full Index Scan. Considering emp_id and salary are the composite keys in the index, oracle database performs a full scan of the index, it reads in sorted order. The end output of the above query we illustrate by using the following snapshot.
Fast Full Index Scan
select emp_dept, salary from empp;
In the above example we try to implement a fast full index scan. In which databases access the record in the index itself without accessing the table and there is any particular order. The end output of the above query we illustrate by using the following snapshot.
Index Unique Scan
select * from empp where emp_id = 4;
In the above example we implement Index Unique Scan it must have either 0 or 1 rowid associated with an index key. The end output of the above query we illustrate by using the following snapshot.
Now assume that the emp_id column is the primary and is indexed with the following entries.
Rules and regulation for B Tree Index
Now let’s see the rules and regulation for B Trees index as follows.
- All leaves of B Tree we will create at the same level of tree.
- In B Tree we determine the degree of the tree and it is denoted by using d.
- The value of the left node of B Tree is always less than the value of the right node that means we can sort all nodes in ascending order from left to right.
- We can calculate maximum child node by using following formula d -1
- In B Tree each node except root node must be contain minimum keys such as d/2-1
- The maximum number of child nodes is equal to the degree of the tree.
We hope from this article you have understood about the Oracle B Tree Index. From this article, we have learned the basic syntax of the B Tree Index and we also see different examples of the B Tree Index. From this article, we learned how and when we use Oracle B Tree Index.
This is a guide to Oracle B Tree Index. Here we discuss the basic syntax of the B Tree Index and we also see different examples. You may also have a look at the following articles to learn more –