Beruflich Dokumente
Kultur Dokumente
Introduction
Why do we need tree indexes? To reduce the time taken to search for a record. Consider a query "Find all students who have got attendance less than 70%". In order to find the records, we must first employ a binary search and scan the file from that point. Instead, indexing can be used. Keep a second file index file with <first key on page, pointer to page>. Since the size of the index file is small searching the first page may become fast. This concept can be further extended recursively (several levels) which leads to tree indexes.
ISAM is a static index structure effective when frequent updates are not done. Unsuitable for frequent growth / shrink of files. ISAM Structure:
Each tree node is a disk page. All the data resides in the leaf pages. When the file is created, all leaf pages are allocated sequentially and sorted on the search key value. Overflow pages may be created, if needed.
Example
Non-leaf Pages
Data Pages
Overflow Pages
20 33
10 15
20 27
33 37
40 46
51 55
63 97
23
B+ trees are dynamic structures. It is a balanced tree. The leaf nodes contain the data pages and the internal nodes are to guide the search. A 50% occupancy in each node with no overflow pages. Searching for record is to traverse the tree from root to the leaf node. d order of the tree and every node contains m entries. Or, d m 2d. Suppose, if d = 2, then each node can have 2 to 4 entries. For root node: 1 m 2d
B+ Trees
Example - Find
13 17
19
14 16
24
20 22
24
30
33 27 29
34
38
39
Key = 5 Left-most pointer. Key = 15 Second pointer from left. But, key not found. Key = 24 Fourth pointer and the key is found
INSERT
Every data value must exist at the leaf level However, only some values exist in internal nodes to guide the search
INSERT: Example-1
Assume: m = 2. That is, we can have a maximum of 1 to 2 keys in each node. All leaf nodes are connected as a doubly linked list (not shown in the figure). Insert sequence:
8, 5, 1, 7, 3, 12, 9, 6 5 5 8
--------------------------------------------------------------------------------------------------
(3) Insert 7:
5 1 5 7 8
(4) Insert 3:
3 1 3 5
5
7 8
5 3 8 5 7 8 12
(6) Insert 9: Simply insert into the node containing key value 12. (7) Insert 6: 5
3
1 3 5
7 6 7
8
8
9 12
Example - Delete
(1) Key = 19: No need for adjustment (2) Key = 20: Redistribute (22, 24) and (27, 29) (3) Key = 24: Merge (22) and (27, 29) yielding (22, 27, 29)
17
5 13 24 30
14
16
19 20 22
24
27
29
33
34
38
39
Example Delete
(3) Key = 24: Merge (22) and (27, 29) yielding (22, 27, 29) Partial tree showing deletion of 24.
17
5 13 30
14
16
22 27 29
33
34
38
39
13
17
30
14
16
22 27 29
33
34
38
39