Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC-310 Database Systems

Similar presentations


Presentation on theme: "CPSC-310 Database Systems"— Presentation transcript:

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

2 B+Trees Support fast search Support range search
Support dynamic changes Could be either dense or sparse * dense: pointers to all records * sparse: one pointer per block Notes #7

3 B+Trees A B+tree node of order n How big is n?
where ph are pointers (disk addresses) and kh are search-keys (values of the attributes in the index) How big is n? Basically we want each B+tree node to fit in a disk block so that a B+tree node can be read/written by a single disk I/O. Typically, n ~ p1 k1 p2 k2 …… pn kn pn+1 Notes #7

4 B+Tree Example order n = 3
root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

5 Sample non-leaf order n = 3
57 81 95 To keys k < 57 To keys 57 k<81 To keys 81 k<95 To keys k  95 Notes #7

6 Sample leaf node order n = 3
From non-leaf node To next leaf in sequence 57 81 95 To record with key 57 To record with key 81 To record with key 95 Notes #7

7 A B+Tree of order n Each node has: n keys and n+1 pointers
These are fixed To keep the nodes not too empty, also for the operations to be applied efficiently: * Non-leaf: at least (n+1)/2 pointers (to children) * Leaf: at least (n+1)/2 pointers to data (plus a “sequence pointer” to the next leaf) Basically: use at least one half of the pointers Notes #7

8 Example (B+ tree of order n=3)
Full node Min. node 120 150 180 30 Non-leaf 3 5 11 30 35 Leaf Notes #7

9 B+tree rules Notes #7

10 B+tree rules Rule 1. All leaves are at same lowest level (balanced tree) Notes #7

11 B+tree rules Rule 1. All leaves are at same lowest level (balanced tree) Rule 2. Pointers in leaves point to records except for “sequence pointer” Notes #7

12 B+tree rules Rule 1. All leaves are at same lowest level (balanced tree) Rule 2. Pointers in leaves point to records except for “sequence pointer” Rule 3. Number of keys/pointers in nodes: Max. # pointers Max. # keys Min. # keys Non-leaf n+1 n (n+1)/2 (n+1)/2 1 Leaf (n+1)/2 + 1 (n+1)/2 Root 2 1 Notes #7

13 B+tree rules Rule 1. All leaves are at same lowest level (balanced tree) Rule 2. Pointers in leaves point to records except for “sequence pointer” Rule 3. Number of keys/pointers in nodes: Max. # pointers Max. # keys Min. # keys Non-leaf n+1 n (n+1)/2 (n+1)/2 1 Leaf (n+1)/2 + 1 (n+1)/2 Root 2 1 could be 1 Notes #7

14 Search in a B+tree Notes #7

15 Search in a B+tree Start from the root Search in a leaf block
May not have to go to the data file Search(ptr, k); \\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Notes #7

16 Search in a B+tree Start from the root Search in a leaf block
May not have to go to the data file Search(ptr, k); \\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Notes #7

17 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Notes #7

18 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

19 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Search(*prt, 130) root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

20 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Search(*prt, 130) root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

21 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Search(*prt, 130) root 100 100  130 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

22 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Search(*prt, 130) root 100 100  130 30 120 150 180 120  130 <150 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

23 Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1 A tree node
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Search(*prt, 130) root 100 100  130 30 120 150 180 120  130 <150 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 130 =130 return Notes #7

24 Range Search in B+tree To research all records whose key values are between k1 and k2: Notes #7

25 Range Search in B+tree To research all records whose key values are between k1 and k2: Range-Search(ptr, k1, k2) Notes #7

26 Range Search in B+tree To research all records whose key values are between k1 and k2: Range-Search(ptr, k1, k2) Call Search(ptr, k1); Notes #7

27 Range Search in B+tree To research all records whose key values are between k1 and k2: Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Notes #7

28 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

29 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

30 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

31 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

32 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 50 < 100 30 120 150 180 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

33 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 50 < 100 30 120 150 180 30  50 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 Notes #7

34 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 50 < 100 30 120 150 180 30  50 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 35 < 50 Not Return Notes #7

35 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 50 < 100 30 120 150 180 30  50 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 35 < 50 Not Return Notes #7

36 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 50 < 100 30 120 150 180 30  50 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 35 < 50 100  125 110  125 Not Return return return 101  125 return Notes #7

37 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 50 < 100 30 120 150 180 30  50 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 35 < 50 100  125 110  125 Not Return return return 101  125 return Notes #7

38 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 50 < 100 30 120 150 180 30  50 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 35 < 50 100  125 110  125 Not Return return return 101  125 120  125 return return Notes #7

