0% found this document useful (0 votes)
14 views

Lecture12 6 Slides Per Page

This document discusses maintaining a sequential set of records using a B+ tree structure. It presents two key aspects: 1) Maintaining the sequential order of records while allowing for insertions and deletions. This is done by organizing records into blocks, splitting or merging blocks as needed to handle overflow or underflow. 2) Adding an index set to the sequence to allow for indexed access and retrieval of individual records. Examples of applications like a student record system and credit card system are provided. The techniques of block splitting on insertion, and block merging or redistribution on deletion are described.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Lecture12 6 Slides Per Page

This document discusses maintaining a sequential set of records using a B+ tree structure. It presents two key aspects: 1) Maintaining the sequential order of records while allowing for insertions and deletions. This is done by organizing records into blocks, splitting or merging blocks as needed to handle overflow or underflow. 2) Adding an index set to the sequence to allow for indexed access and retrieval of individual records. Examples of applications like a student record system and credit card system are provided. The techniques of block splitting on insertion, and block merging or redistribution on deletion are described.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Content

Content
► Maintaining a sequence set
► A simple prefix B+ Tree

12 B+Trees ► Simple Prefix B+ Tree Maintenance: Insertions and

B+Trees 12
Deletions

Copyright © 2004, Binnur Kurt File Organization 310

Motivation
Motivation Example
Example of
of Applications
Applications
►Some applications require two views of a file: ► Student record system in a university
– Indexed view: access to individual records
– Sequential view: batch processing when posting
grades or when fees are paid
B+Trees 12

B+Trees 12

► Credit card system


– Indexed view: interactive check of accounts
– Sequential view: batch processing of payment slips
► We will look at the following two aspect of the problem:
1. Maintaining a sequence set: keeping records in
sequential order
2. Adding an index set to the sequence set
File Organization 311 File Organization 312

Maintaining
Maintaining aa Sequence
Sequence Set
Set Example
Example
► Sorting and re-organizing after insertions and deletions is ►Block Size = 4
out of question ►Key = Last Name
► We organize the sequence set in the following way
– Records are grouped in blocks
B+Trees 12

B+Trees 12

Forward Pointer
– Blocks should be at least half full
– Link fields are used to point to the preceding block Backward Pointer
and the following block (similar to doubly linked list)
– Changes (inserted/deletion) are localized into blocks ADAMS... BIXBY... CARSON... COLE...
by performing:
1. Block Splitting when insertion causes overflow DENVER... ELLIS...
2. Block Merging or Redistribution when deletion
causes underflow
File Organization 313 File Organization 314
Insertion
Insertion with
with Overflow
Overflow Deletion
Deletion with
with Merging
Merging

ADAMS... BIXBY... CARSON... COLE... ADAMS... BAIRD... BIXBY... BOONE...

►Insert “BAIRD...” BYNUM... CARSON... CARTER...


B+Trees 12

B+Trees 12
DENVER... ELLIS...
ADAMS... BAIRD... BIXBY...
COLE... DAVIS...
CARSON... COLE...
►Delete “DAVIS...”

File Organization 315 File Organization 316

Deletion
Deletion with
with Merging
Merging (Con’t)
(Con’t) Delete
Delete “BYNUM”,
“BYNUM”, then
then Delete
Delete “CARTER”
“CARTER”

ADAMS... BAIRD... BIXBY... BOONE... ADAMS... BAIRD... BIXBY... BOONE...

BYNUM... CARSON... CARTER... CARSON...


B+Trees 12

B+Trees 12

COLE... DENVER... ELLIS... COLE... DENVER... ELLIS...

►Block is available for re-use

File Organization 317 File Organization 318

Solution
Solution ## 11 Solution
Solution ## 2:
2: Deletion
Deletion with
with Redistribution
Redistribution
►We can merge Block and
ADAMS... BAIRD... BIXBY...
ADAMS... BAIRD... BIXBY... BOONE...
B+Trees 12

B+Trees 12

BOONE... CARSON...

COLE... DENVER... ELLIS...


CARSON... COLE... DENVER... ELLIS...

File Organization 319 File Organization 320


Advantages
Advantages and
and Disadvantages
Disadvantages of
of Sequence
Sequence Set
Set Choosing
Choosing Block
Block Size
Size
►Advantages ►Main memory constraints (must hold at least 2 blocks)
– No need to re-organize the whole file after ►Avoid seeking within a block (e.g., in sector formatted
insertions/deletions disks choose block size equal to cluster size).
►Disadvantages
B+Trees 12

B+Trees 12
– File takes more space than unblocked files (since
blocks may be half full)
– The order of the records is not necessarily physically
sequential (we only guarantee physical sequentiality
within a block)

File Organization 321 File Organization 322

