Lecture12 6 Slides Per Page
Lecture12 6 Slides Per Page
Content
► Maintaining a sequence set
► A simple prefix B+ Tree
B+Trees 12
Deletions
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
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
B+Trees 12
DENVER... ELLIS...
ADAMS... BAIRD... BIXBY...
COLE... DAVIS...
CARSON... COLE...
►Delete “DAVIS...”
Deletion
Deletion with
with Merging
Merging (Con’t)
(Con’t) Delete
Delete “BYNUM”,
“BYNUM”, then
then Delete
Delete “CARTER”
“CARTER”
B+Trees 12
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...
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)
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
B+Trees 12
• Insert “U” to Block
Node H O Node H O
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
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
A,B,C E,G
B+Trees 12
Node Node
Node E H N
E N
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
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
Node E H