39 Range Search in B+tree Search(ptr, k); p1 k1 p2 k2 …… pn kn pn+1
\\ search a record of key value k in the subtree rooted at ptr \\ assume the B+tree is a dense index of order n Case 1. ptr is a leaf \\ pn+1 is the sequence pointer IF (k = ki) for a key ki in *ptr THEN return(pi); ELSE return(Null); Case 2. ptr is not a leaf find a key ki in *ptr such that ki-1 ≤ k < ki; return(Search(pi, k)); Range Search in B+tree p1 k1 p2 k2 …… pn kn pn+1 A tree node Range-Search(ptr, k1, k2) Call Search(ptr, k1); Follow the sequence pointers until the search key value is larger than k2. Range-Search(*prt, 50, 125) Search(*prt, 50) root 100 50 < 100 30 120 150 180 30  50 3 5 11 30 35 100 101 110 120 130 150 156 179 180 200 35 < 50 100  125 110  125 135 > 125 Not Return return return STOP 101  125 120  125 return return Notes #7

40 Insert into B+tree Notes #7

41 Insert into B+tree Basic idea: Notes #7

42 Insert into B+tree Basic idea:
Find the leaf L where the record r should be inserted; Notes #7

43 Insert into B+tree Basic idea:
Find the leaf L where the record r should be inserted; If L has further room, then insert r into L, and return; Notes #7

44 Insert into B+tree Basic idea:
Find the leaf L where the record r should be inserted; If L has further room, then insert r into L, and return; If L is full, spilt L plus r into two leaves (each is about half full): this causes an additional child for the parent P of L, thus we need to add a child to P; Notes #7

45 Insert into B+tree Basic idea:
Find the leaf L where the record r should be inserted; If L has further room, then insert r into L, and return; If L is full, spilt L plus r into two leaves (each is about half full): this causes an additional child for the parent P of L, thus we need to add a child to P; If P is already full, then we have to split P and add an additional child to P’s parent … (recursively) Notes #7

46 Insert into B+tree Simple case (space available for new child)
Leaf overflow Non-leaf overflow New root Notes #7

47 Insert into B+tree Simple case (space available for new child)
Leaf overflow Non-leaf overflow New root Notes #7

48 I. Simple case: Insert key 32
order n=3 100 30 40 3 5 11 30 31 Notes #7

49 I. Simple case: Insert key 32
order n=3 Insert(prt, 32) 100 30 40 3 5 11 30 31 Notes #7

50 I. Simple case: Insert key 32
order n=3 Insert(prt, 32) 100 32 < 100 30 40 30  32 <40 3 5 11 30 31 Notes #7

51 I. Simple case: Insert key 32
order n=3 Insert(prt, 32) 100 32 < 100 30 40 30  32 <40 3 5 11 30 31 room for 32 Notes #7

52 I. Simple case: Insert key 32
order n=3 Insert(prt, 32) 100 32 < 100 30 40 30  32 <40 3 5 11 30 31 32 Notes #7

53 Insert into B+tree Simple case (space available for new child)
Leaf overflow Non-leaf overflow New root Idea: when there is no space for a new child (all pointers are in use), split the node into two nodes, with both at least half full. Notes #7

54 Complication: node overflow
Notes #7

55 Complication: Leaf overflow
Notes #7

56 Complication: Leaf overflow
p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

57 Complication: Leaf overflow
p k k p’ p1 k1 … p k p** p k … pn kn pn+1 kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

58 Complication: Leaf overflow
p k k p’ p1 k1 … p k p** p k … pn kn pn+1 kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

59 Complication: Leaf overflow
p k k p’ q p1 k1 … p k p** p k … pn kn pn+1 kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

60 Complication: Leaf overflow
p k k p’ ? q What is the key here? p1 k1 … p k p** p k … pn kn pn+1 kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

61 Complication: Leaf overflow
p k k p’ ? q What is the key here? p1 k1 … p k p** p k … pn kn pn+1 kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

62 Complication: Leaf overflow
p k k p’ q 𝑛+1 /2 +1 p1 k1 … p k p** p k … pn kn pn+1 kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 p k p’ p1 k1 … p k p k … … pn kn p* 𝑛+1 /2 𝑛+1 /2 𝑛+1 /2 +1 𝑛+1 /2 +1 pn+1 kn+1 Notes #7

63 Leaf overflow: Insert key 7 (order n = 3)
100 30 3 5 11 30 31 Notes #7

64 Leaf overflow: Insert key 7 (order n = 3)
100 30 7 3 5 11 30 31 Notes #7

65 Leaf overflow: Insert key 7 (order n = 3)
100 30 3 5 7 11 30 31 Notes #7

66 Leaf overflow: Insert key 7 (order n = 3)
100 30 3 5 7 11 30 31 3 5 11 7 Notes #7

