B -Trees - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

B -Trees

Description:

B+-Trees Adapted from Mike Franklin Example Tree Index Index entries: they direct search for data entries in leaves. – PowerPoint PPT presentation

Number of Views:8
Avg rating:3.0/5.0
Slides: 22
Provided by: amoldes
Learn more at: http://www.cs.umd.edu
Category:
Tags: tree | trees

less

Transcript and Presenter's Notes

Title: B -Trees


1
B-Trees
  • Adapted from Mike Franklin

2
Example Tree Index
  • Index entriesltsearch key value, page idgt they
    direct search for data entries in leaves.
  • Example where each node can hold 2 entries

3
ISAM
  • Indexed Sequential Access Method
  • Similar to what we discussed in the last class

Root
40
Index
Pages
20
33
51
63
Primary
Leaf
46
55
10
15
20
27
33
37
40
51
97
63
Pages
41
Overflow
Pages
4
Example B Tree
  • Search begins at root, and key comparisons direct
    it to a leaf.
  • Search for 5, 15, all data entries gt 24 ...
  • Based on the search for 15, we know it is not
    in the tree!

5
B Tree - Properties
  • Balanced
  • Every node except root must be at least ½ full.
  • Order the minimum number of keys/pointers in a
    non-leaf node
  • Fanout of a node the number of pointers out of
    the node

6
B Trees in Practice
  • Typical order 100. Typical fill-factor 67.
  • average fanout 133
  • Typical capacities
  • Height 3 1333 2,352,637 entries
  • Height 4 1334 312,900,700 entries
  • Can often hold top levels in buffer pool
  • Level 1 1 page 8 Kbytes
  • Level 2 133 pages 1 Mbyte
  • Level 3 17,689 pages 133 MBytes

7
B Trees Summary
  • Searching
  • logd(n) Where d is the order, and n is the
    number of entries
  • Insertion
  • Find the leaf to insert into
  • If full, split the node, and adjust index
    accordingly
  • Similar cost as searching
  • Deletion
  • Find the leaf node
  • Delete
  • May not remain half-full must adjust the index
    accordingly

8
Insert 23
No splitting required.
9
Insert 8
10
Example B Tree - Inserting 8
  • Notice that root was split, leading to increase
    in height.
  • In this example, we can avoid split by
    re-distributing entries however,
    this is usually not done in practice.

11
Data vs. Index Page Split (from previous example
of inserting 8)
Data Page Split
  • Observe how minimum occupancy is guaranteed in
    both leaf and index pg splits.
  • Note difference between copy-up and push-up be
    sure you understand the reasons for this.

Index Page Split
12
Delete 19
13
Delete 20 ...
14
Delete 19 and 20 ...
  • Deleting 19 is easy.
  • Deleting 20 is done with re-distribution. Notice
    how middle key is copied up.
  • Further deleting 24 results in more drastic
    changes

15
Delete 24 ...
No redistribution from neighbors possible
16
Deleting 24
  • Must merge.
  • Observe toss of index entry (on right), and
    pull down of index entry (below).

30
39
22
27
38
29
33
34
Root
13
5
30
17
3
39
2
7
22
38
5
8
27
29
33
34
14
16
17
Example of Non-leaf Re-distribution
  • Tree is shown below during deletion of 24. (What
    could be a possible initial tree?)
  • In contrast to previous example, can
    re-distribute entry from left child of root to
    right child.

Root
22
30
17
20
13
5
18
After Re-distribution
  • Intuitively, entries are re-distributed by
    pushing through the splitting entry in the
    parent node.
  • It suffices to re-distribute index entry with key
    20 weve re-distributed 17 as well for
    illustration.

Root
17
30
22
13
5
20
39
7
5
8
2
3
38
17
18
33
34
22
27
29
20
21
14
16
19
Primary vs Secondary Index
  • Note We were assuming the data items were in
    sorted order
  • This is called primary index
  • Secondary index
  • Built on an attribute that the file is not sorted
    on.

20
A Secondary B-Tree index
Root
17
30
22
13
5
20
7
5
8
2
3
17
18
22
27
29
20
21
14
16
2 16 5 39
21
Primary vs Secondary Index
  • Note We were assuming the data items were in
    sorted order
  • This is called primary index
  • Secondary index
  • Built on an attribute that the file is not sorted
    on.
  • Can have many different indexes on the same file.

22
More
  • Hash-based Indexes
  • Static Hashing
  • Extendible Hashing
  • Read on your own.
  • Linear Hashing
  • Grid-files
  • R-Trees
  • etc
Write a Comment
User Comments (0)
About PowerShow.com