130 likes | 239 Views
Announcements. Today Finish up B+ Trees Relational Data Model Reading assignment from last time Chapter 5 and Sections 6.0-6.5 Exam 2 weeks from this coming Monday Program 2 coming next week Replace homework with powerpointizing lecture Buffer Manager operations + LRU (a few weeks back)
E N D
Announcements • Today • Finish up B+ Trees • Relational Data Model • Reading assignment from last time • Chapter 5 and Sections 6.0-6.5 • Exam • 2 weeks from this coming Monday • Program 2 coming next week • Replace homework with powerpointizing lecture • Buffer Manager operations + LRU (a few weeks back) • B+ Tree concepts (today)
B+ Blocks form a Balanced Tree Picture of B+ Tree Goes Here
B+ Tree Properties • A B+ tree is kept balanced (ie, distance from the root to leaf is the same for each leaf) • Let p be the maximum number of tree pointers on an internal block (the order of the B+Tree) • Other than root, each internal page has at least ceil(p/2) tree pointers • A block with q tree pointers has q-1 search field values • Key aspect of B+ trees are graceful algorithms for handling insertions and delete
Leaf Nodes • Together, leaf nodes are very similar to a secondary index Leaf Nodes Picture
Internal Nodes • Internal nodes contain records (key, treePtr) pairs where treePtr points to root of B+Tree for records whose key value falls in some range Internal Nodes Picture
Example 6: Calculating the order of a B+Tree • Recall that the order of a B+ tree is the maximum number of tree pointers in a block • What does it depend on?
Key Operations on B+Tree(or any index for that matter) • Search: given key return RIDs • Ordered Scan: return RIDs in order of key field • Insert: and an entry to the index • Delete: remove an entry from the index
B+Tree Search B+Tree_search( key ) B root block of B+Tree while( B is not a leaf node ) if( key > B.keyq-1 ) B = *(B.Tq) else{ k = 1; while( key >= B.keyk && k <= q-1 ){ k++; } B = *B.Tk } } find and return RID on leaf page B
B+Tree Insert B+Tree Insert Animation
Misc. Thoughts on Indexes • For a frequently updated file, B+Tree index is almost always superior to a sorted file • For small amount of space, we get all the advantages of sorted files plus efficient insertion and deletion • On average B+trees are ~ 67% full • Bulk loading index Vs incremental construction • B+trees Vs other multilevel indexes • MLI blocks typically sequentially allocated, B+Tree usually not • Key Compression – internal nodes of B+Tree need not store full values • Indexes on multiple fields