67 Leaf overflow: Insert key 7 (order n = 3)
100 30 3 5 7 11 30 31 3 5 11 7 Notes #7

68 Leaf overflow: Insert key 7 (order n = 3)
100 30 3 5 7 11 30 31 3 5 11 7 Notes #7

69 Leaf overflow: Insert key 7 (order n = 3)
100 30 3 5 7 11 30 31 3 5 11 7 Notes #7

70 Leaf overflow: Insert key 7 (order n = 3)
100 7 30 3 5 7 11 30 31 3 5 11 7 Notes #7

71 Complication: nonleaf overflow
Notes #7

72 Complication: nonleaf overflow
p k’ p’ kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

73 Complication: nonleaf overflow
p k’ p’ k q (𝑛+1)/2 p1 k1 p2 k2 … p k p p k … pn kn pn+1 kn+1 pn+2 (𝑛+1)/2 -1 (𝑛+1)/2 -1 (𝑛+1)/2 (𝑛+1)/2 +1 (𝑛+1)/2 +1 p k’ p’ kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

74 Complication: nonleaf overflow
p k’ p’ k q (𝑛+1)/2 p1 k1 p2 k2 … p k p p k … pn kn pn+1 kn+1 pn+2 (𝑛+1)/2 -1 (𝑛+1)/2 -1 (𝑛+1)/2 (𝑛+1)/2 +1 (𝑛+1)/2 +1 p k’ p’ kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

75 Complication: nonleaf overflow
p k’ p’ k q (𝑛+1)/2 p1 k1 p2 k2 … p k p p k … pn kn pn+1 kn+1 pn+2 (𝑛+1)/2 -1 (𝑛+1)/2 -1 (𝑛+1)/2 (𝑛+1)/2 +1 (𝑛+1)/2 +1 p k’ p’ kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

76 Complication: nonleaf overflow
p k’ p’ k ? q (𝑛+1)/2 What is the key here? p1 k1 p2 k2 … p k p p k … pn kn pn+1 kn+1 pn+2 (𝑛+1)/2 -1 (𝑛+1)/2 -1 (𝑛+1)/2 (𝑛+1)/2 +1 (𝑛+1)/2 +1 p k’ p’ kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

77 Complication: nonleaf overflow
p k’ p’ k ? q (𝑛+1)/2 What is the key here? p1 k1 p2 k2 … p k p p k … pn kn pn+1 kn+1 pn+2 (𝑛+1)/2 -1 (𝑛+1)/2 -1 (𝑛+1)/2 (𝑛+1)/2 +1 (𝑛+1)/2 +1 p k’ p’ not used kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

78 Complication: nonleaf overflow
p k’ p’ k k q (𝑛+1)/2 (𝑛+1)/2 p1 k1 p2 k2 … p k p p k … pn kn pn+1 kn+1 pn+2 (𝑛+1)/2 -1 (𝑛+1)/2 -1 (𝑛+1)/2 (𝑛+1)/2 +1 (𝑛+1)/2 +1 p k’ p’ kn+1 pn+2 p1 k1 … p k p k p k … pn kn pn+1 (𝑛+1)/2 (𝑛+1)/2 -1 (𝑛+1)/2 +1 (𝑛+1)/2 +1 Notes #7

79 Nonleaf overflow: Insert key 160 (order n = 3)
100 120 150 180 160 150 156 179 180 210 Notes #7

80 Nonleaf overflow: Insert key 160 (order n = 3)
100 120 150 180 150 156 160 179 180 210 150 156 179 160 Notes #7

81 Nonleaf overflow: Insert key 160 (order n = 3)
100 120 150 180 150 156 160 179 180 210 150 156 179 160 Notes #7

82 Nonleaf overflow: Insert key 160 (order n = 3)
100 120 150 180 160 150 156 160 179 180 210 150 156 179 160 Notes #7

83 Nonleaf overflow: Insert key 160 (order n = 3)
100 120 150 180 no room! 160 150 156 160 179 180 210 150 156 179 160 Notes #7

84 Nonleaf overflow: Insert key 160 (order n = 3)
120 150 180 160 100 120 150 180 160 150 156 160 179 180 210 150 156 179 160 Notes #7

85 Nonleaf overflow: Insert key 160 (order n = 3)
120 150 180 160 100 120 150 180 160 150 156 160 179 180 210 150 156 179 160 Notes #7

86 Nonleaf overflow: Insert key 160 (order n = 3)
120 150 180 160 100 160 120 150 180 160 150 156 160 179 180 210 150 156 179 160 Notes #7

87 Nonleaf overflow: Insert key 160 (order n = 3)
100 160 120 150 180 150 156 160 179 180 210 Notes #7


Download ppt "CPSC-310 Database Systems"

Similar presentations


Ads by Google