Announcements ----------------- - Exam #2 grades to be released by tomorrow - Homework #5 grading will start after exam grades are complete - Homework #6 to be released by tomorrow (due next monday) - Lecture 20 exercise after class B-trees ------------- Each B-tree node is mapped to a disk page Many (n decision points in each node) B-trees are balanced: - all leaf nodes contain information about tuples (one entry for each tuple) for each tuple (key value and a pointer to the tuple) and a pointer to the sibling node to the right All nodes are at least half full and at most has n entries (key value+pointer) Internal nodes contain n key values and n+1 pointers, each pointer is to the level below (all nodes must have at least (n+1)/2 pointers but the root may have two pointers) B-trees with duplicate values -------------------------------- Internal nodes will store the smallest key value that is not repeated in the previous node. If no such value, put null for key value. When searching for A=x key value in an internal node, find the first key value that is greater than or equal to x, and follow the node to the right of it. (if no such value, follow the leftmost pointer). Insertion to a B-tree ------------------------- Suppose inserting value (X) into the B-tree (corresponding to a new tuple) Search for X, if the leaf node for X has space, put it in. Done! If the node is full, then create a new leaf node, split the values in half and disitrubte between two leaf nodes, then recursively insert the key value and the pointer to the new node at the internal node above. Deletion from a B-tree -------------------------- Search the leaf node, if the deleted value exists, delete it from leaf, if the leaf is still at least half full: adjust internal nodes as necessary If after deletion, the leaf node is less than half full, find the sibling nodes from the same parent to the left and to the right of this current leaf node, if any of them have an extra tuple, then move the tuple to the leaf node and adjust the parent key values. If no such leaf node exists, then merge with one of the sibling nodes, and delete the leaf node and teh pointer to it recursively from the parent node. B-tree indices on multiple attributes ---------------------------------------- -- see course notes