Adding
Adding an
an Index
Index Set
Set to
to the
the Sequential
Sequential Set
Set The
The Simple
Simple Prefix
Prefix B+
B+ Tree
Tree
►Index will contain SEPERATORS instead of KEYS ►The simple prefix B+ tree consists of
ADAMS... ............. .............. BERNE... – Sequence Set
BO – Index Set:
Set similar to a B-tree index, but storing the
B+Trees 12

B+Trees 12

BOLEN...
BO ............. .............. CAGE... shortest separators for the sequence set.
CAM
CAMP...
CAM ................ ............... DUTTON...
E
EMBRY... ............. ............ EVANS...
F
FABER... ................ ............... FOLK...
FOLKS
FOLKS...
FOLKS ............. ............ GADDIS...
File Organization 323 File Organization 324

Example:
Example: Order
Order of
of the
the index
index set
set is
is 33 Search
Search in
in aa Simple
Simple Prefix
Prefix B+
B+ Tree
Tree
► Search for “EMBRY”
– Retrieve Node (Root)
E – Since “EMBRY”> “E”, so go right, and retrieve Node .
– Since “EMBRY”< “F”, so go left, and Block #
– Look for the record with key “EMBRY” in Block #
B+Trees 12

E Node
BO CAM F FOLKS
Node Node

BO CAM F FOLKS

ADAMS-BERNE BOLEN-CAGE CAMP- DUTTON EMBRY- EVANS FABER-FOLK FOLKS-GADDIS

ADAMS-BERNE BOLEN-CAGE CAMP- DUTTON EMBRY- EVANS FABER-FOLK FOLKS-GADDIS

File Organization 325 File Organization 326


Simple
Simple Prefix
Prefix B+
B+ Tree
Tree Maintenance
Maintenance Example
Example (Cont’d)
(Cont’d)
►Example: 1. Changes which are local to single blocks in the sequence set
– Insert “U”
– Sequence set has blocking factor 4 • Go to the root
– Index set is a B tree of order 3 • Go to the right of “O”
B+Trees 12

B+Trees 12
• Insert “U” to Block

Node H O Node H O

A,C,E,G H,J,L,N O,Q,S A,C,E,G H,J,L,N O,Q,S,U


U

–There is no change in the index set


File Organization 327 File Organization 328

Example
Example (Cont’d)
(Cont’d) Example
Example (Cont’d)
(Cont’d)
– Delete “O” 2. Changes involving multiple blocks in the sequence set
• Go to the root – Delete “S” and “U”
• Go to the right of “O”
• Delete “O” from Block
B+Trees 12

B+Trees 12

Node H O

Node H O
A,C,E,G H,J,L,N Q

A,C,E,G H,J,L,N Q,S,U


–Now Block becomes less than ½ full (UNDERFLOW)

–There is no change in the index set: “O” is still a perfect separator


for Blocks and
File Organization 329 File Organization 330

Example
Example (Cont’d)
(Cont’d) Example
Example (Cont’d)
(Cont’d)
► Since Block is full, the only position is re-distribution bringing ► Insert “B”
a key from Block to Block – Go to the root
► We must update the separator “O” to “N” – Go to the left of “H” to Block
– Block would have hold A,B,C,E,G
– Block is split
B+Trees 12

B+Trees 12

Node H N Node H N

split A,B,C,E,G H,J,L N,Q


A,C,E,G H,J,L N,Q

A,B,C E,G

File Organization 331 File Organization 332


Example
Example (Cont’d)
(Cont’d) Example
Example (Cont’d)
(Cont’d)
► So this causes Node to split
Node H
B+Trees 12

B+Trees 12
Node Node
Node E H N
E N

A,B,C E,G H,J,L N,Q

A,B,C E,G H,J,L N,Q

File Organization 333 File Organization 334

Example
Example (Cont’d)
(Cont’d) Example
Example (Cont’d)
(Cont’d)
► Insert “F” ► Delete “J” and “L”
Node
Node H H
B+Trees 12

B+Trees 12

Node Node
Node Node
E N
E N

A,B,C E,F,G H N,Q


A,B,C E,F
F ,G H,J,L N,Q
► This is an UNDERFLOW. You may think to redistribute Blocks
and : E,F,G,H becomes E,F and G,H.
File Organization 335 File Organization 336

Example
Example (Cont’d)
(Cont’d) Example
Example (Cont’d)
(Cont’d)
► Why this is not possible? ► Send Node and to AVAIL LIST
► Blocks and are not siblings! They are cousins.
► Merge Blocks and
► Send Block to AVAIL LIST Node H

B+Trees 12

B+Trees 12

Remove the Link Between Node and Block


Node Node
Node Node
E H N
E N

A,B,C E,F,G H,N,Q


A,B,C E,F,G H,N,Q

File Organization 337 File Organization 338


Example
Example (Cont’d)
(Cont’d)
► Blocks were reunited as a big happy family again ☺
B+Trees 12

Node E H

A,B,C E,F,G H,N,Q

File Organization 339

You might also like