Tree-Structured Indexes.ppt
《Tree-Structured Indexes.ppt》由会员分享,可在线阅读,更多相关《Tree-Structured Indexes.ppt(61页珍藏版)》请在麦多课文档分享上搜索。
1、,Tree-Structured Indexes,Chapter 10,Introduction,As for any index, 3 alternatives for data entries k*:Data record with key value kChoice is orthogonal to the indexing technique used to locate data entries k*: Hash Tree,Introduction,Tree-structured indexing techniques support both range searches and
2、equality searches.,Motivation for Tree Index,Range search : Find all students with gpa 3.0Given Sorted fileUSE: do binary search to find first such student, then scan to find others.Cost of binary search can be quite high.,Motivation for Tree Index,Range search : Find all students with gpa 3.0 Simpl
3、e idea: Create an index file.,Can do binary search on (smaller) index file!,Page 1,Page 2,Page N,Page 3,Data File,k2,kN,k1,Index File,Motivation for Tree Index,Range search : Find all students with gpa 3.0 Sorted file, do binary search to find first such student, then scan to find others. Cost of bi
4、nary search can be quite high.Simple idea: Create an index file.,Can do binary search on (smaller) index file!,Page 1,Page 2,Page N,Page 3,Data File,k2,kN,k1,Index File,Alternative Tree Index Structures,ISAM (Indexed Sequential Access Method): static structure.B+ tree: dynamic structure. Adjust grac
5、efully under inserts and deletes.,ISAM Index,Page 1,Page 2,Page N,Page 3,Data File,k2,kN,k1,Index File,P,0,K,1,P,1,K,2,P,2,K,m,P,m,index entry,ISAM,Index file may still be quite large. But we can apply the idea repeatedly!,Only leaf pages contain data entries.,Non-leaf,Pages,Pages,Primary pages,Leaf
6、,Example ISAM Tree,Each node can hold 2 entries. No need for next-leaf-page pointers. (?),Inserting 23*, 48*, 41*, 42* .,After Inserting 23*, 48*, 41*.,10*,15*,20*,27*,33*,37*,40*,46*,51*,55*,63*,97*,20,33,51,63,40,Root,23*,48*,41*,Overflow,Pages,Leaf,Index,Pages,Pages,Primary,After Inserting 23*, 4
7、8*, 41*, 42* .,10*,15*,20*,27*,33*,37*,40*,46*,51*,55*,63*,97*,20,33,51,63,40,Root,23*,48*,41*,42*,Overflow,Pages,Leaf,Index,Pages,Pages,Primary,Now Lets Delete: 42*, 51*, 97*, ,10*,15*,20*,27*,33*,37*,40*,46*,51*,55*,63*,97*,20,33,51,63,40,Root,23*,48*,41*,42*,Overflow,Pages,Leaf,Index,Pages,Pages,
8、Primary,. After Deleting 42*, 51*, 97*,Note that 51* appears in index levels, but not in leaf!Index still is “fully balanced”, but with many empty slots.,10*,15*,20*,27*,33*,37*,40*,46*,55*,63*,20,33,51,63,40,Root,23*,48*,41*,Comments on ISAM,Data Pages,Index Pages,Overflow pages,Comments on ISAM,Fi
9、le creation: Leaf (data) pages allocated sequentially sorted by search key index pages allocated space for overflow pages later createdIndex entries: ; they direct search for data entries, which are in leaf pages or even in overflow pages.,Data Pages,Index Pages,Overflow pages,Comments on ISAM,Searc
10、h: Start at root; use key comparisons to go to leaf. Cost log F N ; F = # entries/index pg, N = # leaf pgs Insert: Find leaf that data entry belongs to, and put it there. Delete: Find and remove from leaf; if empty overflow page, de-allocate. If empty primary page, leave it.,Data Pages,Index Pages,O
11、verflow pages,Comments on ISAM : Pros? Cons?,Static tree structure: inserts/deletes affect only leaf pages. Long overflow chains may appear. May affect retrieve performance. Keep 20% free in leaf page. Problem might still appear!+ Concurrent access.index page is not locked since it is never changed.
12、? What to do instead ?,B+ Tree: Most Widely Used Index,Guarantee Search/Insert/delete at log F N cost with F = fanout, N = # leaf pages Keep tree height-balanced. Supports equality and range-searches efficiently.,Example B+ Tree,Search begins at root, and key comparisons direct it to a leaf (as in I
13、SAM). Search for 5*; 15*, for all data entries = 24*.,leaf nodes form a sequence to answer range query,Root,17,24,30,2*,3*,5*,7*,14*,16*,19*,20*,22*,24*,27*,29*,33*,34*,38*,39*,13,B+ Tree Concepts,Insert/delete at log F N cost; keep tree height-balanced. Each node contains d = m = 2d entries. The pa
14、rameter d is called order of tree. Minimum 50% occupancy or fill-factor (except for root).,B+ Trees in Practice,Typical order: 100. Typical fill-factor: 67%. average fanout = 133 Typical capacities: Height 4: 1334 = 312,900,700 records Height 3: 1333 = 2,352,637 records Can often hold top levels in
15、buffer pool: Level 1 = 1 page = 8 Kbytes Level 2 = 133 pages = 1 Mbyte Level 3 = 1332 = 17,689 pages = 133 MBytes,Inserting Data Entry into B+ Tree,Find correct leaf L. Put data entry onto L. If L has enough space, done! Else, must split L (into L and a new node L2) Redistribute entries evenly, copy
16、 up middle key. Insert index entry pointing to L2 into parent of L.This can happen recursively To split index node, redistribute entries evenly, and push up middle key. (Contrast with leaf splits.),Inserting Data Entry into B+ Tree,Splits “grow” the tree in width. A root split increases height of tr
17、ee. Tree growth: gets wider or one level taller at top.,Root,17,24,30,2*,3*,5*,7*,14*,16*,19*,20*,22*,24*,27*,29*,33*,34*,38*,39*,13,Inserting 8* into Example B+ Tree,Root,17,24,30,2*,3*,5*,7*,14*,16*,19*,20*,22*,24*,27*,29*,33*,34*,38*,39*,13,Inserting 8* into Example B+ Tree,2*,3*,5*,7*,8*,5,(Note
18、 that 5 is,continues to appear in the leaf.),s copied up and,Root,17,24,30,2*,3*,5*,7*,14*,16*,19*,20*,22*,24*,27*,29*,33*,34*,38*,39*,13,Inserting 8* into Example B+ Tree,2*,3*,5*,7*,8*,5,5,24,30,17,13,Entry to be inserted in parent node.,(Note that 17 is pushed up and only once Appears in the inde
19、x.),Inserting 8* into Example B+ Tree,Observe how minimum occupancy is guaranteed in both leaf and index pg splits. Note difference between copy-up and push-up; be sure you understand the reasons for this.,2*,3*,5*,7*,8*,5,Entry to be inserted in parent node.,(Note that 5 is,continues to appear in t
20、he leaf.),s copied up and,appears once in the index. Contrast,Inserting 8* into Example B+ Tree,Observe how minimum occupancy is guaranteed in both leaf and index pg splits.Note difference between copy-up and push-up; be sure you understand the reasons for this.,2*,3*,5*,7*,8*,5,Entry to be inserted
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- TREESTRUCTUREDINDEXESPPT
