comp115 databases hash indexing
play

Comp115: Databases Hash Indexing Instructor: Manos Athanassoulis - PowerPoint PPT Presentation

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


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

  2. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Hash ¡Indexing Static ¡Hashing Extendible ¡Hashing Linear ¡Hashing Units 2

  3. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Introduction 1. ¡Actual ¡data ¡record ¡(with ¡key ¡value k ) 2. ¡< k , ¡rid ¡of ¡matching ¡data ¡record> 3. ¡< k , ¡list ¡of ¡rids ¡of ¡matching ¡data ¡records> Choice ¡is ¡orthogonal ¡to ¡the ¡indexing technique Hash-­‑based ¡ indexes ¡ à equality ¡selections Cannot ¡ support ¡range ¡searches Static and ¡dynamic hashing ¡techniques ¡exist

  4. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Static ¡Hashing ¡ #primary ¡bucket ¡pages ¡fixed, ¡allocated ¡sequentially, ¡never ¡de-­‑ allocated; ¡overflow ¡pages ¡if ¡needed h(k) ¡mod ¡M = ¡bucket ¡to ¡insert ¡data ¡entry ¡with ¡key ¡ k ¡ (M: ¡#buckets) ¡ … 0 h(key) ¡mod ¡M … 1 key … h … … … … M-­‑1 Primary ¡bucket ¡pages Overflow ¡pages 4

  5. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Static ¡Hashing ¡(Contd.) ¡ Buckets ¡contain ¡data ¡entries Hash ¡function ¡on ¡ search ¡key ¡ field ¡of ¡record ¡ r ¡ Must ¡distribute ¡values ¡over ¡range ¡0 ¡... ¡M-­‑1 What ¡is ¡a ¡good ¡hash ¡function? ¡ h ( key ) ¡= ¡(a ¡* ¡ key ¡ + ¡b) ¡usually ¡works ¡well a ¡and ¡b ¡are ¡constants; ¡lots ¡known ¡about ¡how ¡to ¡tune ¡ h 5

  6. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Static ¡Hashing ¡(Problems!) ¡ Long ¡overflow ¡chains ¡can ¡develop ¡and ¡degrade ¡ performance Ways ¡to ¡solve? – Reorganization ¡is ¡expensive ¡and ¡may ¡block ¡queries ¡ – Extendible ¡ and ¡ Linear ¡Hashing : ¡Dynamic ¡techniques ¡ to ¡fix ¡this ¡problem 6

  7. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Hash ¡Indexing Static ¡Hashing Extendible ¡Hashing Linear ¡Hashing Units 7

  8. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Extendible ¡Hashing ¡ Why ¡not ¡double ¡the ¡number ¡of ¡buckets? ¡ Note ¡that ¡reading ¡and ¡writing ¡all ¡pages ¡is ¡expensive! ¡ Idea : ¡ Use ¡directory ¡of ¡pointers ¡to ¡buckets ¡ On ¡overflow, ¡double ¡the ¡directory ¡(not ¡the ¡# ¡of ¡buckets) ¡ Why ¡does ¡this ¡help? ¡ Directory ¡is ¡much ¡smaller ¡than ¡the ¡entire ¡index ¡file ¡ Only ¡one ¡page ¡of ¡data ¡entries ¡is ¡split ¡ No ¡overflow ¡page! ¡(caveat: ¡duplicates ¡w.r.t. ¡the ¡hash ¡function) ¡ Trick ¡lies ¡in ¡how ¡the ¡hash ¡function ¡is ¡adjusted! ¡ 8

  9. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Extendible ¡Hashing Directory: ¡an ¡array ¡ Search ¡for ¡k: ¡ – Apply ¡hash ¡function ¡h(k) ¡ – Take ¡last ¡ global ¡depth ¡ # ¡bits ¡of ¡ h ( k ) ¡ Insert: ¡ – If ¡the ¡bucket ¡has ¡space, ¡insert, ¡done – If ¡the ¡bucket ¡if ¡full, ¡ split ¡ it, ¡re-­‑distribute ¡– If ¡ necessary, ¡double ¡the ¡directory ¡ 9

  10. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example local ¡depth 2 4* ¡12* global ¡depth: 2 00 2 1* ¡13* 13*=1101 01 2 10* 10 h 11 2 15* ¡7* directory data ¡pages what ¡is ¡the ¡hash ¡function? 10

  11. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example: ¡Insert ¡6 2 4* ¡12* global ¡depth: 2 00 2 1* ¡13* 6*=0110 01 2 10* 10 h 11 2 15* ¡7* directory data ¡pages 11

  12. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example: ¡Insert ¡6 2 4* ¡12* global ¡depth: 2 00 2 1* ¡13* 6*=0110 01 2 10* 10 h 11 2 15* ¡7* directory data ¡pages 12

  13. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example: ¡Insert ¡6 2 4* ¡12* global ¡depth: 2 00 2 1* ¡13* 6*=0110 01 2 10* ¡6* 10 h 11 2 15* ¡7* directory data ¡pages 13

  14. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡2: ¡Insert ¡9 2 4* ¡12* 2 00 2 1* ¡13* 9*=1001 01 2 10* ¡6* 10 h 11 2 15* ¡7* directory data ¡pages 14

  15. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡2: ¡Insert ¡9 2 4* ¡12* 2 00 2 1* ¡13* 9*=1001 01 2 10* ¡6* 10 h 11 2 15* ¡7* directory data ¡pages now ¡what?? 15

  16. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡2: ¡Insert ¡9 2 4* ¡12* 3 000 2 1* ¡13* 9*=1001 001 2 10* ¡6* 010 h 011 2 15* ¡7* 100 data ¡pages 101 110 111 (1) ¡double ¡the ¡directory 16

  17. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡2: ¡Insert ¡9 2 4* ¡12* 3 000 3 1* 9*=1001 001 2 10* ¡6* 010 h 011 2 15* ¡7* 100 3 13* 101 110 111 (1) double ¡the ¡directory (2) re-­‑distribute ¡the ¡split ¡bucket 17

  18. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡2: ¡Insert ¡9 2 4* ¡12* 3 000 3 1* 9*=1001 001 2 10* ¡6* 010 h 011 2 15* ¡7* 100 3 13* 101 110 111 (1) double ¡the ¡directory (2) re-­‑distribute ¡the ¡split ¡bucket (3) connect ¡corresponding ¡buckets 18

  19. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡2: ¡Insert ¡9 2 4* ¡12* 3 000 3 1* 9*=1001 001 2 10* ¡6* 010 h 011 2 15* ¡7* 100 3 13* 101 110 111 19

  20. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡2: ¡Insert ¡9 2 4* ¡12* 3 000 3 1* ¡9* 9*=1001 001 2 10* ¡6* 010 h 011 2 15* ¡7* 100 3 13* 101 110 111 do ¡we ¡have ¡to ¡re-­‑distribute ¡all? 20

  21. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡3: ¡Insert ¡5 2 4* ¡12* 3 000 3 1* ¡9* 5*=0101 001 2 10* ¡6* 010 h 011 2 15* ¡7* 100 3 13* 101 110 111 21

  22. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡3: ¡Insert ¡5 2 4* ¡12* 3 000 3 1* ¡9* 5*=0101 001 2 10* ¡6* 010 h 011 2 15* ¡7* 100 3 13* ¡5* 101 110 111 what ¡happens ¡if ¡we ¡want ¡to ¡insert ¡17? do ¡we ¡have ¡to ¡re-­‑distribute ¡all? [17 à 10001] ¡so, ¡double ¡the ¡dir again! 22

  23. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡3: ¡Insert ¡5 2 4* ¡12* 3 000 3 1* ¡9* 5*=0101 001 2 10* ¡6* 010 h 011 2 15* ¡7* 100 3 13* ¡5* 101 110 111 do ¡we ¡have ¡to ¡double ¡the ¡directory every ¡time ¡we ¡split ¡a ¡bucket? 23

  24. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡3: ¡Insert ¡14 2 4* ¡12* 3 000 3 1* ¡9* 14*=1110 001 2 10* ¡6* 010 h 011 2 15* ¡7* 100 3 13* ¡5* 101 110 111 24

  25. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡3: ¡Insert ¡14 2 4* ¡12* 3 000 3 1* ¡9* 14*=1110 001 2 10* ¡6* 010 h 011 2 15* ¡7* 100 3 13* ¡5* 101 110 111 25

  26. Comp115 ¡[Spring ¡2017] ¡-­‑ http://www.cs.tufts.edu/comp/115/ ¡-­‑ Manos ¡Athanassoulis Example ¡3: ¡Insert ¡14 2 4* ¡12* 3 000 3 1* ¡9* 14*=1110 001 3 10* 010 h 011 2 15* ¡7* 100 3 13* ¡5* 101 110 3 6* 111 26

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