comp115 databases tree structured indexing
play

Comp115: Databases Tree-structured indexing Instructor: Manos - PowerPoint PPT Presentation

Comp115 [Spring 2017] - http://www.cs.tufts.edu/comp/115/ - Manos Athanassoulis Comp115: Databases Tree-structured indexing Instructor: Manos Athanassoulis Comp115 [Spring 2017] -


  1. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Comp115: ¡Databases Tree-­‑structured ¡indexing Instructor: ¡Manos ¡Athanassoulis

  2. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Some ¡Reminders HW3 ¡will ¡be ¡out ¡soon ¡(last ¡homework) Exercises ¡will ¡be ¡posted ¡for ¡some ¡lectures à reading ¡material ¡to ¡help ¡you ¡for ¡midterms solutions ¡will ¡be ¡posted midterm ¡1 ¡is ¡on ¡March ¡13 th SQL ¡hands-­‑on ¡test ¡(tentatively) ¡on ¡March ¡15 th project ¡will ¡be ¡out ¡this ¡week ¡and ¡you ¡will ¡be ¡able ¡to ¡ work ¡until ¡the ¡end ¡of ¡the ¡semester

  3. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Tree-­‑structured ¡indexing Intro ¡& ¡B + -­‑Tree Insert ¡into ¡a ¡B + -­‑Tree Delete ¡from ¡a ¡B + -­‑Tree Prefix ¡Key ¡Compression ¡& ¡Bulk ¡Loading Units

  4. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Introduction Recall: ¡3 ¡alternatives ¡for ¡data ¡entries ¡ k*: • Data ¡record ¡with ¡key ¡value k • < k , ¡rid ¡of ¡data ¡record ¡with ¡search ¡key ¡value k > • < k , ¡list ¡of ¡rids ¡of ¡data ¡records ¡with ¡search ¡key ¡ k > Choice ¡is ¡orthogonal ¡to ¡the ¡ indexing ¡technique ¡ used ¡to ¡locate ¡data ¡entries ¡k*. Tree-­‑structured ¡indexing ¡techniques ¡support ¡ both ¡ range ¡searches ¡ and ¡ equality ¡searches . 4

  5. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Range ¡Searches “Find ¡all ¡students ¡with ¡gpa > ¡3.0” – If ¡data ¡is ¡in ¡sorted ¡file, ¡do ¡binary ¡search ¡to ¡find ¡first ¡such ¡ student, ¡then ¡scan ¡to ¡find ¡others. – Cost ¡of ¡maintaining ¡sorted ¡file ¡+ ¡performing ¡binary ¡search ¡ in ¡a ¡database ¡can ¡be ¡quite ¡high. ¡Q: ¡Why??? Simple ¡idea: ¡ ¡Create ¡an ¡“index” file. Index ¡File kN k1 k2 Data ¡File Page ¡N Page ¡3 Page ¡1 Page ¡2 ☛ Can ¡do ¡binary ¡search ¡on ¡(smaller) ¡index ¡file! 5

  6. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis B+ ¡Tree: ¡ ¡The ¡Most ¡Widely-­‑Used ¡Index Insert/delete ¡at ¡log ¡ F N ¡cost; ¡keep ¡tree ¡ height-­‑balanced . ¡ ¡ ¡ (F ¡= ¡fanout, ¡N ¡= ¡# ¡leaf ¡pages) Minimum ¡50% ¡occupancy ¡(except ¡for ¡root). ¡ ¡Each ¡node ¡ contains ¡d ¡<= ¡ ¡ m <= ¡2d ¡entries. ¡“d” ¡is ¡called ¡the ¡ order of ¡the ¡tree. Supports ¡equality and ¡range-­‑searches efficiently. All ¡searches ¡go ¡from ¡root ¡to ¡leaves, ¡in ¡a ¡dynamic structure. Index ¡Entries (Direct ¡search) Data ¡Entries 6

  7. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡B+ ¡Tree Search ¡begins ¡at ¡root, ¡and ¡key ¡comparisons ¡ direct ¡it ¡to ¡a ¡leaf. Search ¡for ¡5*, ¡15*, ¡all ¡data ¡entries ¡>= ¡24* ¡... Root 30 13 17 24 19* 20* 22* 24* 27* 29* 33* 34* 38* 39* 2* 3* 5* 7* 14* 16* ☛ Based ¡on ¡the ¡search ¡for ¡15*, ¡we ¡know it ¡is ¡not ¡in ¡the ¡tree! 7

  8. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis B+ ¡Trees ¡in ¡Practice ¡(cool ¡facts!) Typical ¡order: ¡100. ¡ ¡Typical ¡fill-­‑factor: ¡67%. – average ¡fanout = ¡2*100*0.67 ¡= ¡134 Typical ¡capacities: – Height ¡4: ¡133 4 = ¡312,900,721 ¡entries – Height ¡3: ¡133 3 = ¡ ¡ ¡ ¡2,406,104 ¡entries Can ¡often ¡hold ¡top ¡levels ¡in ¡buffer ¡pool: – Level ¡1 ¡= ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡1 ¡page ¡= ¡ ¡ ¡ ¡ ¡8 ¡KB – Level ¡2 ¡= ¡ ¡ ¡ ¡ ¡ ¡134 ¡pages ¡= ¡ ¡ ¡ ¡ ¡1 ¡MB – Level ¡3 ¡= ¡ ¡17,956 ¡pages ¡= ¡140 ¡MB 8

  9. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Tree-­‑structured ¡indexing Intro ¡& ¡B + -­‑Tree Insert ¡into ¡a ¡B + -­‑Tree Delete ¡from ¡a ¡B + -­‑Tree Prefix ¡Key ¡Compression ¡& ¡Bulk ¡Loading Units

  10. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Inserting ¡a ¡Data ¡Entry ¡into ¡a ¡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 ¡up middle ¡key. Insert ¡index ¡entry ¡pointing ¡to ¡ L2 ¡ into ¡parent of ¡ L . This ¡can ¡happen ¡recursively – To ¡split ¡index ¡node, ¡redistribute ¡entries ¡evenly, ¡but ¡ push ¡ up middle ¡key. ¡ ¡(Contrast ¡with ¡leaf ¡splits.) Splits ¡“grow” ¡tree; ¡root ¡split ¡increases ¡height. ¡ ¡ – Tree ¡growth: ¡gets ¡ wider or ¡ one ¡level ¡taller ¡at ¡top. 10

  11. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡B+ ¡Tree ¡-­‑ Inserting ¡8* Root 13 17 24 3* 5* 19* 20* 22* 23* 24* 27* 29* 2* 7* 14* 16* 11

  12. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡B+ ¡Tree ¡-­‑ Inserting ¡8* Root 13 17 24 3* 5* 19* 20* 22* 23* 24* 27* 29* 2* 7* 14* 16* 3* 5* 19* 20* 22* 23* 24* 27* 29* 2* 7* 14* 16* 12

  13. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡B+ ¡Tree ¡-­‑ Inserting ¡8* Root 13 17 24 3* 5* 19* 20* 22* 23* 24* 27* 29* 2* 7* 14* 16* 3* 7* 8* 19* 20* 22* 23* 24* 27* 29* 2* 5* 14* 16* 13

  14. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡B+ ¡Tree ¡-­‑ Inserting ¡8* Root 13 17 24 3* 5* 19* 20* 22* 23* 24* 27* 29* 2* 7* 14* 16* 13 17 24 3* 7* 8* 19* 20* 22* 23* 24* 27* 29* 2* 5* 14* 16* 14

  15. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡B+ ¡Tree ¡-­‑ Inserting ¡8* Root 13 17 24 3* 5* 19* 20* 22* 23* 24* 27* 29* 2* 7* 14* 16* 5 13 17 24 3* 7* 8* 19* 20* 22* 23* 24* 27* 29* 2* 5* 14* 16* 15

  16. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡B+ ¡Tree ¡-­‑ Inserting ¡21* Root 5 13 17 24 2* 3* 5* 7* 8* 19* 20* 22* 24* 27* 29* 14* 16* 23* 5 13 17 24 2* 3* 5* 7* 8* 19* 20* 22* ¡ ¡23* 24* 27* 29* 14* 16* 16

  17. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡B+ ¡Tree ¡-­‑ Inserting ¡21* Root 5 13 17 24 2* 3* 5* 7* 8* 19* 20* 22* 24* 27* 29* 14* 16* 23* 5 13 17 24 2* 3* 5* 7* 8* 19* 20* 21* 22* 23* 24* 27* 29* 14* 16* 17

  18. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡B+ ¡Tree ¡-­‑ Inserting ¡21* Root 5 13 17 24 2* 3* 5* 7* 8* 19* 20* 22* 24* 27* 29* 14* 16* 23* 21 5 13 24 17 2* 3* 5* 7* 8* 19* 20* 21* 22* 23* 24* 27* 29* 14* 16* 18

  19. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡B+ ¡Tree ¡-­‑ Inserting ¡21* Root 5 13 17 24 2* 3* 5* 7* 8* 19* 20* 22* 24* 27* 29* 14* 16* 23* Root 17 21 5 13 24 2* 3* 5* 7* 8* 19* 20* 21* 22* 23* 24* 27* 29* 14* 16* 19

  20. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡B+ ¡Tree Root 17 21 5 13 24 2* 3* 5* 7* 8* 19* 20* 21* 22* 23* 24* 27* 29* 14* 16* Notice ¡that ¡root ¡was ¡split, ¡leading ¡to ¡increase ¡in ¡height. In ¡this ¡example, ¡we ¡can ¡avoid ¡split ¡by ¡re-­‑distributing ¡entries; ¡ however, ¡this ¡is ¡usually ¡not ¡done ¡in ¡practice. 20

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