Docsity

Tree Structured Indexes - Lecture Slides | EECS 484, Exams of Database Management Systems (DBMS)

Toggle sidebar
bg1
1
2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 1
Tree-Structured Indexes
Chapter 10
2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 2
Index Design Space
Data Entry (k*) Contents
Organization
Structure for k*
• Hash-based
+ Equality search
• Tree-based
+ Range, equality search
B+Tree (dynamic)
ISAM (static)
1. Actual Data record
-index = file!
2. <k, rid>
-actual records in a diffe rent file
3. <k, list of rids>
2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 3
Motivation
•Range and equality searches very common
•Can scan heap file, but this is expensive
•Goal:
Create a dynamic index structure
that allows for efficient evaluation and
equality and range queries
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Tree Structured Indexes - Lecture Slides | EECS 484 and more Exams Database Management Systems (DBMS) in PDF only on Docsity!

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 1

Tree-Structured Indexes

Chapter 10

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 2

Index Design Space

Data Entry (k*) Contents

Organization

Structure for k*

  • Hash-based

+ Equality search

  • Tree-based

+ Range, equality search

B+Tree (dynamic)

ISAM (static)

1. Actual Data record

  • index = file!

2. <k, rid>

  • actual records in a different file

3. <k, list of rids>

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 3

Motivation

• Range and equality searches very common

• Can scan heap file, but this is expensive

• Goal: Create a dynamic index structure

that allows for efficient evaluation and

equality and range queries

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 4

B+ Tree

• Height-balanced (dynamic) tree structure

• Minimum 50% occupancy (except for root).

Each node contains d <= m <= 2 d entries.

The parameter d is called the order of the tree.

• Supports equality and range-searches efficiently.

Index Entries

(Direct search)

Data

Entries

Index Entries

Entries in the index

(i.e. non-leaf) pages:

(search key value, pageid)

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 5

Example B+ Tree

  • Search: Starting from root, examine index entries in non-leaf

nodes, and traverse down the tree until a leaf node is reached

  • Non-leaf nodes can be searched using a binary or a linear search.
  • Search for 5, 15, all data entries >=24*

Root

Height = 1

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 6

B+-tree Page Format

Leaf Page

R

K

R

K

K

n

P

n+

data entries (Alternative 2)

record 1 record 2

Next

Page

Pointer

R

n

record m

P

Prev

Page

Pointer

Non-leaf

Page

P

K

P

K

P

K

m

P

m+

index entries

Pointer to a

page with

Values < K 1

Pointer to a page

with values s.t.

K 1

≤ Values < K 2

Pointer to a

page with

values ≥K m

Pointer to a page

with values s.t.,

K 2

≤ Values < K 3

P

m

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 10

A Note on Order

• Order ( d ) concept replaced by physical space

criterion in practice ( at least half-full).

  • Index (i.e. non-leaf) pages can typically hold many

more entries than leaf pages.

  • Leaf pages could have actual data records
  • Variable sized records and search keys mean different

nodes will contain different numbers of entries.

  • Even with fixed length fields, multiple records with the

same search key value ( duplicates) can lead to

variable-sized data entries (if we use Alternative (3)).

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 11

B+ Tree Operations

• Search

• Equality

• Range

• Insert data entry

• Delete data entry

• Bulk load

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 12

B+-Tree: Inserting a Data Entry

• Find correct leaf L.

• Put data entry onto L.

  • If L has enough space, done!
  • Else, must split L (into L and a new node L2)
    • Redistribute entries evenly, copy up middle key.
    • Insert index entry pointing to L2 into parent of L.

• This can happen recursively

  • To split index node, redistribute entries evenly, but

push up middle key. (Contrast with leaf splits.)

• Splits “grow” tree; root split increases height.

  • Tree growth: gets wider or one level taller at top.

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 13

Inserting 8* into B+ Tree

Root

Entry to be inserted in parent node

Copied up (and continues to

appear in the leaf)

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 14

Inserting 8* into B+ Tree

Insert in parent node.

Pushed up (and only appears once in

the index)

Minimum occupancy is guaranteed in

both leaf and index page splits

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 15

Root

Inserting 8* into B+ Tree

  • Root was split: height increases by 1
  • Could avoid split by re-distributing entries with a sibling
    • Sibling: immediately to left or right, and same parent

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 19

Deleting 22* and 20*

• Deleting 22* is easy.

• Deleting 20* is done with re-distribution.

Notice how middle key is copied up.

Root

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 20

... And Then Deleting 24*

• Must merge.

• In the non-leaf node,

toss the index entry

with key value = 27

Can this

merge?

Root

 Pull down of

index entry

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 21

Non-leaf Re-distribution

• Tree during deletion of 24*.

• Can re-distribute entry from left child of

root to right child.

Root

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 22

After Re-distribution

• Rotate through the parent node

• It suffices to re-distribute index entry with key 20;

For illustration 17 also re-distributed

Root

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 23

B+-Tree Deletion

• Try redistribution with all siblings first, then

merge. Why?

• Good chance that redistribution is possible

(large fanout!)

• Only need to propagate changes to parent node

• Files typically grow not shrink!

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 24

B+ Tree Operations

• Search

• Equality

• Range

• Insert data entry

• Delete data entry

• Bulk load

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 28

Summary

• Tree-structured indexes are ideal for range-

searches, also good for equality searches.

• B+ tree is a dynamic height-balanced index

structure.

• Inserts/deletes/search costs O(log

F

N).

• High fanout ( F ) means depth rarely more than 3

or 4.

• Most widely used index in database management

systems because of its versatility. One of the

most optimized components of a DBMS.

2/17/09 EECS 484: Database Management Systems, Kristen LeFevre 29

Announcements

• Optional Exercises: 10.1, 10.5, 10.

• Reminder: Please fill out midterm course

feedback online :)