cs 764 topics in database management systems lecture 9 b
play

CS 764: Topics in Database Management Systems Lecture 9: B-tree - PowerPoint PPT Presentation

CS 764: Topics in Database Management Systems Lecture 9: B-tree Locking Xiangyao Yu 10/5/2020 1 Todays Paper: B-tree Locking ACM Trans. Database Syst. 1981 2 Agenda Index in OLTP database B tree, B+ tree, and B* tree B link -tree 3


  1. CS 764: Topics in Database Management Systems Lecture 9: B-tree Locking Xiangyao Yu 10/5/2020 1

  2. Today’s Paper: B-tree Locking ACM Trans. Database Syst. 1981 2

  3. Agenda Index in OLTP database B tree, B+ tree, and B* tree B link -tree 3

  4. Index in an OLTP Database Select name From student Where id=xxx Primary index (id) ptr to tuple or page id Data store 4

  5. Index in an OLTP Database Select name Select name From student From student Where email=xxx Where id=xxx Primary Secondary Primary index (id) index (email) index (id) ptr to tuple or page id id ptr to tuple or page id Data store Data store 5

  6. B-tree Balanced tree data structure • Data is sorted • Supports: search, sequential scan, insets, and deletes Algorithm Average Worst case Space O(n) O(n) Search O(log n) O(log n) Insert O(log n) O(log n) Delete O(log n) O(log n) 6

  7. B-tree Balanced tree data structure • Data is sorted • Supports: search, sequential scan, inserts, and deletes Properties • Every node has at most m children. • Every non-leaf node (except root) has at least ⌈ m /2 ⌉ child nodes. • All the leaf nodes of the B-tree must be at the same level. Algorithm Average Worst case Space O(n) O(n) Search O(log n) O(log n) Insert O(log n) O(log n) Delete O(log n) O(log n) 7

  8. B-tree vs. B+ Tree vs. B* Tree B-tree 10 8 14 16 4 9 13 15 17 19 B-tree: data pointers stored in all nodes 8

  9. B-tree vs. B+ Tree vs. B* Tree B-tree B+ tree 10 10 8 14 16 8 14 16 4 9 13 15 17 19 4 9 13 15 17 19 B-tree: data pointers stored in all nodes B+ tree: • Data pointers stored only in leaf nodes • The leaf nodes are linked 9

  10. B-tree vs. B+ Tree vs. B* Tree B-tree B+ tree B* tree 10 10 10 19 high key 8 14 16 8 14 16 8 9 14 16 19 4 9 13 15 17 19 4 9 13 15 17 19 4 9 13 15 17 19 B-tree: data pointers stored in all nodes B+ tree: • Data pointers stored only in leaf nodes • The leaf nodes are linked B* tree is a misused term in B-tree literature • Typically means a variant of B+ tree in which each node is least 2/3 full • In this paper: B+ tree with high key appended to non-leaf nodes (upper bound on values) 10

  11. B* Tree Structure Within each node, keys in ascending order Each node contains at least k keys and at most 2k keys ( k is a tree parameter) Values stored in a subtree are bounded by the the two key values K i-1 < v ≤ K i Example: search key 53 11

  12. B* Tree Insertion Insert to leaf if the leaf node has fewer than 2k entries If leaf has 2k entries, split the node into two nodes (split may happen recursively) 12

  13. Challenge of Concurrent Operations Concurrent search and insert operations may cause problems 13

  14. B link -Tree B link tree B* tree 10 19 10 19 link pointer 8 9 14 16 19 8 9 14 16 19 4 9 13 15 17 19 4 9 13 15 17 19 Adds a link field that points to the next node at the same level of the tree as the current node The link pointer of the rightmost node on a level is a null pointer 14

  15. B link -Tree: Search Algorithm … … root 5 10 23 … … 11 13 17 19 … … … Key: 13 Example: search Key=13 15

  16. B link -Tree: Search Algorithm … … root 5 10 23 … … 11 13 17 19 … … … Key: 13 Example: search Key=13 16

  17. B link -Tree: Insert Algorithm Insert to leaf if the leaf node if not full Illustration of node split (node a is split into a’ and b’ ) Before split Step 1 Step 2 Step 3 17

  18. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 10 23 … … 11 13 17 23 … … … … 18

  19. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 10 23 stack = { F root, } … … 11 13 17 23 … … … … 19

  20. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 10 23 … … 11 13 17 23 … … … … initially, w is the data page to be inserted 20

  21. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 10 23 … … 11 13 17 23 … … … … 21

  22. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 10 23 … … 11 13 17 23 A … … … … B Allocate new block on disk 22

  23. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 10 23 … … 11 13 17 23 A … … … … B 17 23 11 13 14 create two pages in memory 23

  24. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 10 23 … … 11 13 17 23 A … … … … B 17 23 11 13 14 update the two disk pages (page B first) 24

  25. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 10 23 … … B 11 13 14 17 23 A update the two disk pages (page B first) 25

  26. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 10 23 … … B 11 13 14 17 23 A try to insert (key=14, ptr= B ) to F 26

  27. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 10 14 23 … … B 11 13 14 17 23 A insert (key=14, ptr= B ) to F 27

  28. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 7 9 10 11 14 23 … … B 12 13 14 17 23 A At most three locks are being during an insert 28

  29. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 7 9 10 11 14 23 … … B 12 13 14 17 23 A At most three locks are being during an insert 29

  30. B link -Tree: Insert Algorithm … … Example: root Insert 14 F 5 7 9 10 11 14 23 … … B 12 13 14 17 23 A At most three locks are being during an insert 30

  31. Revisit Concurrent Operations key=15 is less than max key in node y Follow the link ptr to the next leaf node and 15 is found! 31

  32. Other Issues Delete: allow fewer than k entries in a leaf node • Observations: insertions are much more frequent than deletions Deadlock freedom: locks are acquired bottom-up and left to right => total order Livelock: keep following the link pointer due to node splits 32

  33. Q/A – B-tree Locking B+ tree vs. B* tree? Which variant of B-tree are modern DBMSs using? Would a left pointer add benefit? Experimental comparison What’s the typical value of k ? Binary search within a node? Disk utilization w.r.t. deletion Deadlock vs. livelock? 33

  34. Before Next Lecture Submit review before next lecture • C. Mohan, et al. ARIES: A Transaction Recovery Method Supporting Fine- Granularity Locking and Partial Rollbacks Using Write-Ahead Logging. ACM Trans. Database Syst. 1992. 34

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend