CPSC-310 Database Systems

Slides:



Advertisements
Similar presentations
Advanced Database Discussion B Trees. Motivation for B-Trees So far we have assumed that we can store an entire data structure in main memory What if.
Advertisements

Dr. Kalpakis CMSC 661, Principles of Database Systems Index Structures [13]
CPSC-608 Database Systems Fall 2010 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #7.
CS4432: Database Systems II
Data Structures and Algorithms1 B-Trees with Minimum=1 2-3 Trees.
CPSC-608 Database Systems Fall 2011 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #10.
CPSC-608 Database Systems Fall 2008 Instructor: Jianer Chen Office: HRBB 309B Phone: Notes #7.
B + Trees Dale-Marie Wilson, Ph.D.. B + Trees Search Tree Used to guide search for a record, given the value of one of its fields Two types of Nodes Internal.
B + -Trees Same structure as B-trees. Dictionary pairs are in leaves only. Leaves form a doubly-linked list. Remaining nodes have following structure:
©Silberschatz, Korth and Sudarshan12.1Database System Concepts Chapter 12: Part B Part A:  Index Definition in SQL  Ordered Indices  Index Sequential.
B + -Trees (Part 1) Lecture 20 COMP171 Fall 2006.
1 Database indices Database Systems manage very large amounts of data. –Examples: student database for NWU Social Security database To facilitate queries,
B + -Trees (Part 1). Motivation AVL tree with N nodes is an excellent data structure for searching, indexing, etc. –The Big-Oh analysis shows most operations.
B+ - Tree & B - Tree By Phi Thong Ho.
B-Trees and B+-Trees Disk Storage What is a multiway tree?
Homework #3 Due Thursday, April 17 Problems: –Chapter 11: 11.6, –Chapter 12: 12.1, 12.2, 12.3, 12.4, 12.5, 12.7.
CS 255: Database System Principles slides: B-trees
CS4432: Database Systems II
1 B-Trees Section AVL (Adelson-Velskii and Landis) Trees AVL tree is binary search tree with balance condition –To ensure depth of the tree is.
IntroductionIntroduction  Definition of B-trees  Properties  Specialization  Examples  2-3 trees  Insertion of B-tree  Remove items from B-tree.
B-Tree. B-Trees a specialized multi-way tree designed especially for use on disk In a B-tree each node may contain a large number of keys. The number.
 B+ Tree Definition  B+ Tree Properties  B+ Tree Searching  B+ Tree Insertion  B+ Tree Deletion.
