Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data...
Transcript of Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data...
![Page 1: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/1.jpg)
Data Management and File Organization
Indexing
B-Tree Operations
B+Trees
![Page 2: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/2.jpg)
Topics
• Insertion in a B-Tree
• Deletion from a B-Tree
• B+Trees
![Page 3: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/3.jpg)
Insertion in a B-Tree
• Start searching the leaf node to insert the new record
• If the leaf node is full, split it into two nodes.
• Add the smallest key in the new leaf to the internal node.
• Update the tree if necessary
![Page 4: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/4.jpg)
Sample Data File
![Page 5: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/5.jpg)
B-Tree of the Sample Data File (N=2)
![Page 6: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/6.jpg)
Insert <8, B>
![Page 7: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/7.jpg)
Insert <15, X> and <16, T>
![Page 8: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/8.jpg)
Insert <15, X> and <16, T>
![Page 9: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/9.jpg)
Insert <4, Q>
![Page 10: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/10.jpg)
Insert <6, J>
![Page 11: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/11.jpg)
Insertion when the root node is full
• If the root node is full and a new key is to be added to it,
– split the root node into two nodes
– Put last N keys in new node
– Create a new node and put the middle key in it
– Make the new node the new root. (old root and the new node split from it will be its children)
![Page 12: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/12.jpg)
Split the Root
![Page 13: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/13.jpg)
Deletion from a B-Tree
• When two leaf nodes are merged, a key is removed from the internal node.
• If after removing a key, the internal node has less than N keys, it is merged with its neighboring internal node. (Except the root)
• When only one leaf node is left in the tree, the root is removed.
![Page 14: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/14.jpg)
Example: Delete 1
![Page 15: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/15.jpg)
Example, Delete 1
![Page 16: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/16.jpg)
Example, Delete 1
![Page 17: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/17.jpg)
B+Trees
• B-Trees are used to find the location of a record in a data file
• The index and data files are two separate files
• B+Tree combines the data and index files in a single tree
• Leaf nodes are used to store data records
![Page 18: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/18.jpg)
Sample Data
![Page 19: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/19.jpg)
Sample B+Tree (N=2)
![Page 20: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/20.jpg)
Exhaustive Reading in Index Files
• Exhaustive reading from a B-Tree needs starting from the root each time
• In a B+Tree leaf nodes are connected by pointers
• Exhaustive reading a B+Tree is as fast as exhaustive reading of a sorted file without overflow area
![Page 21: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/21.jpg)
Exhaustive Reading
![Page 22: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/22.jpg)
Improving Access Speed
• Motivation: The number of file access in an indexed file is as many as the tree height (3 or 4 for example)
• Hashing method provides a quick access to the records (1 or 2 file access)
![Page 23: Data Management and File Organizationceng351.cankaya.edu.tr/uploads/files/file/Data... · Data Management and File Organization Indexing B-Tree Operations B+Trees. Topics •Insertion](https://reader034.fdocuments.us/reader034/viewer/2022052005/60192f3e266e527c5203438b/html5/thumbnails/23.jpg)
Questions?