Database Management 8. course. Query types Equality query – Each field has to be equal to a constant Range query – Not all the fields have to be equal.
1 B Trees - Motivation Recall our discussion on AVL-trees –The maximum height of an AVL-tree with n-nodes is log 2 (n) since the branching factor (degree,
CSE373: Data Structures & Algorithms Lecture 15: B-Trees Linda Shapiro Winter 2015.
Multi-way Trees. M-way trees So far we have discussed binary trees only. In this lecture, we go over another type of tree called m- way trees or trees.
B-Trees. CSM B-Trees 2 Motivation for B-Trees So far we have assumed that we can store an entire data structure in main memory What if we have so.
DBMS 2001Notes 4.1: B-Trees1 Principles of Database Management Systems 4.1: B-Trees Pekka Kilpeläinen (after Stanford CS245 slide originals by Hector Garcia-Molina,
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture17.
CS 405G: Introduction to Database Systems 22 Index Chen Qian University of Kentucky.
Indexes. Primary Indexes Dense Indexes Pointer to every record of a sequential file, (ordered by search key). Can make sense because records may be much.
R-Trees: A Dynamic Index Structure For Spatial Searching Antonin Guttman.
B-TREE. Motivation for B-Trees So far we have assumed that we can store an entire data structure in main memory What if we have so much data that it won’t.
Indexing and B+-Trees By Kenneth Cheung CS 157B TR 07:30-08:45 Professor Lee.
1 Chapter 12: Indexing and Hashing Indexing Indexing Basic Concepts Basic Concepts Ordered Indices Ordered Indices B+-Tree Index Files B+-Tree Index Files.
1 CSCE 520 Test 2 Info Indexing Modified from slides of Hector Garcia-Molina and Jeff Ullman.
1 Query Processing Part 3: B+Trees. 2 Dense and Sparse Indexes Advantage: - Simple - Index is sequential file good for scans Disadvantage: - Insertions.
CS422 Principles of Database Systems Indexes Chengyu Sun California State University, Los Angeles.
CS422 Principles of Database Systems Indexes
COMP261 Lecture 23 B Trees.
Multilevel Indexing and B+ Trees
Multilevel Indexing and B+ Trees
Multiway Search Trees Data may not fit into main memory
Azita Keshmiri CS 157B Ch 12 indexing and hashing
Tree-Structured Indexes
CPSC-310 Database Systems
CSE373: Data Structures & Algorithms Lecture 15: B-Trees
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
CPSC-629 Analysis of Algorithms
Data Structures and Algorithms
B Tree Adhiraj Goel 1RV07IS004.
CPSC-310 Database Systems
Lecture 26 Multiway Search Trees Chapter 11 of textbook
CPSC-310 Database Systems
(Slides by Hector Garcia-Molina,
CPSC-310 Database Systems
B+-Trees and Static Hashing
B+Trees The slides for this text are organized into chapters. This lecture covers Chapter 9. Chapter 1: Introduction to Database Systems Chapter 2: The.
Multiway Trees Searching and B-Trees Advanced Tree Structures
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
B+Tree Example n=3 Root
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
Chapter 11 Indexing And Hashing (1)
CPSC-608 Database Systems
2-3 Trees Extended tree. Tree in which all empty subtrees are replaced by new nodes that are called external nodes. Original nodes are called internal.
B+-Trees j a0 k1 a1 k2 a2 … kj aj j = number of keys in node.
CPSC-608 Database Systems
Tree-Structured Indexes
CPSC-608 Database Systems
Index Structures Chapter 13 of GUW September 16, 2019
Presentation transcript:

CPSC-310 Database Systems Professor Jianer Chen Room 315C HRBB Lecture #20

B+Trees Support fast search Support range search Support dynamic changes B+tree node of order n: p1 k1 p2 k2 …… pn kn pn+1 Notes #7

Delete in B+tree Basic idea: Find the leaf L where the record r should be deleted; If L remains at least half-full after deleting r, then delete r, and return; Else consider the sibling L’ of L; 3.1 If L’ is more than half-full, then move a record from L’ to L, and return; 3.2 Else combine L and L’ into a single leaf; 3.3 But now you need to consider the case of deleting a child from L’s parent … (recursively) Notes #7

Delete in B+tree Simple case: the node remains at least half-full after deletion. Re-distribute keys among siblings Coalesce with a sibling and delete a pointer from its father Notes #7

Delete in B+tree Simple case: the node remains at least half-full after deletion. Re-distribute keys among siblings Coalesce with a sibling and delete a pointer from its father Notes #7

Key re-distribution at leaves p’ k’ p k p” k” i = (n+1)/2  1 t > (n+1)/2 p1 k1 … pi ki --- p* q1 h1 q2 h2 … qt ht --- q* Notes #7

Key re-distribution at leaves p’ k’ p k p” k” i = (n+1)/2  1 t > (n+1)/2 p1 k1 … pi ki --- p* q1 h1 q2 h2 … qt ht --- q* p’ k’ p k p” k” p1 k1 … pi ki q1 h1 --- p* q2 h2 … qt ht --- q* Notes #7

Key re-distribution at leaves p’ k’ p k p” k” i = (n+1)/2  1 t > (n+1)/2 p1 k1 … pi ki --- p* q1 h1 q2 h2 … qt ht --- q* p’ k’ p k p” k” h2 p1 k1 … pi ki q1 h1 --- p* q2 h2 … qt ht --- q* Notes #7

Key re-distribution at leaves: Delete 5 order n=3 Notes #7

Key re-distribution at leaves: Delete 5 order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Notes #7

Key re-distribution at leaves: Delete 5 order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Delete 5 Notes #7

Key re-distribution at leaves: Delete 5 order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Notes #7

Key re-distribution at leaves: Delete 5 order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Less than half-full !! Notes #7

Key re-distribution at leaves: Delete 5 order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Look at the sibling, which is more than half-full, so we can redistribute the keysa Notes #7

Key re-distribution at leaves: Delete 5 order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Look at the sibling, which is more than half-full, so we can redistribute the keysa Notes #7

Key re-distribution at leaves: Delete 5 order n=3 Delete(prt, 5) 105 10 40 3 5 10 20 35 40 50 Look at the sibling, which is more than half-full, so we can redistribute the keys Notes #7

Key re-distribution at leaves: Delete 5 order n=3 Delete(prt, 5) 105 10 40 redistribution 3 10 20 35 40 50 3 10 20 35 Notes #7

Key re-distribution at leaves: Delete 5 order n=3 Delete(prt, 5) 105 10 40 redistribution 20 3 10 20 35 40 50 3 10 20 35 Notes #7

Key re-distribution at leaves: Delete 5 order n=3 Delete(prt, 5) 105 20 10 40 redistribution 20 3 10 20 35 40 50 3 10 20 35 Notes #7

Key re-distribution at leaves: Delete 5 order n=3 105 20 40 3 10 20 35 40 50 Notes #7

Key re-distribution at nonleaves Notes #7

Key re-distribution at nonleaves p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - Notes #7

Key re-distribution at nonleaves p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - Notes #7

Key re-distribution at nonleaves p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” p1 k1 … pi ki pi+1 q1 q1 h1 q2 h2 … qt ht qt+1 - Notes #7

Key re-distribution at nonleaves p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” p1 k1 … pi ki pi+1 q1 ? q1 h1 q2 h2 … qt ht qt+1 - Notes #7

Key re-distribution at nonleaves p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” p1 k1 … pi ki pi+1 q1 ? q1 h1 q2 h2 … qt ht qt+1 - Notes #7

Key re-distribution at nonleaves p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” p1 k1 … pi ki pi+1 q1 k’ q1 h1 q2 h2 … qt ht qt+1 - Notes #7

Key re-distribution at nonleaves p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” ? p1 k1 … pi ki pi+1 q1 k’ q1 h1 q2 h2 … qt ht qt+1 - Notes #7

Key re-distribution at nonleaves p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” ? p1 k1 … pi ki pi+1 q1 k’ q1 h1 q2 h2 … qt ht qt+1 - Notes #7

Key re-distribution at nonleaves p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” h1 p1 k1 … pi ki pi+1 q1 k’ q1 h1 q2 h2 … qt ht qt+1 - Notes #7

Key re-distribution at nonleaves p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - p’ k’ p k p” k” h1 p1 k1 … pi ki pi+1 q1 k’ q2 h2 … qt ht qt+1 Notes #7

Key re-distribution at nonleaves p’ k’ p k p” k” i+1 = (n+1)/2  1 t+1> (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 q2 h2 … qt ht qt+1 - an example of key re-distribution at nonleaves will be given later. p’ k’ p k p” k” h1 p1 k1 … pi ki pi+1 q1 k’ q2 h2 … qt ht qt+1 Notes #7

Delete in B+tree Simple case: the node remains at least half-full after deletion. Re-distribute keys among siblings Coalesce with a sibling and delete a pointer from its father Notes #7

Delete in B+tree Simple case: the node remains at least half-full after deletion. Re-distribute keys among siblings Coalesce with a sibling and delete a pointer from its father Observation: when two siblings both are no more than half full, coalesce them into a single node (which is nearly full) Notes #7

Node Coalescence Notes #7

Leaf Coalescence Notes #7

Leaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki --- p* i = (n+1)/2  1 t = (n+1)/2 p1 k1 … pi ki --- p* q1 h1 … qt ht --- q* Notes #7

Leaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki --- p* i = (n+1)/2  1 t = (n+1)/2 p1 k1 … pi ki --- p* q1 h1 … qt ht --- q* p’ k’ p k p” k” p1 k1 … pi ki q1 h1 … qt ht - q* q* Notes #7

Leaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki --- p* i = (n+1)/2  1 t = (n+1)/2 p1 k1 … pi ki --- p* q1 h1 … qt ht --- q* p’ k’ p k p” k” p1 k1 … pi ki q1 h1 … qt ht - q* q* Notes #7

Leaf coalescence : Delete key 5 Notes #7

Leaf coalescence : Delete key 5 order n=3 Delete(prt, 5) 38 10 60 80 3 5 10 20 40 50 60 75 80 90 Notes #7

Leaf coalescence : Delete key 5 order n=3 Delete(prt, 5) 38 10 60 80 3 5 10 20 40 50 60 75 80 90 Delete 5 Notes #7

Leaf coalescence : Delete key 5 order n=3 Delete(prt, 5) 38 10 60 80 3 5 10 20 40 50 60 75 80 90 Notes #7

The sibling is just half-full, so we should coalesce Leaf coalescence : Delete key 5 order n=3 Delete(prt, 5) 38 10 60 80 3 5 10 20 40 50 60 75 80 90 The sibling is just half-full, so we should coalesce Notes #7

Leaf coalescence : Delete key 5 order n=3 Delete(prt, 5) 38 10 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

Leaf coalescence : Delete key 5 order n=3 Delete(prt, 5) Less than half-full 38 10 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

half-full, so we can re-distribute pointers at nonleaves Leaf coalescence : Delete key 5 order n=3 Delete(prt, 5) Less than half-full more than half-full, so we can re-distribute pointers at nonleaves 38 10 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

half-full, so we can re-distribute pointers at nonleaves Leaf coalescence : Delete key 5 order n=3 Delete(prt, 5) Less than half-full more than half-full, so we can re-distribute pointers at nonleaves 38 10 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

half-full, so we can re-distribute pointers at nonleaves Key re-distribution at Nonleaves order n=3 Delete(prt, 5) Less than half-full more than half-full, so we can re-distribute pointers at nonleaves 38 10 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

half-full, so we can re-distribute pointers at nonleaves Key re-distribution at Nonleaves order n=3 Delete(prt, 5) Less than half-full more than half-full, so we can re-distribute pointers at nonleaves 38 60 38 10 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

half-full, so we can re-distribute pointers at nonleaves Key re-distribution at Nonleaves order n=3 Delete(prt, 5) Less than half-full more than half-full, so we can re-distribute pointers at nonleaves 38 60 38 10 80 60 80 Leaf coalescence 3 10 20 10 20 40 50 60 75 80 90 3 5 10 20 Notes #7

Key re-distribution at Nonleaves order n=3 60 38 80 3 10 20 40 50 60 75 80 90 Notes #7

Nonleaf Coalescence Notes #7

Nonleaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki pi+1 i+1 = (n+1)/2  1 t+1= (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 Notes #7

Nonleaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki pi+1 i+1 = (n+1)/2  1 t+1= (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 p’ k’ p k p” k” p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 q1 h1 … qt ht qt+1 Notes #7

Nonleaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki pi+1 i+1 = (n+1)/2  1 t+1= (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 p’ k’ p k p” k” p1 k1 … pi ki pi+1 ? q1 h1 … qt ht qt+1 q1 h1 … qt ht qt+1 Notes #7

Nonleaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki pi+1 i+1 = (n+1)/2  1 t+1= (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 p’ k’ p k p” k” p1 k1 … pi ki pi+1 ? q1 h1 … qt ht qt+1 q1 h1 … qt ht qt+1 Notes #7

Nonleaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki pi+1 i+1 = (n+1)/2  1 t+1= (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 p’ k’ p k p” k” p1 k1 … pi ki pi+1 k q1 h1 … qt ht qt+1 q1 h1 … qt ht qt+1 Notes #7

Nonleaf Coalescence p’ k’ p k p” k” p1 k1 … pi ki pi+1 i+1 = (n+1)/2  1 t+1= (n+1)/2 p1 k1 … pi ki pi+1 q1 h1 … qt ht qt+1 p’ k’ p k p” k” p1 k1 … pi ki pi+1 k q1 h1 … qt ht qt+1 q1 h1 … qt ht qt+1 Notes #7

Nonleaf coalescence : Delete key 5 order n=3 Notes #7

Nonleaf coalescence : Delete key 5 order n=3 Delete(prt, 5) 55 10 60 3 5 10 20 55 58 61 72 Notes #7

Nonleaf coalescence : Delete key 5 order n=3 Delete(prt, 5) 55 10 60 3 5 10 20 55 58 61 72 delete 5 Notes #7

Nonleaf coalescence : Delete key 5 order n=3 Delete(prt, 5) 55 10 60 3 5 10 20 55 58 61 72 Notes #7

Nonleaf coalescence : Delete key 5 order n=3 Delete(prt, 5) 55 10 60 leaf coalescence 3 10 20 10 20 55 58 61 72 3 5 10 20 Notes #7

Nonleaf coalescence : Delete key 5 order n=3 Delete(prt, 5) 55 less than half-full 10 60 leaf coalescence 10 20 55 58 61 72 3 10 20 3 5 10 20 Notes #7

Nonleaf coalescence : Delete key 5 order n=3 Delete(prt, 5) 55 less than half-full just half-full, so we need to coalesce 10 60 leaf coalescence 10 20 55 58 61 72 3 10 20 3 5 10 20 Notes #7

Nonleaf coalescence : Delete key 5 order n=3 55 60 Delete(prt, 5) 55 nonleaf coalescence 55 60 60 leaf coalescence 61 72 3 10 20 10 20 55 58 3 5 10 20 Notes #7

Nonleaf coalescence : Delete key 5 order n=3 55 60 Delete(prt, 5) 55 nonleaf coalescence new root 55 60 60 leaf coalescence 61 72 3 10 20 10 20 55 58 3 5 10 20 Notes #7

Nonleaf coalescence : Delete key 5 order n=3 55 60 3 10 20 55 58 61 72 Notes #7

Pseudo Code for Deletion in a B+tree Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); Notes #7

Pseudo Code for Deletion in a B+tree Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a leaf Notes #7

Pseudo Code for Deletion in a B+tree Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a nonleaf Notes #7

Pseudo Code for Deletion in a B+tree Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a nonleaf recursion Notes #7

Pseudo Code for Deletion in a B+tree Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a nonleaf no new child needs to be added recursion Notes #7

Pseudo Code for Deletion in a B+tree Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a nonleaf no new child needs to be added recursion key re-distribution Notes #7

Pseudo Code for Deletion in a B+tree Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a nonleaf no new child needs to be added recursion key re-distribution node coalescence Notes #7

Pseudo Code for Deletion in a B+tree Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); delete at a nonleaf no new child needs to be added recursion key re-distribution node coalescence decide if a new root Notes #7

Pseudo Code for Deletion in a B+tree Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); report if pt is less than half-full Notes #7

Pseudo Code for Deletion in a B+tree Delete(pt, (k,p), belowmin); \\ technically, the smallest key kmin in *ptr is also returned \\ (k,p) is the data record to be deleted from the subtree rooted at pt; belowmin = true if \\ after deletion, pt has fewer than the required min # of pointers; Case 1. pt is a leaf delete (k,p) in pt; IF pt has at least (n+1)/2 data pointers OR pt is the root THEN return (belowmin = false) ELSE return (belowmin = true); Case 2. pt is not a leaf find a key ki in pt such that ki ≤ k < ki+1; Delete(pi , (k, p), belowmin'); IF (not belowmin') THEN return(belowmin= false); ELSE IF pi has an adjacent sibling p' that has more than the required min # of pointers THEN move one key-pointer pair from p' to pi; ELSE combine pi with an adjacent sibling of pi into a single node; IF pt is the root with only one pointer pi THEN pt = pi; return(belowmin= false); IF pt has at least (n+1)/2 pointers OR pt is the root THEN return(belowmin= false) ELSE return(belowmin= true); Notes #7

B+tree deletions in practice Often, coalescing is not implemented Too hard and not worth it! Notes #7

Outline of Course Representing things by tables E-R model (Ch. 4) Good table structures Functional Dependencies (Ch.3) Basic operations on relations Relational Algebra (Chs. 2+5) Storage management (Chs. 13-14) SQL languages in DDL/DML (Ch. 6) Query processing (Chs. 15-16) More on SQL (Chs. 7-9) Transition processing (Chs. 17-19)